Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
RenameRestrictions
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 2
6
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Rename restriction level
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Maintenance
22 */
23
24require_once __DIR__ . '/Maintenance.php';
25
26/**
27 * Maintenance script that updates page_restrictions and
28 * protected_titles tables to use a new name for a given
29 * restriction level.
30 *
31 * @ingroup Maintenance
32 */
33class RenameRestrictions extends Maintenance {
34    public function __construct() {
35        parent::__construct();
36        $this->addDescription( 'Rename a restriction level' );
37        $this->addArg( 'oldlevel', 'Old name of restriction level', true );
38        $this->addArg( 'newlevel', 'New name of restriction level', true );
39    }
40
41    public function execute() {
42        $oldLevel = $this->getArg( 0 );
43        $newLevel = $this->getArg( 1 );
44
45        $dbw = $this->getPrimaryDB();
46        $dbw->newUpdateQueryBuilder()
47            ->update( 'page_restrictions' )
48            ->set( [ 'pr_level' => $newLevel ] )
49            ->where( [ 'pr_level' => $oldLevel ] )
50            ->caller( __METHOD__ )
51            ->execute();
52        $dbw->newUpdateQueryBuilder()
53            ->update( 'protected_titles' )
54            ->set( [ 'pt_create_perm' => $newLevel ] )
55            ->where( [ 'pt_create_perm' => $oldLevel ] )
56            ->caller( __METHOD__ )
57            ->execute();
58    }
59
60}
61
62$maintClass = RenameRestrictions::class;
63require_once RUN_MAINTENANCE_IF_MAIN;