Merge "Remove parameter 'options' from hook 'SkinEditSectionLinks'"
[lhc/web/wiklou.git] / includes / jobqueue / jobs / ClearUserWatchlistJob.php
index 3e8b2ad..0cb1a52 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
 use MediaWiki\MediaWikiServices;
+use MediaWiki\User\UserIdentity;
 
 /**
  * Job to clear a users watchlist in batches.
@@ -10,37 +11,28 @@ use MediaWiki\MediaWikiServices;
  * @ingroup JobQueue
  * @since 1.31
  */
-class ClearUserWatchlistJob extends Job {
-
-       /**
-        * @param User $user User to clear the watchlist for.
-        * @param int $maxWatchlistId The maximum wl_id at the time the job was first created.
-        *
-        * @return ClearUserWatchlistJob
-        */
-       public static function newForUser( User $user, $maxWatchlistId ) {
-               return new self(
-                       null,
-                       [ 'userId' => $user->getId(), 'maxWatchlistId' => $maxWatchlistId ]
-               );
-       }
-
+class ClearUserWatchlistJob extends Job implements GenericParameterJob {
        /**
-        * @param Title|null $title Not used by this job.
         * @param array $params
         *  - userId,         The ID for the user whose watchlist is being cleared.
         *  - maxWatchlistId, The maximum wl_id at the time the job was first created,
         */
-       public function __construct( Title $title = null, array $params ) {
-               parent::__construct(
-                       'clearUserWatchlist',
-                       SpecialPage::getTitleFor( 'EditWatchlist', 'clear' ),
-                       $params
-               );
+       public function __construct( array $params ) {
+               parent::__construct( 'clearUserWatchlist', $params );
 
                $this->removeDuplicates = true;
        }
 
+       /**
+        * @param UserIdentity $user User to clear the watchlist for.
+        * @param int $maxWatchlistId The maximum wl_id at the time the job was first created.
+        *
+        * @return ClearUserWatchlistJob
+        */
+       public static function newForUser( UserIdentity $user, $maxWatchlistId ) {
+               return new self( [ 'userId' => $user->getId(), 'maxWatchlistId' => $maxWatchlistId ] );
+       }
+
        public function run() {
                global $wgUpdateRowsPerQuery;
                $userId = $this->params['userId'];
@@ -53,7 +45,7 @@ class ClearUserWatchlistJob extends Job {
 
                // Wait before lock to try to reduce time waiting in the lock.
                if ( !$loadBalancer->safeWaitForMasterPos( $dbr ) ) {
-                       $this->setLastError( 'Timed out while waiting for slave to catch up before lock' );
+                       $this->setLastError( 'Timed out waiting for replica to catch up before lock' );
                        return false;
                }
 
@@ -66,7 +58,7 @@ class ClearUserWatchlistJob extends Job {
                }
 
                if ( !$loadBalancer->safeWaitForMasterPos( $dbr ) ) {
-                       $this->setLastError( 'Timed out while waiting for slave to catch up within lock' );
+                       $this->setLastError( 'Timed out waiting for replica to catch up within lock' );
                        return false;
                }
 
@@ -101,7 +93,7 @@ class ClearUserWatchlistJob extends Job {
                if ( count( $watchlistIds ) === (int)$batchSize ) {
                        // Until we get less results than the limit, recursively push
                        // the same job again.
-                       JobQueueGroup::singleton()->push( new self( $this->getTitle(), $this->getParams() ) );
+                       JobQueueGroup::singleton()->push( new self( $this->getParams() ) );
                }
 
                return true;