Add unit test for bug 32888
[lhc/web/wiklou.git] / maintenance / patchSql.php
1 <?php
2 /**
3 * Manually run an SQL patch outside of the general updaters.
4 * This ensures that the DB options (charset, prefix, engine) are correctly set.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
20 *
21 * @ingroup Maintenance
22 */
23
24 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
25
26 class PatchSql extends Maintenance {
27 public function __construct() {
28 parent::__construct();
29 $this->mDescription = "Run an SQL file into the DB, replacing prefix and charset vars";
30 $this->addArg( 'patch-name', 'Name of the patch file, either full path or in maintenance/archives' );
31 }
32
33 public function getDbType() {
34 return Maintenance::DB_ADMIN;
35 }
36
37 public function execute() {
38 $dbw = wfGetDB( DB_MASTER );
39 foreach ( $this->mArgs as $arg ) {
40 $files = array(
41 $arg,
42 $dbw->patchPath( $arg ),
43 $dbw->patchPath( "patch-$arg.sql" ),
44 );
45 foreach ( $files as $file ) {
46 if ( file_exists( $file ) ) {
47 $this->output( "$file ...\n" );
48 $dbw->sourceFile( $file );
49 continue 2;
50 }
51 }
52 $this->error( "Could not find $arg\n" );
53 }
54 $this->output( "done.\n" );
55 }
56 }
57
58 $maintClass = "PatchSql";
59 require_once( RUN_MAINTENANCE_IF_MAIN );