Debian Codegraph @

maintenance/renameRestrictions.php

raw symbols SCIP
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
24 // @codeCoverageIgnoreStart
25 require_once __DIR__ . '/Maintenance.php';
26 // @codeCoverageIgnoreEnd
27
28 /**
29 * Maintenance script that updates page_restrictions and
30 * protected_titles tables to use a new name for a given
31 * restriction level.
32 *
33 * @ingroup Maintenance
34 */
35 class RenameRestrictions extends Maintenance {
36 public function __construct() {
37 parent::__construct();
38 $this->addDescription( 'Rename a restriction level' );
39 $this->addArg( 'oldlevel', 'Old name of restriction level', true );
40 $this->addArg( 'newlevel', 'New name of restriction level', true );
41 }
42
43 public function execute() {
44 $oldLevel = $this->getArg( 0 );
45 $newLevel = $this->getArg( 1 );
46
47 $dbw = $this->getPrimaryDB();
48 $dbw->newUpdateQueryBuilder()
49 ->update( 'page_restrictions' )
50 ->set( [ 'pr_level' => $newLevel ] )
51 ->where( [ 'pr_level' => $oldLevel ] )
52 ->caller( __METHOD__ )
53 ->execute();
54 $dbw->newUpdateQueryBuilder()
55 ->update( 'protected_titles' )
56 ->set( [ 'pt_create_perm' => $newLevel ] )
57 ->where( [ 'pt_create_perm' => $oldLevel ] )
58 ->caller( __METHOD__ )
59 ->execute();
60 }
61
62 }
63
64 // @codeCoverageIgnoreStart
65 $maintClass = RenameRestrictions::class;
66 require_once RUN_MAINTENANCE_IF_MAIN;
67 // @codeCoverageIgnoreEnd