addOption( 'force', 'Run the update even if it was completed already' ); $this->setBatchSize( 200 ); } public function execute() { $db = $this->getDB( DB_MASTER ); $key = $this->getUpdateKey(); if ( !$this->hasOption( 'force' ) && $db->selectRow( 'updatelog', '1', [ 'ul_key' => $key ], __METHOD__ ) ) { $this->output( "..." . $this->updateSkippedMessage() . "\n" ); return true; } if ( !$this->doDBUpdates() ) { return false; } $db->insert( 'updatelog', [ 'ul_key' => $key ], __METHOD__, [ 'IGNORE' ] ); return true; } /** * Message to show that the update was done already and was just skipped * @return string */ protected function updateSkippedMessage() { $key = $this->getUpdateKey(); return "Update '{$key}' already logged as completed. Use --force to run it again."; } /** * Do the actual work. All child classes will need to implement this. * Return true to log the update as done or false (usually on failure). * @return bool */ abstract protected function doDBUpdates(); /** * Get the update key name to go in the update log table * @return string */ abstract protected function getUpdateKey(); }