r103033 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103032‎ | r103033 | r103034 >
Date:21:20, 14 November 2011
Author:reedy
Status:ok
Tags:
Comment:
REL1_18 Partial manual merge of r94370, r94382, r96578, r101019 to bring LoggedUpdateMaintenance
Modified paths:
  • /branches/REL1_18/phase3/includes/AutoLoader.php (modified) (history)
  • /branches/REL1_18/phase3/maintenance/Maintenance.php (modified) (history)

Diff [purge]

Index: branches/REL1_18/phase3/maintenance/Maintenance.php
@@ -1263,3 +1263,71 @@
12641264 return;
12651265 }
12661266 }
 1267+
 1268+/**
 1269+ * Class for scripts that perform database maintenance and want to log the
 1270+ * update in `updatelog` so we can later skip it
 1271+ */
 1272+abstract class LoggedUpdateMaintenance extends Maintenance {
 1273+ public function __construct() {
 1274+ parent::__construct();
 1275+ $this->addOption( 'force', 'Run the update even if it was completed already' );
 1276+ $this->setBatchSize( 200 );
 1277+ }
 1278+
 1279+ public function execute() {
 1280+ $db = $this->getDB( DB_MASTER );
 1281+ $key = $this->getUpdateKey();
 1282+
 1283+ if ( !$this->hasOption( 'force' ) &&
 1284+ $db->selectRow( 'updatelog', '1', array( 'ul_key' => $key ), __METHOD__ ) )
 1285+ {
 1286+ $this->output( "..." . $this->updateSkippedMessage() . "\n" );
 1287+ return true;
 1288+ }
 1289+
 1290+ if ( !$this->doDBUpdates() ) {
 1291+ return false;
 1292+ }
 1293+
 1294+ if (
 1295+ $db->insert( 'updatelog', array( 'ul_key' => $key ), __METHOD__, 'IGNORE' ) )
 1296+ {
 1297+ return true;
 1298+ } else {
 1299+ $this->output( $this->updatelogFailedMessage() . "\n" );
 1300+ return false;
 1301+ }
 1302+ }
 1303+
 1304+ /**
 1305+ * Message to show that the update was done already and was just skipped
 1306+ * @return String
 1307+ */
 1308+ protected function updateSkippedMessage() {
 1309+ $key = $this->getUpdateKey();
 1310+ return "Update '{$key}' already logged as completed.";
 1311+ }
 1312+
 1313+ /**
 1314+ * Message to show the the update log was unable to log the completion of this update
 1315+ * @return String
 1316+ */
 1317+ protected function updatelogFailedMessage() {
 1318+ $key = $this->getUpdateKey();
 1319+ return "Unable to log update '{$key}' as completed.";
 1320+ }
 1321+
 1322+ /**
 1323+ * Do the actual work. All child classes will need to implement this.
 1324+ * Return true to log the update as done or false (usually on failure).
 1325+ * @return Bool
 1326+ */
 1327+ abstract protected function doDBUpdates();
 1328+
 1329+ /**
 1330+ * Get the update key name to go in the update log table
 1331+ * @return String
 1332+ */
 1333+ abstract protected function getUpdateKey();
 1334+}
\ No newline at end of file
Index: branches/REL1_18/phase3/includes/AutoLoader.php
@@ -826,6 +826,7 @@
827827 'DeleteArchivedRevisionsImplementation' => 'maintenance/deleteArchivedRevisions.inc',
828828 'DeleteDefaultMessages' => 'maintenance/deleteDefaultMessages.php',
829829 'FakeMaintenance' => 'maintenance/Maintenance.php',
 830+ 'LoggedUpdateMaintenance' => 'maintenance/Maintenance.php',
830831 'Maintenance' => 'maintenance/Maintenance.php',
831832 'FixExtLinksProtocolRelative' => 'maintenance/fixExtLinksProtocolRelative.php',
832833 'PopulateCategory' => 'maintenance/populateCategory.php',

Follow-up revisions

RevisionCommit summaryAuthorDate
r104716Merge r103033 from REL1_18 to fix fatal on fixExtLinksProtocolRelative from r...reedy18:56, 30 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r94370* Added LoggedUpdateMaintenance subclass...aaron19:11, 12 August 2011
r94382Changed PopulateImageSha1 to use LoggedUpdateMaintenance and added it to $pos...aaron20:37, 12 August 2011
r96578Tweaks to LoggedUpdateMaintenance:...demon15:52, 8 September 2011
r101019Added default updateSkippedMessage() messageaaron18:37, 27 October 2011

Status & tagging log