Index: branches/REL1_18/phase3/maintenance/Maintenance.php |
— | — | @@ -1263,3 +1263,71 @@ |
1264 | 1264 | return; |
1265 | 1265 | } |
1266 | 1266 | } |
| 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 @@ |
827 | 827 | 'DeleteArchivedRevisionsImplementation' => 'maintenance/deleteArchivedRevisions.inc', |
828 | 828 | 'DeleteDefaultMessages' => 'maintenance/deleteDefaultMessages.php', |
829 | 829 | 'FakeMaintenance' => 'maintenance/Maintenance.php', |
| 830 | + 'LoggedUpdateMaintenance' => 'maintenance/Maintenance.php', |
830 | 831 | 'Maintenance' => 'maintenance/Maintenance.php', |
831 | 832 | 'FixExtLinksProtocolRelative' => 'maintenance/fixExtLinksProtocolRelative.php', |
832 | 833 | 'PopulateCategory' => 'maintenance/populateCategory.php', |