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
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.
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.
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
25 * @ingroup Maintenance
27 use MediaWiki\MediaWikiServices
;
29 if ( !defined( 'RUN_MAINTENANCE_IF_MAIN' ) ) {
30 echo "This file must be included after Maintenance.php\n";
34 // Wasn't included from the file scope, halt execution (probably wanted the class)
35 // If a class is using commandLine.inc (old school maintenance), they definitely
36 // cannot be included and will proceed with execution
37 if ( !Maintenance
::shouldExecute() && $maintClass != CommandLineInc
::class ) {
41 if ( !$maintClass ||
!class_exists( $maintClass ) ) {
42 echo "\$maintClass is not set or is set to a non-existent class.\n";
46 // Get an object to start us off
47 /** @var Maintenance $maintenance */
48 $maintenance = new $maintClass();
50 // Basic sanity checks and such
51 $maintenance->setup();
53 // We used to call this variable $self, but it was moved
54 // to $maintenance->mSelf. Keep that here for b/c
55 $self = $maintenance->getName();
57 // Define how settings are loaded (e.g. LocalSettings.php)
58 if ( !defined( 'MW_CONFIG_CALLBACK' ) && !defined( 'MW_CONFIG_FILE' ) ) {
59 define( 'MW_CONFIG_FILE', $maintenance->loadSettings() );
62 // Custom setup for Maintenance entry point
63 if ( !defined( 'MW_SETUP_CALLBACK' ) ) {
65 function wfMaintenanceSetup() {
66 // phpcs:ignore MediaWiki.NamingConventions.ValidGlobalName.wgPrefix
67 global $maintenance, $wgLocalisationCacheConf, $wgCacheDirectory;
68 if ( $maintenance->getDbType() === Maintenance
::DB_NONE
) {
69 if ( $wgLocalisationCacheConf['storeClass'] === false
70 && ( $wgLocalisationCacheConf['store'] == 'db'
71 ||
( $wgLocalisationCacheConf['store'] == 'detect' && !$wgCacheDirectory ) )
73 $wgLocalisationCacheConf['storeClass'] = LCStoreNull
::class;
77 $maintenance->finalSetup();
80 define( 'MW_SETUP_CALLBACK', 'wfMaintenanceSetup' );
83 require_once "$IP/includes/Setup.php";
85 // Initialize main config instance
86 $maintenance->setConfig( MediaWikiServices
::getInstance()->getMainConfig() );
88 // Sanity-check required extensions are installed
89 $maintenance->checkRequiredExtensions();
91 // A good time when no DBs have writes pending is around lag checks.
92 // This avoids having long running scripts just OOM and lose all the updates.
93 $maintenance->setAgentAndTriggers();
95 $maintenance->validateParamsAndArgs();
99 $success = $maintenance->execute();
100 } catch ( Exception
$ex ) {
103 $cls = get_class( $ex );
104 print "$cls from line {$ex->getLine()} of {$ex->getFile()}: {$ex->getMessage()}\n";
105 print $ex->getTraceAsString() . "\n";
106 $ex = $ex->getPrevious();
110 // Potentially debug globals
111 $maintenance->globals();
113 if ( $maintenance->getDbType() !== Maintenance
::DB_NONE
) {
114 // Perform deferred updates.
115 $lbFactory = MediaWikiServices
::getInstance()->getDBLoadBalancerFactory();
116 $lbFactory->commitMasterChanges( $maintClass );
117 DeferredUpdates
::doUpdates();
120 // log profiling info
121 wfLogProfilingData();
123 if ( isset( $lbFactory ) ) {
124 // Commit and close up!
125 $lbFactory->commitMasterChanges( 'doMaintenance' );
126 $lbFactory->shutdown( $lbFactory::SHUTDOWN_NO_CHRONPROT
);
129 // Exit with an error status if execute() returned false
130 if ( $success === false ) {