X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fuser%2FUserGroupMembership.php;h=cf985cb9eb72cbaca6d42dc5ad73c6a880583a44;hb=fe94275c8fcfc248a5eae857dde7c5772d993ab5;hp=e757e59629620896f98b79b8385231dad495ab7b;hpb=4b2f95bed5a9ae0a917264abed2ba1fd9fb78f3c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/user/UserGroupMembership.php b/includes/user/UserGroupMembership.php index e757e59629..cf985cb9eb 100644 --- a/includes/user/UserGroupMembership.php +++ b/includes/user/UserGroupMembership.php @@ -46,7 +46,7 @@ class UserGroupMembership { /** * @param int $userId The ID of the user who belongs to the group - * @param string $group The internal group name + * @param string|null $group The internal group name * @param string|null $expiry Timestamp of expiry in TS_MW format, or null if no expiry */ public function __construct( $userId = 0, $group = null, $expiry = null ) { @@ -230,18 +230,20 @@ class UserGroupMembership { public function isExpired() { if ( !$this->expiry ) { return false; - } else { - return wfTimestampNow() > $this->expiry; } + return wfTimestampNow() > $this->expiry; } /** * Purge expired memberships from the user_groups table + * + * @return int|bool false if purging wasn't attempted (e.g. because of + * readonly), the number of rows purged (might be 0) otherwise */ public static function purgeExpired() { $services = MediaWikiServices::getInstance(); if ( $services->getReadOnlyMode()->isReadOnly() ) { - return; + return false; } $lbFactory = $services->getDBLoadBalancerFactory(); @@ -251,10 +253,11 @@ class UserGroupMembership { $lockKey = $dbw->getDomainID() . ':usergroups-prune'; // specific to this wiki $scopedLock = $dbw->getScopedLockAndFlush( $lockKey, __METHOD__, 0 ); if ( !$scopedLock ) { - return; // already running + return false; // already running } $now = time(); + $purgedRows = 0; do { $dbw->startAtomic( __METHOD__ ); @@ -284,12 +287,15 @@ class UserGroupMembership { ); // Push the groups to user_former_groups $dbw->insert( 'user_former_groups', $insertData, __METHOD__, [ 'IGNORE' ] ); + // Count how many rows were purged + $purgedRows += $res->numRows(); } $dbw->endAtomic( __METHOD__ ); $lbFactory->commitAndWaitForReplication( __METHOD__, $ticket ); } while ( $res->numRows() > 0 ); + return $purgedRows; } /** @@ -347,9 +353,8 @@ class UserGroupMembership { $ugm = self::newFromRow( $row ); if ( !$ugm->isExpired() ) { return $ugm; - } else { - return false; } + return false; } /** @@ -412,9 +417,8 @@ class UserGroupMembership { } return $context->msg( 'group-membership-link-with-expiry' ) ->params( $groupLink, $expiryDT, $expiryD, $expiryT )->text(); - } else { - return $groupLink; } + return $groupLink; } /**