maintenance: Replace implicit Bugzilla bug numbers with Phab ones
[lhc/web/wiklou.git] / maintenance / storage / trackBlobs.php
index a3f9386..4f22843 100644 (file)
@@ -38,7 +38,7 @@ echo "All done.\n";
 class TrackBlobs {
        public $clusters, $textClause;
        public $doBlobOrphans;
-       public $trackedBlobs = array();
+       public $trackedBlobs = [];
 
        public $batchSize = 1000;
        public $reportingInterval = 10;
@@ -67,9 +67,9 @@ class TrackBlobs {
 
        function checkIntegrity() {
                echo "Doing integrity check...\n";
-               $dbr = wfGetDB( DB_SLAVE );
+               $dbr = wfGetDB( DB_REPLICA );
 
-               // Scan for HistoryBlobStub objects in the text table (bug 20757)
+               // Scan for HistoryBlobStub objects in the text table (T22757)
 
                $exists = $dbr->selectField( 'text', 1,
                        'old_flags LIKE \'%object%\' AND old_flags NOT LIKE \'%external%\' ' .
@@ -84,7 +84,7 @@ class TrackBlobs {
                        exit( 1 );
                }
 
-               // Scan the archive table for HistoryBlobStub objects or external flags (bug 22624)
+               // Scan the archive table for HistoryBlobStub objects or external flags (T24624)
                $flags = $dbr->selectField( 'archive', 'ar_flags',
                        'ar_flags LIKE \'%external%\' OR (' .
                        'ar_flags LIKE \'%object%\' ' .
@@ -117,7 +117,7 @@ class TrackBlobs {
 
        function getTextClause() {
                if ( !$this->textClause ) {
-                       $dbr = wfGetDB( DB_SLAVE );
+                       $dbr = wfGetDB( DB_REPLICA );
                        $this->textClause = '';
                        foreach ( $this->clusters as $cluster ) {
                                if ( $this->textClause != '' ) {
@@ -135,11 +135,11 @@ class TrackBlobs {
                        return false;
                }
 
-               return array(
+               return [
                        'cluster' => $m[1],
                        'id' => intval( $m[2] ),
                        'hash' => isset( $m[3] ) ? $m[3] : null
-               );
+               ];
        }
 
        /**
@@ -147,7 +147,7 @@ class TrackBlobs {
         */
        function trackRevisions() {
                $dbw = wfGetDB( DB_MASTER );
-               $dbr = wfGetDB( DB_SLAVE );
+               $dbr = wfGetDB( DB_REPLICA );
 
                $textClause = $this->getTextClause();
                $startId = 0;
@@ -158,25 +158,25 @@ class TrackBlobs {
                echo "Finding revisions...\n";
 
                while ( true ) {
-                       $res = $dbr->select( array( 'revision', 'text' ),
-                               array( 'rev_id', 'rev_page', 'old_id', 'old_flags', 'old_text' ),
-                               array(
+                       $res = $dbr->select( [ 'revision', 'text' ],
+                               [ 'rev_id', 'rev_page', 'old_id', 'old_flags', 'old_text' ],
+                               [
                                        'rev_id > ' . $dbr->addQuotes( $startId ),
                                        'rev_text_id=old_id',
                                        $textClause,
                                        'old_flags ' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ),
-                               ),
+                               ],
                                __METHOD__,
-                               array(
+                               [
                                        'ORDER BY' => 'rev_id',
                                        'LIMIT' => $this->batchSize
-                               )
+                               ]
                        );
                        if ( !$res->numRows() ) {
                                break;
                        }
 
-                       $insertBatch = array();
+                       $insertBatch = [];
                        foreach ( $res as $row ) {
                                $startId = $row->rev_id;
                                $info = $this->interpretPointer( $row->old_text );
@@ -188,14 +188,14 @@ class TrackBlobs {
                                        echo "Invalid cluster returned in SQL query: {$info['cluster']}\n";
                                        continue;
                                }
-                               $insertBatch[] = array(
+                               $insertBatch[] = [
                                        'bt_page' => $row->rev_page,
                                        'bt_rev_id' => $row->rev_id,
                                        'bt_text_id' => $row->old_id,
                                        'bt_cluster' => $info['cluster'],
                                        'bt_blob_id' => $info['id'],
                                        'bt_cgz_hash' => $info['hash']
-                               );
+                               ];
                                if ( $this->doBlobOrphans ) {
                                        gmp_setbit( $this->trackedBlobs[$info['cluster']], $info['id'] );
                                }
@@ -219,9 +219,9 @@ class TrackBlobs {
         * archive table counts as orphan for our purposes.
         */
        function trackOrphanText() {
-               # Wait until the blob_tracking table is available in the slave
+               # Wait until the blob_tracking table is available in the replica DB
                $dbw = wfGetDB( DB_MASTER );
-               $dbr = wfGetDB( DB_SLAVE );
+               $dbr = wfGetDB( DB_REPLICA );
                $pos = $dbw->getMasterPos();
                $dbr->masterPosWait( $pos, 100000 );
 
@@ -235,22 +235,22 @@ class TrackBlobs {
 
                # Scan the text table for orphan text
                while ( true ) {
-                       $res = $dbr->select( array( 'text', 'blob_tracking' ),
-                               array( 'old_id', 'old_flags', 'old_text' ),
-                               array(
+                       $res = $dbr->select( [ 'text', 'blob_tracking' ],
+                               [ 'old_id', 'old_flags', 'old_text' ],
+                               [
                                        'old_id>' . $dbr->addQuotes( $startId ),
                                        $textClause,
                                        'old_flags ' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ),
                                        'bt_text_id IS NULL'
-                               ),
+                               ],
                                __METHOD__,
-                               array(
+                               [
                                        'ORDER BY' => 'old_id',
                                        'LIMIT' => $this->batchSize
-                               ),
-                               array( 'blob_tracking' => array( 'LEFT JOIN', 'bt_text_id=old_id' ) )
+                               ],
+                               [ 'blob_tracking' => [ 'LEFT JOIN', 'bt_text_id=old_id' ] ]
                        );
-                       $ids = array();
+                       $ids = [];
                        foreach ( $res as $row ) {
                                $ids[] = $row->old_id;
                        }
@@ -259,7 +259,7 @@ class TrackBlobs {
                                break;
                        }
 
-                       $insertBatch = array();
+                       $insertBatch = [];
                        foreach ( $res as $row ) {
                                $startId = $row->old_id;
                                $info = $this->interpretPointer( $row->old_text );
@@ -272,14 +272,14 @@ class TrackBlobs {
                                        continue;
                                }
 
-                               $insertBatch[] = array(
+                               $insertBatch[] = [
                                        'bt_page' => 0,
                                        'bt_rev_id' => 0,
                                        'bt_text_id' => $row->old_id,
                                        'bt_cluster' => $info['cluster'],
                                        'bt_blob_id' => $info['id'],
                                        'bt_cgz_hash' => $info['hash']
-                               );
+                               ];
                                if ( $this->doBlobOrphans ) {
                                        gmp_setbit( $this->trackedBlobs[$info['cluster']], $info['id'] );
                                }
@@ -317,7 +317,7 @@ class TrackBlobs {
                        echo "Searching for orphan blobs in $cluster...\n";
                        $lb = wfGetLBFactory()->getExternalLB( $cluster );
                        try {
-                               $extDB = $lb->getConnection( DB_SLAVE );
+                               $extDB = $lb->getConnection( DB_REPLICA );
                        } catch ( DBConnectionError $e ) {
                                if ( strpos( $e->error, 'Unknown database' ) !== false ) {
                                        echo "No database on $cluster\n";
@@ -342,10 +342,10 @@ class TrackBlobs {
                        // Build a bitmap of actual blob rows
                        while ( true ) {
                                $res = $extDB->select( $table,
-                                       array( 'blob_id' ),
-                                       array( 'blob_id > ' . $extDB->addQuotes( $startId ) ),
+                                       [ 'blob_id' ],
+                                       [ 'blob_id > ' . $extDB->addQuotes( $startId ) ],
                                        __METHOD__,
-                                       array( 'LIMIT' => $this->batchSize, 'ORDER BY' => 'blob_id' )
+                                       [ 'LIMIT' => $this->batchSize, 'ORDER BY' => 'blob_id' ]
                                );
 
                                if ( !$res->numRows() ) {
@@ -369,7 +369,7 @@ class TrackBlobs {
                        $orphans = gmp_and( $actualBlobs, gmp_com( $this->trackedBlobs[$cluster] ) );
 
                        // Traverse the orphan list
-                       $insertBatch = array();
+                       $insertBatch = [];
                        $id = 0;
                        $numOrphans = 0;
                        while ( true ) {
@@ -377,13 +377,13 @@ class TrackBlobs {
                                if ( $id == -1 ) {
                                        break;
                                }
-                               $insertBatch[] = array(
+                               $insertBatch[] = [
                                        'bo_cluster' => $cluster,
                                        'bo_blob_id' => $id
-                               );
+                               ];
                                if ( count( $insertBatch ) > $this->batchSize ) {
                                        $dbw->insert( 'blob_orphans', $insertBatch, __METHOD__ );
-                                       $insertBatch = array();
+                                       $insertBatch = [];
                                }
 
                                ++$id;