Use DB domain in JobQueueGroup and make WikiMap domain ID methods stricter
[lhc/web/wiklou.git] / includes / jobqueue / JobQueue.php
index 1f4f179..7d34f32 100644 (file)
@@ -30,7 +30,7 @@ use MediaWiki\MediaWikiServices;
  */
 abstract class JobQueue {
        /** @var string Wiki ID */
-       protected $wiki;
+       protected $domain;
        /** @var string Job type */
        protected $type;
        /** @var string Job priority for pop() */
@@ -56,10 +56,10 @@ abstract class JobQueue {
         * @throws MWException
         */
        protected function __construct( array $params ) {
-               $this->wiki = $params['wiki'];
+               $this->domain = $params['domain'] ?? $params['wiki']; // b/c
                $this->type = $params['type'];
-               $this->claimTTL = isset( $params['claimTTL'] ) ? $params['claimTTL'] : 0;
-               $this->maxTries = isset( $params['maxTries'] ) ? $params['maxTries'] : 3;
+               $this->claimTTL = $params['claimTTL'] ?? 0;
+               $this->maxTries = $params['maxTries'] ?? 3;
                if ( isset( $params['order'] ) && $params['order'] !== 'any' ) {
                        $this->order = $params['order'];
                } else {
@@ -69,12 +69,8 @@ abstract class JobQueue {
                        throw new MWException( __CLASS__ . " does not support '{$this->order}' order." );
                }
                $this->dupCache = wfGetCache( CACHE_ANYTHING );
-               $this->aggr = isset( $params['aggregator'] )
-                       ? $params['aggregator']
-                       : new JobQueueAggregatorNull( [] );
-               $this->readOnlyReason = isset( $params['readOnlyReason'] )
-                       ? $params['readOnlyReason']
-                       : false;
+               $this->aggr = $params['aggregator'] ?? new JobQueueAggregatorNull( [] );
+               $this->readOnlyReason = $params['readOnlyReason'] ?? false;
        }
 
        /**
@@ -121,8 +117,16 @@ abstract class JobQueue {
        /**
         * @return string Wiki ID
         */
+       final public function getDomain() {
+               return $this->domain;
+       }
+
+       /**
+        * @return string Wiki ID
+        * @deprecated 1.33
+        */
        final public function getWiki() {
-               return $this->wiki;
+               return $this->domain;
        }
 
        /**
@@ -334,7 +338,7 @@ abstract class JobQueue {
                }
 
                $this->doBatchPush( $jobs, $flags );
-               $this->aggr->notifyQueueNonEmpty( $this->wiki, $this->type );
+               $this->aggr->notifyQueueNonEmpty( $this->domain, $this->type );
 
                foreach ( $jobs as $job ) {
                        if ( $job->isRootJob() ) {
@@ -362,8 +366,9 @@ abstract class JobQueue {
                global $wgJobClasses;
 
                $this->assertNotReadOnly();
-               if ( $this->wiki !== wfWikiID() ) {
-                       throw new MWException( "Cannot pop '{$this->type}' job off foreign wiki queue." );
+               if ( !WikiMap::isCurrentWikiDomain( $this->domain ) ) {
+                       throw new MWException(
+                               "Cannot pop '{$this->type}' job off foreign '{$this->domain}' wiki queue." );
                } elseif ( !isset( $wgJobClasses[$this->type] ) ) {
                        // Do not pop jobs if there is no class for the queue type
                        throw new MWException( "Unrecognized job type '{$this->type}'." );
@@ -372,7 +377,7 @@ abstract class JobQueue {
                $job = $this->doPop();
 
                if ( !$job ) {
-                       $this->aggr->notifyQueueEmpty( $this->wiki, $this->type );
+                       $this->aggr->notifyQueueEmpty( $this->domain, $this->type );
                }
 
                // Flag this job as an old duplicate based on its "root" job...
@@ -472,7 +477,7 @@ abstract class JobQueue {
                $params = $job->getRootJobParams();
 
                $key = $this->getRootJobCacheKey( $params['rootJobSignature'] );
-               // Callers should call batchInsert() and then this function so that if the insert
+               // Callers should call JobQueueGroup::push() before this method so that if the insert
                // fails, the de-duplication registration will be aborted. Since the insert is
                // deferred till "transaction idle", do the same here, so that the ordering is
                // maintained. Having only the de-duplication registration succeed would cause
@@ -526,9 +531,13 @@ abstract class JobQueue {
         * @return string
         */
        protected function getRootJobCacheKey( $signature ) {
-               list( $db, $prefix ) = wfSplitWikiID( $this->wiki );
-
-               return wfForeignMemcKey( $db, $prefix, 'jobqueue', $this->type, 'rootjob', $signature );
+               $this->dupCache->makeGlobalKey(
+                       'jobqueue',
+                       $this->domain,
+                       $this->type,
+                       'rootjob',
+                       $signature
+               );
        }
 
        /**