Debian Codegraph @

vendor/wikimedia/parsoid/tools/doMaintenance.php

raw
1 <?php
2 /**
3 * We want to make this whole thing as seamless as possible to the
4 * end-user. Unfortunately, we can't do _all_ of the work in the class
5 * because A) included files are not in global scope, but in the scope
6 * of their caller, and B) MediaWiki has way too many globals. So instead
7 * we'll kinda fake it, and do the requires() inline. <3 PHP
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
23 *
24 * @file
25 * @ingroup Maintenance
26 */
27
28 // THIS IS A STRIPPED DOWN VERSION OF doMaintenance.php from mediawiki core.
29
30 if ( !defined( 'PARSOID_RUN_MAINTENANCE_IF_MAIN' ) ) {
31 echo "This file must be included after Maintenance.php\n";
32 exit( 1 );
33 }
34
35 if ( !$maintClass || !class_exists( $maintClass ) ) {
36 echo "\$maintClass is not set or is set to a non-existent class.\n";
37 exit( 1 );
38 }
39
40 // Get an object to start us off
41 /** @var Maintenance $maintenance */
42 $maintenance = new $maintClass();
43
44 // Basic setup checks and such
45 $maintenance->setup();
46
47 $maintenance->finalSetup();
48
49 // Set an appropriate locale (T291234)
50 // Matches core's Setup.php
51 putenv( "LC_ALL=" . setlocale( LC_ALL, 'C.UTF-8', 'C' ) );
52
53 $maintenance->validateParamsAndArgs();
54
55 // Do the work
56 try {
57 $success = $maintenance->execute();
58 } catch ( Exception $ex ) {
59 $success = false;
60 while ( $ex ) {
61 $cls = get_class( $ex );
62 print "$cls from line {$ex->getLine()} of {$ex->getFile()}: {$ex->getMessage()}\n";
63 print $ex->getTraceAsString() . "\n";
64 $ex = $ex->getPrevious();
65 }
66 }
67
68 // Exit with an error status if execute() returned false
69 if ( $success === false ) {
70 exit( 1 );
71 }