Tweaks to LoggedUpdateMaintenance:
authorChad Horohoe <demon@users.mediawiki.org>
Thu, 8 Sep 2011 15:52:00 +0000 (15:52 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Thu, 8 Sep 2011 15:52:00 +0000 (15:52 +0000)
* Reduce some duplication
* Prefix skipped steps with "..." per updater convention
* Make PopulateLogUsertext, PopulateLogSearch and PopulateParentId use LoggedUpdateMaintenance -- now they will properly log when there was "Nothing to do" and we can skip the clutter on future update runs
* Docs, etc.

includes/installer/DatabaseUpdater.php
includes/installer/MysqlUpdater.php
maintenance/Maintenance.php
maintenance/populateImageSha1.php
maintenance/populateLogSearch.php
maintenance/populateLogUsertext.php
maintenance/populateParentId.php
maintenance/populateRevisionLength.php

index 38bbd42..b20054d 100644 (file)
@@ -519,33 +519,25 @@ abstract class DatabaseUpdater {
        }
 
        protected function doLogUsertextPopulation() {
-               if ( $this->updateRowExists( 'populate log_usertext' ) ) {
-                       $this->output( "...log_user_text field already populated.\n" );
-                       return;
-               }
-
-               $this->output(
+               if ( !$this->updateRowExists( 'populate log_usertext' ) ) {
+                       $this->output(
                        "Populating log_user_text field, printing progress markers. For large\n" .
                        "databases, you may want to hit Ctrl-C and do this manually with\n" .
                        "maintenance/populateLogUsertext.php.\n" );
+               }
                $task = $this->maintenance->runChild( 'PopulateLogUsertext' );
                $task->execute();
-               $this->output( "Done populating log_user_text field.\n" );
        }
 
        protected function doLogSearchPopulation() {
-               if ( $this->updateRowExists( 'populate log_search' ) ) {
-                       $this->output( "...log_search table already populated.\n" );
-                       return;
+               if ( !$this->updateRowExists( 'populate log_search' ) ) {
+                       $this->output(
+                               "Populating log_search table, printing progress markers. For large\n" .
+                               "databases, you may want to hit Ctrl-C and do this manually with\n" .
+                               "maintenance/populateLogSearch.php.\n" );
                }
-
-               $this->output(
-                       "Populating log_search table, printing progress markers. For large\n" .
-                       "databases, you may want to hit Ctrl-C and do this manually with\n" .
-                       "maintenance/populateLogSearch.php.\n" );
                $task = $this->maintenance->runChild( 'PopulateLogSearch' );
                $task->execute();
-               $this->output( "Done populating log_search table.\n" );
        }
 
        protected function doUpdateTranscacheField() {
index 29d2673..951acb6 100644 (file)
@@ -747,11 +747,12 @@ class MysqlUpdater extends DatabaseUpdater {
        }
 
        protected function doPopulateParentId() {
-               if ( $this->updateRowExists( 'populate rev_parent_id' ) ) {
-                       $this->output( "...rev_parent_id column already populated.\n" );
-                       return;
+               if ( !$this->updateRowExists( 'populate rev_parent_id' ) ) {
+                       $this->output(
+                               "Populating rev_parent_id fields, printing progress markers. For large\n" .
+                               "databases, you may want to hit Ctrl-C and do this manually with\n" .
+                               "maintenance/populateParentId.php.\n" );
                }
-
                $task = $this->maintenance->runChild( 'PopulateParentId' );
                $task->execute();
        }
index adccee1..0dca74a 100644 (file)
@@ -1224,6 +1224,9 @@ abstract class Maintenance {
        }
 }
 
+/**
+ * Fake maintenance wrapper, mostly used for the web installer/updater
+ */
 class FakeMaintenance extends Maintenance {
        protected $mSelf = "FakeMaintenanceScript";
        public function execute() {
@@ -1231,10 +1234,15 @@ class FakeMaintenance extends Maintenance {
        }
 }
 
+/**
+ * Class for scripts that perform database maintenance and want to log the
+ * update in `updatelog` so we can later skip it
+ */
 abstract class LoggedUpdateMaintenance extends Maintenance {
        public function __construct() {
                parent::__construct();
                $this->addOption( 'force', 'Run the update even if it was completed already' );
+               $this->setBatchSize( 200 );
        }
 
        public function execute() {
@@ -1244,7 +1252,7 @@ abstract class LoggedUpdateMaintenance extends Maintenance {
                if ( !$this->hasOption( 'force' ) &&
                        $db->selectRow( 'updatelog', '1', array( 'ul_key' => $key ), __METHOD__ ) )
                {
-                       $this->output( $this->updateSkippedMessage() . "\n" );
+                       $this->output( "..." . $this->updateSkippedMessage() . "\n" );
                        return true;
                }
 
@@ -1262,6 +1270,15 @@ abstract class LoggedUpdateMaintenance extends Maintenance {
                }
        }
 
+       /**
+        * Message to show the the update log was unable to log the completion of this update
+        * @return String
+        */
+       protected function updatelogFailedMessage() {
+               $key = $this->getUpdateKey();
+               return "Unable to log update '{$key}' as completed.";
+       }
+
        /**
         * Do the actual work. All child classes will need to implement this.
         * Return true to log the update as done or false (usually on failure).
@@ -1280,10 +1297,4 @@ abstract class LoggedUpdateMaintenance extends Maintenance {
         * @return String
         */
        abstract protected function updateSkippedMessage();
-
-       /**
-        * Message to show the the update log was unable to log the completion of this update
-        * @return String
-        */
-       abstract protected function updatelogFailedMessage();
 }
index 4fee6fe..90fe82c 100644 (file)
@@ -29,7 +29,6 @@ class PopulateImageSha1 extends LoggedUpdateMaintenance {
                $this->addOption( 'method', "Use 'pipe' to pipe to mysql command line,\n" .
                        "\t\tdefault uses Database class", false, true );
                $this->addOption( 'file', 'Fix for a specific file, without File: namespace prefixed', false, true );
-               $this->setBatchSize( 200 );
        }
 
        protected function getUpdateKey() {
@@ -40,10 +39,6 @@ class PopulateImageSha1 extends LoggedUpdateMaintenance {
                return 'img_sha1 column of image table already populated.';
        }
 
-       protected function updatelogFailedMessage() {
-               return 'Could not insert img_sha1 population row.';
-       }
-
        public function doDBUpdates() {
                $method = $this->getOption( 'method', 'normal' );
                $file = $this->getOption( 'file' );
index f13873c..e3f6067 100644 (file)
 
 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
 
-class PopulateLogSearch extends Maintenance {
-
-       const LOG_SEARCH_BATCH_SIZE = 100;
-
+class PopulateLogSearch extends LoggedUpdateMaintenance {
        static $tableMap = array( 'rev' => 'revision', 'fa' => 'filearchive', 'oi' => 'oldimage', 'ar' => 'archive' );
 
        public function __construct() {
                parent::__construct();
                $this->mDescription = "Migrate log params to new table and index for searching";
+               $this->setBatchSize( 100 );
+       }
+
+       protected function getUpdateKey() {
+               return 'populate log_search';
+       }
+
+       protected function updateSkippedMessage() {
+               return 'log_search table already populated.';
        }
 
-       public function execute() {
+       protected function doDBUpdates() {
                $db = $this->getDB( DB_MASTER );
                if ( !$db->tableExists( 'log_search' ) ) {
-                       $this->error( "log_search does not exist", true );
+                       $this->error( "log_search does not exist" );
+                       return false;
                }
                $start = $db->selectField( 'logging', 'MIN(log_id)', false, __FUNCTION__ );
                if ( !$start ) {
@@ -47,9 +54,9 @@ class PopulateLogSearch extends Maintenance {
                $end = $db->selectField( 'logging', 'MAX(log_id)', false, __FUNCTION__ );
 
                # Do remaining chunk
-               $end += self::LOG_SEARCH_BATCH_SIZE - 1;
+               $end += $this->mBatchSize - 1;
                $blockStart = $start;
-               $blockEnd = $start + self::LOG_SEARCH_BATCH_SIZE - 1;
+               $blockEnd = $start + $this->mBatchSize - 1;
 
                $delTypes = array( 'delete', 'suppress' ); // revisiondelete types
                while ( $blockEnd <= $end ) {
@@ -128,23 +135,12 @@ class PopulateLogSearch extends Maintenance {
                                        $log->addRelations( 'target_author_ip', $userIPs, $row->log_id );
                                }
                        }
-                       $blockStart += self::LOG_SEARCH_BATCH_SIZE;
-                       $blockEnd += self::LOG_SEARCH_BATCH_SIZE;
+                       $blockStart += $this->mBatchSize;
+                       $blockEnd += $this->mBatchSize;
                        wfWaitForSlaves();
                }
-               if ( $db->insert(
-                               'updatelog',
-                               array( 'ul_key' => 'populate log_search' ),
-                               __FUNCTION__,
-                               'IGNORE'
-                       )
-               ) {
-                       $this->output( "log_search population complete.\n" );
-                       return true;
-               } else {
-                       $this->output( "Could not insert log_search population row.\n" );
-                       return false;
-               }
+               $this->output( "Done populating log_search table.\n" );
+               return true;
        }
 }
 
index e9e6926..2b0e2d6 100644 (file)
 
 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
 
-class PopulateLogUsertext extends Maintenance {
+class PopulateLogUsertext extends LoggedUpdateMaintenance {
        public function __construct() {
                parent::__construct();
-               $this->mDescription = "Populates the log_user_text";
+               $this->mDescription = "Populates the log_user_text field";
                $this->setBatchSize( 100 );
        }
 
-       public function execute() {
+       protected function getUpdateKey() {
+               return 'populate log_usertext';
+       }
+
+       protected function updateSkippedMessage() {
+               return 'log_user_text column of logging table already populated.';
+       }
+
+       protected function doDBUpdates() {
                $db = $this->getDB( DB_MASTER );
                $start = $db->selectField( 'logging', 'MIN(log_id)', false, __METHOD__ );
                if ( !$start ) {
@@ -61,19 +69,8 @@ class PopulateLogUsertext extends Maintenance {
                        $blockEnd += $this->mBatchSize;
                        wfWaitForSlaves();
                }
-               if ( $db->insert(
-                               'updatelog',
-                               array( 'ul_key' => 'populate log_usertext' ),
-                               __METHOD__,
-                               'IGNORE'
-                       )
-               ) {
-                       $this->output( "log_usertext population complete.\n" );
-                       return true;
-               } else {
-                       $this->output( "Could not insert log_usertext population row.\n" );
-                       return false;
-               }
+               $this->output( "Done populating log_user_text field.\n" );
+               return true;
        }
 }
 
index 7cbc267..67689b9 100644 (file)
 
 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
 
-class PopulateParentId extends Maintenance {
+class PopulateParentId extends LoggedUpdateMaintenance {
        public function __construct() {
                parent::__construct();
                $this->mDescription = "Populates rev_parent_id";
-               $this->setBatchSize( 200 );
        }
 
-       public function execute() {
+       protected function getUpdateKey() {
+               return 'populate rev_parent_id';
+       }
+
+       protected function updateSkippedMessage() {
+               return 'rev_parent_id column of revision table already populated.';
+       }
+
+       protected function doDBUpdates() {
                $db = wfGetDB( DB_MASTER );
                if ( !$db->tableExists( 'revision' ) ) {
-                       $this->error( "revision table does not exist", true );
+                       $this->error( "revision table does not exist" );
+                       return false;
                }
                $this->output( "Populating rev_parent_id 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 ) ) {
-                       $this->output( "...revision table seems to be empty.\n" );
-                       $db->insert( 'updatelog',
-                               array( 'ul_key' => 'populate rev_parent_id' ),
-                               __METHOD__,
-                               'IGNORE' );
-                       return;
+                       $this->output( "...revision table seems to be empty, nothing to do.\n" );
+                       return true;
                }
                # Do remaining chunk
                $blockStart = intval( $start );
@@ -100,17 +104,8 @@ class PopulateParentId extends Maintenance {
                        $blockEnd += $this->mBatchSize;
                        wfWaitForSlaves();
                }
-               $logged = $db->insert( 'updatelog',
-                       array( 'ul_key' => 'populate rev_parent_id' ),
-                       __METHOD__,
-                       'IGNORE' );
-               if ( $logged ) {
-                       $this->output( "rev_parent_id population complete ... {$count} rows [{$changed} changed]\n" );
-                       return true;
-               } else {
-                       $this->output( "Could not insert rev_parent_id population row.\n" );
-                       return false;
-               }
+               $this->output( "rev_parent_id population complete ... {$count} rows [{$changed} changed]\n" );
+               return true;
        }
 }
 
index ff053d1..bb42de9 100644 (file)
@@ -26,7 +26,6 @@ class PopulateRevisionLength extends LoggedUpdateMaintenance {
        public function __construct() {
                parent::__construct();
                $this->mDescription = "Populates the rev_len field";
-               $this->setBatchSize( 200 );
        }
 
        protected function getUpdateKey() {
@@ -37,10 +36,6 @@ class PopulateRevisionLength extends LoggedUpdateMaintenance {
                return 'rev_len column of revision table already populated.';
        }
 
-       protected function updatelogFailedMessage() {
-               return 'Could not insert rev_len population row.';
-       }
-
        public function doDBUpdates() {
                $db = $this->getDB( DB_MASTER );
                if ( !$db->tableExists( 'revision' ) ) {