MediaWiki REL1_39
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_PRIMARY );
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 public function setForce( $forced = true ) {
59 $this->mOptions['force'] = $forced;
60 }
61
66 protected function updateSkippedMessage() {
67 $key = $this->getUpdateKey();
68
69 return "Update '{$key}' already logged as completed. Use --force to run it again.";
70 }
71
77 abstract protected function doDBUpdates();
78
83 abstract protected function getUpdateKey();
84}
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.
setForce( $forced=true)
Sets whether a run of this maintenance script has the force parameter set.
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)
const DB_PRIMARY
Definition defines.php:28