Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
19 / 19 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| RenameRestrictions | |
100.00% |
19 / 19 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Rename restriction level |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | * @ingroup Maintenance |
| 8 | */ |
| 9 | |
| 10 | use MediaWiki\Maintenance\Maintenance; |
| 11 | |
| 12 | // @codeCoverageIgnoreStart |
| 13 | require_once __DIR__ . '/Maintenance.php'; |
| 14 | // @codeCoverageIgnoreEnd |
| 15 | |
| 16 | /** |
| 17 | * Maintenance script that updates page_restrictions and |
| 18 | * protected_titles tables to use a new name for a given |
| 19 | * restriction level. |
| 20 | * |
| 21 | * @ingroup Maintenance |
| 22 | */ |
| 23 | class RenameRestrictions extends Maintenance { |
| 24 | public function __construct() { |
| 25 | parent::__construct(); |
| 26 | $this->addDescription( 'Rename a restriction level' ); |
| 27 | $this->addArg( 'oldlevel', 'Old name of restriction level', true ); |
| 28 | $this->addArg( 'newlevel', 'New name of restriction level', true ); |
| 29 | } |
| 30 | |
| 31 | public function execute() { |
| 32 | $oldLevel = $this->getArg( 0 ); |
| 33 | $newLevel = $this->getArg( 1 ); |
| 34 | |
| 35 | $dbw = $this->getPrimaryDB(); |
| 36 | $dbw->newUpdateQueryBuilder() |
| 37 | ->update( 'page_restrictions' ) |
| 38 | ->set( [ 'pr_level' => $newLevel ] ) |
| 39 | ->where( [ 'pr_level' => $oldLevel ] ) |
| 40 | ->caller( __METHOD__ ) |
| 41 | ->execute(); |
| 42 | $dbw->newUpdateQueryBuilder() |
| 43 | ->update( 'protected_titles' ) |
| 44 | ->set( [ 'pt_create_perm' => $newLevel ] ) |
| 45 | ->where( [ 'pt_create_perm' => $oldLevel ] ) |
| 46 | ->caller( __METHOD__ ) |
| 47 | ->execute(); |
| 48 | } |
| 49 | |
| 50 | } |
| 51 | |
| 52 | // @codeCoverageIgnoreStart |
| 53 | $maintClass = RenameRestrictions::class; |
| 54 | require_once RUN_MAINTENANCE_IF_MAIN; |
| 55 | // @codeCoverageIgnoreEnd |