Convert all array() syntax to []
[lhc/web/wiklou.git] / includes / jobqueue / JobQueueDB.php
index 51dec65..aaf9fb0 100644 (file)
@@ -55,7 +55,7 @@ class JobQueueDB extends JobQueue {
        }
 
        protected function supportedOrders() {
-               return array( 'random', 'timestamp', 'fifo' );
+               return [ 'random', 'timestamp', 'fifo' ];
        }
 
        protected function optimalOrder() {
@@ -70,7 +70,7 @@ class JobQueueDB extends JobQueue {
                $dbr = $this->getSlaveDB();
                try {
                        $found = $dbr->selectField( // unclaimed job
-                               'job', '1', array( 'job_cmd' => $this->type, 'job_token' => '' ), __METHOD__
+                               'job', '1', [ 'job_cmd' => $this->type, 'job_token' => '' ], __METHOD__
                        );
                } catch ( DBError $e ) {
                        $this->throwDBException( $e );
@@ -94,7 +94,7 @@ class JobQueueDB extends JobQueue {
                try {
                        $dbr = $this->getSlaveDB();
                        $size = (int)$dbr->selectField( 'job', 'COUNT(*)',
-                               array( 'job_cmd' => $this->type, 'job_token' => '' ),
+                               [ 'job_cmd' => $this->type, 'job_token' => '' ],
                                __METHOD__
                        );
                } catch ( DBError $e ) {
@@ -124,7 +124,7 @@ class JobQueueDB extends JobQueue {
                $dbr = $this->getSlaveDB();
                try {
                        $count = (int)$dbr->selectField( 'job', 'COUNT(*)',
-                               array( 'job_cmd' => $this->type, "job_token != {$dbr->addQuotes( '' )}" ),
+                               [ 'job_cmd' => $this->type, "job_token != {$dbr->addQuotes( '' )}" ],
                                __METHOD__
                        );
                } catch ( DBError $e ) {
@@ -155,11 +155,11 @@ class JobQueueDB extends JobQueue {
                $dbr = $this->getSlaveDB();
                try {
                        $count = (int)$dbr->selectField( 'job', 'COUNT(*)',
-                               array(
+                               [
                                        'job_cmd' => $this->type,
                                        "job_token != {$dbr->addQuotes( '' )}",
                                        "job_attempts >= " . $dbr->addQuotes( $this->maxTries )
-                               ),
+                               ],
                                __METHOD__
                        );
                } catch ( DBError $e ) {
@@ -204,8 +204,8 @@ class JobQueueDB extends JobQueue {
                        return;
                }
 
-               $rowSet = array(); // (sha1 => job) map for jobs that are de-duplicated
-               $rowList = array(); // list of jobs for jobs that are not de-duplicated
+               $rowSet = []; // (sha1 => job) map for jobs that are de-duplicated
+               $rowList = []; // list of jobs for jobs that are not de-duplicated
                foreach ( $jobs as $job ) {
                        $row = $this->insertFields( $job );
                        if ( $job->ignoreDuplicates() ) {
@@ -222,11 +222,11 @@ class JobQueueDB extends JobQueue {
                        // Strip out any duplicate jobs that are already in the queue...
                        if ( count( $rowSet ) ) {
                                $res = $dbw->select( 'job', 'job_sha1',
-                                       array(
+                                       [
                                                // No job_type condition since it's part of the job_sha1 hash
                                                'job_sha1' => array_keys( $rowSet ),
                                                'job_token' => '' // unclaimed
-                                       ),
+                                       ],
                                        $method
                                );
                                foreach ( $res as $row ) {
@@ -275,7 +275,7 @@ class JobQueueDB extends JobQueue {
                        $job = false; // job popped off
                        do { // retry when our row is invalid or deleted as a duplicate
                                // Try to reserve a row in the DB...
-                               if ( in_array( $this->order, array( 'fifo', 'timestamp' ) ) ) {
+                               if ( in_array( $this->order, [ 'fifo', 'timestamp' ] ) ) {
                                        $row = $this->claimOldest( $uuid );
                                } else { // random first
                                        $rand = mt_rand( 0, self::MAX_JOB_RANDOM ); // encourage concurrent UPDATEs
@@ -334,12 +334,12 @@ class JobQueueDB extends JobQueue {
                                $ineq = $gte ? '>=' : '<=';
                                $dir = $gte ? 'ASC' : 'DESC';
                                $row = $dbw->selectRow( 'job', self::selectFields(), // find a random job
-                                       array(
+                                       [
                                                'job_cmd' => $this->type,
                                                'job_token' => '', // unclaimed
-                                               "job_random {$ineq} {$dbw->addQuotes( $rand )}" ),
+                                               "job_random {$ineq} {$dbw->addQuotes( $rand )}" ],
                                        __METHOD__,
-                                       array( 'ORDER BY' => "job_random {$dir}" )
+                                       [ 'ORDER BY' => "job_random {$dir}" ]
                                );
                                if ( !$row && !$invertedDirection ) {
                                        $gte = !$gte;
@@ -351,12 +351,12 @@ class JobQueueDB extends JobQueue {
                                // in MySQL if there are many rows for some reason. This uses a small OFFSET
                                // instead of job_random for reducing excess claim retries.
                                $row = $dbw->selectRow( 'job', self::selectFields(), // find a random job
-                                       array(
+                                       [
                                                'job_cmd' => $this->type,
                                                'job_token' => '', // unclaimed
-                                       ),
+                                       ],
                                        __METHOD__,
-                                       array( 'OFFSET' => mt_rand( 0, self::MAX_OFFSET ) )
+                                       [ 'OFFSET' => mt_rand( 0, self::MAX_OFFSET ) ]
                                );
                                if ( !$row ) {
                                        $tinyQueue = true; // we know the queue must have <= MAX_OFFSET rows
@@ -367,11 +367,11 @@ class JobQueueDB extends JobQueue {
 
                        if ( $row ) { // claim the job
                                $dbw->update( 'job', // update by PK
-                                       array(
+                                       [
                                                'job_token' => $uuid,
                                                'job_token_timestamp' => $dbw->timestamp(),
-                                               'job_attempts = job_attempts+1' ),
-                                       array( 'job_cmd' => $this->type, 'job_id' => $row->job_id, 'job_token' => '' ),
+                                               'job_attempts = job_attempts+1' ],
+                                       [ 'job_cmd' => $this->type, 'job_id' => $row->job_id, 'job_token' => '' ],
                                        __METHOD__
                                );
                                // This might get raced out by another runner when claiming the previously
@@ -418,24 +418,24 @@ class JobQueueDB extends JobQueue {
                                // Use a subquery to find the job, within an UPDATE to claim it.
                                // This uses as much of the DB wrapper functions as possible.
                                $dbw->update( 'job',
-                                       array(
+                                       [
                                                'job_token' => $uuid,
                                                'job_token_timestamp' => $dbw->timestamp(),
-                                               'job_attempts = job_attempts+1' ),
-                                       array( 'job_id = (' .
+                                               'job_attempts = job_attempts+1' ],
+                                       [ 'job_id = (' .
                                                $dbw->selectSQLText( 'job', 'job_id',
-                                                       array( 'job_cmd' => $this->type, 'job_token' => '' ),
+                                                       [ 'job_cmd' => $this->type, 'job_token' => '' ],
                                                        __METHOD__,
-                                                       array( 'ORDER BY' => 'job_id ASC', 'LIMIT' => 1 ) ) .
+                                                       [ 'ORDER BY' => 'job_id ASC', 'LIMIT' => 1 ] ) .
                                                ')'
-                                       ),
+                                       ],
                                        __METHOD__
                                );
                        }
                        // Fetch any row that we just reserved...
                        if ( $dbw->affectedRows() ) {
                                $row = $dbw->selectRow( 'job', self::selectFields(),
-                                       array( 'job_cmd' => $this->type, 'job_token' => $uuid ), __METHOD__
+                                       [ 'job_cmd' => $this->type, 'job_token' => $uuid ], __METHOD__
                                );
                                if ( !$row ) { // raced out by duplicate job removal
                                        wfDebug( "Row deleted as duplicate by another process.\n" );
@@ -470,7 +470,7 @@ class JobQueueDB extends JobQueue {
 
                        // Delete a row with a single DELETE without holding row locks over RTTs...
                        $dbw->delete( 'job',
-                               array( 'job_cmd' => $this->type, 'job_id' => $job->metadata['id'] ), __METHOD__ );
+                               [ 'job_cmd' => $this->type, 'job_id' => $job->metadata['id'] ], __METHOD__ );
 
                        JobQueue::incrStats( 'acks', $this->type );
                } catch ( DBError $e ) {
@@ -521,7 +521,7 @@ class JobQueueDB extends JobQueue {
        protected function doDelete() {
                $dbw = $this->getMasterDB();
                try {
-                       $dbw->delete( 'job', array( 'job_cmd' => $this->type ) );
+                       $dbw->delete( 'job', [ 'job_cmd' => $this->type ] );
                } catch ( DBError $e ) {
                        $this->throwDBException( $e );
                }
@@ -541,7 +541,7 @@ class JobQueueDB extends JobQueue {
         * @return void
         */
        protected function doFlushCaches() {
-               foreach ( array( 'size', 'acquiredcount' ) as $type ) {
+               foreach ( [ 'size', 'acquiredcount' ] as $type ) {
                        $this->cache->delete( $this->getCacheKey( $type ) );
                }
        }
@@ -551,7 +551,7 @@ class JobQueueDB extends JobQueue {
         * @return Iterator
         */
        public function getAllQueuedJobs() {
-               return $this->getJobIterator( array( 'job_cmd' => $this->getType(), 'job_token' => '' ) );
+               return $this->getJobIterator( [ 'job_cmd' => $this->getType(), 'job_token' => '' ] );
        }
 
        /**
@@ -559,7 +559,7 @@ class JobQueueDB extends JobQueue {
         * @return Iterator
         */
        public function getAllAcquiredJobs() {
-               return $this->getJobIterator( array( 'job_cmd' => $this->getType(), "job_token > ''" ) );
+               return $this->getJobIterator( [ 'job_cmd' => $this->getType(), "job_token > ''" ] );
        }
 
        /**
@@ -575,7 +575,7 @@ class JobQueueDB extends JobQueue {
                                        $job = Job::factory(
                                                $row->job_cmd,
                                                Title::makeTitle( $row->job_namespace, $row->job_title ),
-                                               strlen( $row->job_params ) ? unserialize( $row->job_params ) : array()
+                                               strlen( $row->job_params ) ? unserialize( $row->job_params ) : []
                                        );
                                        $job->metadata['id'] = $row->job_id;
                                        $job->metadata['timestamp'] = $row->job_timestamp;
@@ -601,9 +601,9 @@ class JobQueueDB extends JobQueue {
                // have stale jobs. This lets recycleAndDeleteStaleJobs() re-enqueue
                // failed jobs so that they can be popped again for that edge case.
                $res = $dbr->select( 'job', 'DISTINCT job_cmd',
-                       array( 'job_cmd' => $types ), __METHOD__ );
+                       [ 'job_cmd' => $types ], __METHOD__ );
 
-               $types = array();
+               $types = [];
                foreach ( $res as $row ) {
                        $types[] = $row->job_cmd;
                }
@@ -613,10 +613,10 @@ class JobQueueDB extends JobQueue {
 
        protected function doGetSiblingQueueSizes( array $types ) {
                $dbr = $this->getSlaveDB();
-               $res = $dbr->select( 'job', array( 'job_cmd', 'COUNT(*) AS count' ),
-                       array( 'job_cmd' => $types ), __METHOD__, array( 'GROUP BY' => 'job_cmd' ) );
+               $res = $dbr->select( 'job', [ 'job_cmd', 'COUNT(*) AS count' ],
+                       [ 'job_cmd' => $types ], __METHOD__, [ 'GROUP BY' => 'job_cmd' ] );
 
-               $sizes = array();
+               $sizes = [];
                foreach ( $res as $row ) {
                        $sizes[$row->job_cmd] = (int)$row->count;
                }
@@ -646,11 +646,11 @@ class JobQueueDB extends JobQueue {
                                // These jobs can be recycled into the queue by expiring the claim. Selecting
                                // the IDs first means that the UPDATE can be done by primary key (less deadlocks).
                                $res = $dbw->select( 'job', 'job_id',
-                                       array(
+                                       [
                                                'job_cmd' => $this->type,
                                                "job_token != {$dbw->addQuotes( '' )}", // was acquired
                                                "job_token_timestamp < {$dbw->addQuotes( $claimCutoff )}", // stale
-                                               "job_attempts < {$dbw->addQuotes( $this->maxTries )}" ), // retries left
+                                               "job_attempts < {$dbw->addQuotes( $this->maxTries )}" ], // retries left
                                        __METHOD__
                                );
                                $ids = array_map(
@@ -663,11 +663,11 @@ class JobQueueDB extends JobQueue {
                                        // Set the timestamp to the current time, as it is useful to now that the job
                                        // was already tried before (the timestamp becomes the "released" time).
                                        $dbw->update( 'job',
-                                               array(
+                                               [
                                                        'job_token' => '',
-                                                       'job_token_timestamp' => $dbw->timestamp( $now ) ), // time of release
-                                               array(
-                                                       'job_id' => $ids ),
+                                                       'job_token_timestamp' => $dbw->timestamp( $now ) ], // time of release
+                                               [
+                                                       'job_id' => $ids ],
                                                __METHOD__
                                        );
                                        $affected = $dbw->affectedRows();
@@ -679,11 +679,11 @@ class JobQueueDB extends JobQueue {
 
                        // Just destroy any stale jobs...
                        $pruneCutoff = $dbw->timestamp( $now - self::MAX_AGE_PRUNE );
-                       $conds = array(
+                       $conds = [
                                'job_cmd' => $this->type,
                                "job_token != {$dbw->addQuotes( '' )}", // was acquired
                                "job_token_timestamp < {$dbw->addQuotes( $pruneCutoff )}" // stale
-                       );
+                       ];
                        if ( $this->claimTTL > 0 ) { // only prune jobs attempted too many times...
                                $conds[] = "job_attempts >= {$dbw->addQuotes( $this->maxTries )}";
                        }
@@ -696,7 +696,7 @@ class JobQueueDB extends JobQueue {
                                }, iterator_to_array( $res )
                        );
                        if ( count( $ids ) ) {
-                               $dbw->delete( 'job', array( 'job_id' => $ids ), __METHOD__ );
+                               $dbw->delete( 'job', [ 'job_id' => $ids ], __METHOD__ );
                                $affected = $dbw->affectedRows();
                                $count += $affected;
                                JobQueue::incrStats( 'abandons', $this->type, $affected );
@@ -717,7 +717,7 @@ class JobQueueDB extends JobQueue {
        protected function insertFields( IJobSpecification $job ) {
                $dbw = $this->getMasterDB();
 
-               return array(
+               return [
                        // Fields that describe the nature of the job
                        'job_cmd' => $job->getType(),
                        'job_namespace' => $job->getTitle()->getNamespace(),
@@ -731,7 +731,7 @@ class JobQueueDB extends JobQueue {
                                16, 36, 31
                        ),
                        'job_random' => mt_rand( 0, self::MAX_JOB_RANDOM )
-               );
+               ];
        }
 
        /**
@@ -767,7 +767,7 @@ class JobQueueDB extends JobQueue {
                        ? wfGetLBFactory()->getExternalLB( $this->cluster, $this->wiki )
                        : wfGetLB( $this->wiki );
 
-               return $lb->getConnectionRef( $index, array(), $this->wiki );
+               return $lb->getConnectionRef( $index, [], $this->wiki );
        }
 
        /**
@@ -819,7 +819,7 @@ class JobQueueDB extends JobQueue {
         * @return array
         */
        public static function selectFields() {
-               return array(
+               return [
                        'job_id',
                        'job_cmd',
                        'job_namespace',
@@ -831,6 +831,6 @@ class JobQueueDB extends JobQueue {
                        'job_token',
                        'job_token_timestamp',
                        'job_sha1',
-               );
+               ];
        }
 }