Merge "Revert "Adding sanity check to Title::isRedirect().""
[lhc/web/wiklou.git] / maintenance / populateRevisionSha1.php
index 7cb137d..1d8e4c8 100644 (file)
@@ -67,7 +67,7 @@ class PopulateRevisionSha1 extends LoggedUpdateMaintenance {
                $end = $db->selectField( $table, "MAX($idCol)", false, __METHOD__ );
                if ( !$start || !$end ) {
                        $this->output( "...$table table seems to be empty.\n" );
-                       return true;
+                       return 0;
                }
 
                $count = 0;
@@ -81,13 +81,13 @@ class PopulateRevisionSha1 extends LoggedUpdateMaintenance {
                                AND $idCol IS NOT NULL AND {$prefix}_sha1 = ''";
                        $res = $db->select( $table, '*', $cond, __METHOD__ );
 
-                       $db->begin();
+                       $db->begin( __METHOD__ );
                        foreach ( $res as $row ) {
                                if ( $this->upgradeRow( $row, $table, $idCol, $prefix ) ) {
                                        $count++;
                                }
                        }
-                       $db->commit();
+                       $db->commit( __METHOD__ );
 
                        $blockStart += $this->mBatchSize;
                        $blockEnd += $this->mBatchSize;
@@ -95,37 +95,52 @@ class PopulateRevisionSha1 extends LoggedUpdateMaintenance {
                }
                return $count;
        }
-       
+
+       /**
+        * @return int
+        */
        protected function doSha1LegacyUpdates() {
                $count = 0;
                $db = $this->getDB( DB_MASTER );
-               $res = $db->select( 'archive', '*', array( 'ar_rev_id IS NULL' ), __METHOD__ );
+               $res = $db->select( 'archive', '*',
+                       array( 'ar_rev_id IS NULL', 'ar_sha1' => '' ), __METHOD__ );
 
                $updateSize = 0;
-               $db->begin();
+               $db->begin( __METHOD__ );
                foreach ( $res as $row ) {
                        if ( $this->upgradeLegacyArchiveRow( $row ) ) {
                                ++$count;
                        }
                        if ( ++$updateSize >= 100 ) {
                                $updateSize = 0;
-                               $db->commit();
+                               $db->commit( __METHOD__ );
                                $this->output( "Commited row with ar_timestamp={$row->ar_timestamp}\n" );
                                wfWaitForSlaves();
-                               $db->begin();
+                               $db->begin( __METHOD__ );
                        }
                }
-               $db->commit();
+               $db->commit( __METHOD__ );
+               return $count;
        }
 
+       /**
+        * @param $row
+        * @param $table
+        * @param $idCol
+        * @param $prefix
+        * @return bool
+        */
        protected function upgradeRow( $row, $table, $idCol, $prefix ) {
                $db = $this->getDB( DB_MASTER );
-               if ( $table === 'archive' ) {
-                       $rev = Revision::newFromArchiveRow( $row );
-               } else {
-                       $rev = new Revision( $row );
+               try {
+                       $rev = ( $table === 'archive' )
+                               ? Revision::newFromArchiveRow( $row )
+                               : new Revision( $row );
+                       $text = $rev->getRawText();
+               } catch ( MWException $e ) {
+                       $this->output( "Text of revision with {$idCol}={$row->$idCol} unavailable!\n" );
+                       return false; // bug 22624?
                }
-               $text = $rev->getRawText();
                if ( !is_string( $text ) ) {
                        # This should not happen, but sometimes does (bug 20757)
                        $this->output( "Text of revision with {$idCol}={$row->$idCol} unavailable!\n" );
@@ -134,15 +149,24 @@ class PopulateRevisionSha1 extends LoggedUpdateMaintenance {
                        $db->update( $table,
                                array( "{$prefix}_sha1" => Revision::base36Sha1( $text ) ),
                                array( $idCol => $row->$idCol ),
-                               __METHOD__ 
+                               __METHOD__
                        );
                        return true;
                }
        }
 
+       /**
+        * @param $row
+        * @return bool
+        */
        protected function upgradeLegacyArchiveRow( $row ) {
                $db = $this->getDB( DB_MASTER );
-               $rev = Revision::newFromArchiveRow( $row );
+               try {
+                       $rev = Revision::newFromArchiveRow( $row );
+               } catch ( MWException $e ) {
+                       $this->output( "Text of revision with timestamp {$row->ar_timestamp} unavailable!\n" );
+                       return false; // bug 22624?
+               }
                $text = $rev->getRawText();
                if ( !is_string( $text ) ) {
                        # This should not happen, but sometimes does (bug 20757)
@@ -159,7 +183,7 @@ class PopulateRevisionSha1 extends LoggedUpdateMaintenance {
                                        'ar_timestamp' => $row->ar_timestamp,
                                        'ar_len'       => $row->ar_len // extra sanity
                                ),
-                               __METHOD__ 
+                               __METHOD__
                        );
                        return true;
                }