| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Maintenance; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
abstract class LoggedUpdateMaintenance extends Maintenance { |
| 29 |
public function __construct() { |
| 30 |
parent::__construct(); |
| 31 |
$this->addOption( 'force', 'Run the update even if it was completed already' ); |
| 32 |
$this->setBatchSize( 200 ); |
| 33 |
} |
| 34 |
|
| 35 |
public function execute() { |
| 36 |
$db = $this->getPrimaryDB(); |
| 37 |
$key = $this->getUpdateKey(); |
| 38 |
$queryBuilder = $db->newSelectQueryBuilder() |
| 39 |
->select( '1' ) |
| 40 |
->from( 'updatelog' ) |
| 41 |
->where( [ 'ul_key' => $key ] ); |
| 42 |
|
| 43 |
if ( !$this->hasOption( 'force' ) |
| 44 |
&& $queryBuilder->caller( __METHOD__ )->fetchRow() |
| 45 |
) { |
| 46 |
$this->output( "..." . $this->updateSkippedMessage() . "\n" ); |
| 47 |
|
| 48 |
return true; |
| 49 |
} |
| 50 |
|
| 51 |
if ( !$this->doDBUpdates() ) { |
| 52 |
return false; |
| 53 |
} |
| 54 |
|
| 55 |
$db->newInsertQueryBuilder() |
| 56 |
->insertInto( 'updatelog' ) |
| 57 |
->ignore() |
| 58 |
->row( [ 'ul_key' => $key ] ) |
| 59 |
->caller( __METHOD__ )->execute(); |
| 60 |
|
| 61 |
return true; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
public function setForce( $forced = true ) { |
| 69 |
$this->setOption( 'force', $forced ); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
protected function updateSkippedMessage() { |
| 77 |
$key = $this->getUpdateKey(); |
| 78 |
|
| 79 |
return "Update '{$key}' already logged as completed. Use --force to run it again."; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
abstract protected function doDBUpdates(); |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
abstract protected function getUpdateKey(); |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
class_alias( LoggedUpdateMaintenance::class, 'LoggedUpdateMaintenance' ); |