MediaWiki REL1_35
LoggedUpdateMaintenance.php
Go to the documentation of this file.
1<?php
26abstract class LoggedUpdateMaintenance extends Maintenance {
27 public function __construct() {
28 parent::__construct();
29 $this->addOption( 'force', 'Run the update even if it was completed already' );
30 $this->setBatchSize( 200 );
31 }
32
33 public function execute() {
34 $db = $this->getDB( DB_MASTER );
35 $key = $this->getUpdateKey();
36
37 if ( !$this->hasOption( 'force' )
38 && $db->selectRow( 'updatelog', '1', [ 'ul_key' => $key ], __METHOD__ )
39 ) {
40 $this->output( "..." . $this->updateSkippedMessage() . "\n" );
41
42 return true;
43 }
44
45 if ( !$this->doDBUpdates() ) {
46 return false;
47 }
48
49 $db->insert( 'updatelog', [ 'ul_key' => $key ], __METHOD__, [ 'IGNORE' ] );
50
51 return true;
52 }
53
58 protected function updateSkippedMessage() {
59 $key = $this->getUpdateKey();
60
61 return "Update '{$key}' already logged as completed. Use --force to run it again.";
62 }
63
69 abstract protected function doDBUpdates();
70
75 abstract protected function getUpdateKey();
76}
getDB()
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
__construct()
Default constructor.
doDBUpdates()
Do the actual work.
updateSkippedMessage()
Message to show that the update was done already and was just skipped.
getUpdateKey()
Get the update key name to go in the update log table.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
setBatchSize( $s=0)
Set the batch size.
const DB_MASTER
Definition defines.php:29