Fixup some assignments in conditionals
[lhc/web/wiklou.git] / maintenance / storage / checkStorage.php
index c372b9c..bc47f95 100644 (file)
@@ -21,8 +21,6 @@
  * @ingroup Maintenance ExternalStorage
  */
 
-define( 'CONCAT_HEADER', 'O:27:"concatenatedgziphistoryblob"' );
-
 if ( !defined( 'MEDIAWIKI' ) ) {
        require_once( dirname( __FILE__ ) . '/../commandLine.inc' );
 
@@ -43,6 +41,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
  * @ingroup Maintenance ExternalStorage
  */
 class CheckStorage {
+       const CONCAT_HEADER = 'O:27:"concatenatedgziphistoryblob"';
        var $oldIdMap, $errors;
        var $dbStore = null;
 
@@ -55,7 +54,6 @@ class CheckStorage {
        );
 
        function check( $fix = false, $xml = '' ) {
-               $fname = 'checkStorage';
                $dbr = wfGetDB( DB_SLAVE );
                if ( $fix ) {
                        $dbw = wfGetDB( DB_MASTER );
@@ -63,7 +61,7 @@ class CheckStorage {
                } else {
                        print "Checking...\n";
                }
-               $maxRevId = $dbr->selectField( 'revision', 'MAX(rev_id)', false, $fname );
+               $maxRevId = $dbr->selectField( 'revision', 'MAX(rev_id)', false, __METHOD__ );
                $chunkSize = 1000;
                $flagStats = array();
                $objectStats = array();
@@ -84,7 +82,7 @@ class CheckStorage {
                        $this->oldIdMap = array();
                        $dbr->ping();
                        $res = $dbr->select( 'revision', array( 'rev_id', 'rev_text_id' ),
-                               array( "rev_id BETWEEN $chunkStart AND $chunkEnd" ), $fname );
+                               array( "rev_id BETWEEN $chunkStart AND $chunkEnd" ), __METHOD__ );
                        foreach ( $res as $row ) {
                                $this->oldIdMap[$row->rev_id] = $row->rev_text_id;
                        }
@@ -99,8 +97,11 @@ class CheckStorage {
                        $externalRevs = array();
                        $objectRevs = array();
                        $res = $dbr->select( 'text', array( 'old_id', 'old_flags' ),
-                               'old_id IN (' . implode( ',', $this->oldIdMap ) . ')', $fname );
+                               'old_id IN (' . implode( ',', $this->oldIdMap ) . ')', __METHOD__ );
                        foreach ( $res as $row ) {
+                               /**
+                                * @var $flags int
+                                */
                                $flags = $row->old_flags;
                                $id = $row->old_id;
 
@@ -133,7 +134,7 @@ class CheckStorage {
                                                $dbw = wfGetDB( DB_MASTER );
                                                $dbw->ping();
                                                $dbw->update( 'text', array( 'old_flags' => '' ),
-                                                       array( 'old_id' => $id ), $fname );
+                                                       array( 'old_id' => $id ), __METHOD__ );
                                                echo "Fixed\n";
                                        } else {
                                                $this->error( 'fixable', "Warning: old_flags set to 0", $id );
@@ -154,7 +155,7 @@ class CheckStorage {
                        $externalNormalBlobs = array();
                        if ( count( $externalRevs ) ) {
                                $res = $dbr->select( 'text', array( 'old_id', 'old_flags', 'old_text' ),
-                                       array( 'old_id IN (' . implode( ',', $externalRevs ) . ')' ), $fname );
+                                       array( 'old_id IN (' . implode( ',', $externalRevs ) . ')' ), __METHOD__ );
                                foreach ( $res as $row ) {
                                        $urlParts = explode( '://', $row->old_text, 2 );
                                        if ( count( $urlParts ) !== 2 || $urlParts[1] == '' ) {
@@ -192,7 +193,7 @@ class CheckStorage {
                                        $blobsTable = $this->dbStore->getTable( $extDb );
                                        $res = $extDb->select( $blobsTable,
                                                array( 'blob_id' ),
-                                               array( 'blob_id IN( ' . implode( ',', $blobIds ) . ')' ), $fname );
+                                               array( 'blob_id IN( ' . implode( ',', $blobIds ) . ')' ), __METHOD__ );
                                        foreach ( $res as $row ) {
                                                unset( $xBlobIds[$row->blob_id] );
                                        }
@@ -211,7 +212,7 @@ class CheckStorage {
                        if ( count( $objectRevs ) ) {
                                $headerLength = 300;
                                $res = $dbr->select( 'text', array( 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ),
-                                       array( 'old_id IN (' . implode( ',', $objectRevs ) . ')' ), $fname );
+                                       array( 'old_id IN (' . implode( ',', $objectRevs ) . ')' ), __METHOD__ );
                                foreach ( $res as $row ) {
                                        $oldId = $row->old_id;
                                        $matches = array();
@@ -262,7 +263,7 @@ class CheckStorage {
                        if ( count( $concatBlobs ) ) {
                                $headerLength = 300;
                                $res = $dbr->select( 'text', array( 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ),
-                                       array( 'old_id IN (' . implode( ',', array_keys( $concatBlobs ) ) . ')' ), $fname );
+                                       array( 'old_id IN (' . implode( ',', array_keys( $concatBlobs ) ) . ')' ), __METHOD__ );
                                foreach ( $res as $row ) {
                                        $flags = explode( ',', $row->old_flags );
                                        if ( in_array( 'external', $flags ) ) {
@@ -285,7 +286,7 @@ class CheckStorage {
                                                        $this->error( 'unfixable', "Error: invalid flags \"{$row->old_flags}\" on concat bulk row {$row->old_id}",
                                                                $concatBlobs[$row->old_id] );
                                                }
-                                       } elseif ( strcasecmp( substr( $row->header, 0, strlen( CONCAT_HEADER ) ), CONCAT_HEADER ) ) {
+                                       } elseif ( strcasecmp( substr( $row->header, 0, strlen( self::CONCAT_HEADER ) ), self::CONCAT_HEADER ) ) {
                                                $this->error( 'restore text', "Error: Incorrect object header for concat bulk row {$row->old_id}",
                                                        $concatBlobs[$row->old_id] );
                                        } # else good
@@ -354,7 +355,6 @@ class CheckStorage {
        }
 
        function checkExternalConcatBlobs( $externalConcatBlobs ) {
-               $fname = 'CheckStorage::checkExternalConcatBlobs';
                if ( !count( $externalConcatBlobs ) ) {
                        return;
                }
@@ -367,12 +367,12 @@ class CheckStorage {
                        $blobIds = array_keys( $oldIds );
                        $extDb =& $this->dbStore->getSlave( $cluster );
                        $blobsTable = $this->dbStore->getTable( $extDb );
-                       $headerLength = strlen( CONCAT_HEADER );
+                       $headerLength = strlen( self::CONCAT_HEADER );
                        $res = $extDb->select( $blobsTable,
                                array( 'blob_id', "LEFT(blob_text, $headerLength) AS header" ),
-                               array( 'blob_id IN( ' . implode( ',', $blobIds ) . ')' ), $fname );
+                               array( 'blob_id IN( ' . implode( ',', $blobIds ) . ')' ), __METHOD__ );
                        foreach ( $res as $row ) {
-                               if ( strcasecmp( $row->header, CONCAT_HEADER ) ) {
+                               if ( strcasecmp( $row->header, self::CONCAT_HEADER ) ) {
                                        $this->error( 'restore text', "Error: invalid header on target $cluster/{$row->blob_id} of two-part ES URL",
                                                $oldIds[$row->blob_id] );
                                }
@@ -440,8 +440,6 @@ class CheckStorage {
        }
 
        function importRevision( &$revision, &$importer ) {
-               $fname = 'CheckStorage::importRevision';
-
                $id = $revision->getID();
                $text = $revision->getText();
                if ( $text === '' ) {
@@ -462,7 +460,7 @@ class CheckStorage {
 
                // Find text row again
                $dbr = wfGetDB( DB_SLAVE );
-               $oldId = $dbr->selectField( 'revision', 'rev_text_id', array( 'rev_id' => $id ), $fname );
+               $oldId = $dbr->selectField( 'revision', 'rev_text_id', array( 'rev_id' => $id ), __METHOD__ );
                if ( !$oldId ) {
                        echo "Missing revision row for rev_id $id\n";
                        return;
@@ -476,7 +474,7 @@ class CheckStorage {
                $dbw->update( 'text',
                        array( 'old_flags' => $flags, 'old_text' => $text ),
                        array( 'old_id' => $oldId ),
-                       $fname, array( 'LIMIT' => 1 )
+                       __METHOD__, array( 'LIMIT' => 1 )
                );
 
                // Remove it from the unfixed list and add it to the fixed list