\n to eof
[lhc/web/wiklou.git] / maintenance / populateRevisionLength.php
index 2ee6779..9b6826c 100644 (file)
@@ -20,7 +20,7 @@
  * @ingroup Maintenance
  */
 
-require_once( dirname(__FILE__) . '/Maintenance.php' );
+require_once( dirname( __FILE__ ) . '/Maintenance.php' );
 
 class PopulateRevisionLength extends Maintenance {
        public function __construct() {
@@ -37,7 +37,7 @@ class PopulateRevisionLength extends Maintenance {
                $this->output( "Populating rev_len column\n" );
                $start = $db->selectField( 'revision', 'MIN(rev_id)', false, __FUNCTION__ );
                $end = $db->selectField( 'revision', 'MAX(rev_id)', false, __FUNCTION__ );
-               if( is_null( $start ) || is_null( $end ) ){
+               if ( is_null( $start ) || is_null( $end ) ) {
                        $this->output( "...revision table seems to be empty.\n" );
                        $db->insert( 'updatelog',
                                array( 'ul_key' => 'populate rev_len' ),
@@ -49,7 +49,8 @@ class PopulateRevisionLength extends Maintenance {
                $blockStart = intval( $start );
                $blockEnd = intval( $start ) + $this->mBatchSize - 1;
                $count = 0;
-               while( $blockStart <= $end ) {
+               $missing = 0;
+               while ( $blockStart <= $end ) {
                        $this->output( "...doing rev_id from $blockStart to $blockEnd\n" );
                        $res = $db->select( 'revision',
                                            Revision::selectFields(),
@@ -58,15 +59,22 @@ class PopulateRevisionLength extends Maintenance {
                                                   "rev_len IS NULL" ),
                                            __METHOD__ );
                        # Go through and update rev_len from these rows.
-                       foreach( $res as $row ) {
+                       foreach ( $res as $row ) {
                                $rev = new Revision( $row );
                                $text = $rev->getRawText();
-                               # Update the row...
-                               $db->update( 'revision',
-                                            array( 'rev_len' => strlen( $text ) ),
-                                            array( 'rev_id' => $row->rev_id ),
-                                            __METHOD__ );
-                               $count++;
+                               if ( !is_string( $text ) ) {
+                                       # This should not happen, but sometimes does (bug 20757)
+                                       $this->output( "Text of revision {$row->rev_id} unavailable!\n" );
+                                       $missing++;
+                               }
+                               else {
+                                       # Update the row...
+                                       $db->update( 'revision',
+                                                    array( 'rev_len' => strlen( $text ) ),
+                                                    array( 'rev_id' => $row->rev_id ),
+                                                    __METHOD__ );
+                                       $count++;
+                               }
                        }
                        $blockStart += $this->mBatchSize;
                        $blockEnd += $this->mBatchSize;
@@ -76,8 +84,8 @@ class PopulateRevisionLength extends Maintenance {
                        array( 'ul_key' => 'populate rev_len' ),
                        __METHOD__,
                        'IGNORE' );
-               if( $logged ) {
-                       $this->output( "rev_len population complete ... {$count} rows changed\n" );
+               if ( $logged ) {
+                       $this->output( "rev_len population complete ... {$count} rows changed ({$missing} missing)\n" );
                        return true;
                } else {
                        $this->output( "Could not insert rev_len population row.\n" );