}
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() {
}
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();
}
}
}
+/**
+ * Fake maintenance wrapper, mostly used for the web installer/updater
+ */
class FakeMaintenance extends Maintenance {
protected $mSelf = "FakeMaintenanceScript";
public function execute() {
}
}
+/**
+ * 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() {
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;
}
}
}
+ /**
+ * 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).
* @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();
}
$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() {
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' );
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 ) {
$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 ) {
$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;
}
}
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 ) {
$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;
}
}
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 );
$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;
}
}
public function __construct() {
parent::__construct();
$this->mDescription = "Populates the rev_len field";
- $this->setBatchSize( 200 );
}
protected function getUpdateKey() {
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' ) ) {