MediaWiki  master
LoggedUpdateMaintenance.php
Go to the documentation of this file.
1 <?php
26 abstract 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 }
LoggedUpdateMaintenance\__construct
__construct()
Default constructor.
Definition: LoggedUpdateMaintenance.php:27
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:55
LoggedUpdateMaintenance
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
Definition: LoggedUpdateMaintenance.php:26
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:245
DB_MASTER
const DB_MASTER
Definition: defines.php:26
LoggedUpdateMaintenance\execute
execute()
Do the actual work.
Definition: LoggedUpdateMaintenance.php:33
LoggedUpdateMaintenance\updateSkippedMessage
updateSkippedMessage()
Message to show that the update was done already and was just skipped.
Definition: LoggedUpdateMaintenance.php:58
Maintenance\getDB
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1366
LoggedUpdateMaintenance\doDBUpdates
doDBUpdates()
Do the actual work.
LoggedUpdateMaintenance\getUpdateKey
getUpdateKey()
Get the update key name to go in the update log table.
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:434
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular option exists.
Definition: Maintenance.php:266
Maintenance\setBatchSize
setBatchSize( $s=0)
Set the batch size.
Definition: Maintenance.php:374