MediaWiki  master
doMaintenance.php
Go to the documentation of this file.
1 <?php
28 
29 if ( !defined( 'RUN_MAINTENANCE_IF_MAIN' ) ) {
30  echo "This file must be included after Maintenance.php\n";
31  exit( 1 );
32 }
33 
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 ) {
38  return;
39 }
40 
41 if ( !$maintClass || !class_exists( $maintClass ) ) {
42  echo "\$maintClass is not set or is set to a non-existent class.\n";
43  exit( 1 );
44 }
45 
46 // Define the MediaWiki entrypoint
47 define( 'MEDIAWIKI', true );
48 
49 // This environment variable is ensured present by Maintenance.php.
50 $IP = getenv( 'MW_INSTALL_PATH' );
51 
52 // Get an object to start us off
55 
56 // Basic sanity checks and such
57 $maintenance->setup();
58 
59 // We used to call this variable $self, but it was moved
60 // to $maintenance->mSelf. Keep that here for b/c
61 $self = $maintenance->getName();
62 
63 // Define how settings are loaded (e.g. LocalSettings.php)
64 if ( !defined( 'MW_CONFIG_CALLBACK' ) && !defined( 'MW_CONFIG_FILE' ) ) {
65  define( 'MW_CONFIG_FILE', $maintenance->loadSettings() );
66 }
67 
68 // Custom setup for Maintenance entry point
69 if ( !defined( 'MW_SETUP_CALLBACK' ) ) {
70 
71  function wfMaintenanceSetup() {
72  // phpcs:ignore MediaWiki.NamingConventions.ValidGlobalName.wgPrefix
74  if ( $maintenance->getDbType() === Maintenance::DB_NONE ) {
75  if ( $wgLocalisationCacheConf['storeClass'] === false
76  && ( $wgLocalisationCacheConf['store'] == 'db'
77  || ( $wgLocalisationCacheConf['store'] == 'detect' && !$wgCacheDirectory ) )
78  ) {
79  $wgLocalisationCacheConf['storeClass'] = LCStoreNull::class;
80  }
81  }
82 
83  $maintenance->finalSetup();
84  }
85 
86  define( 'MW_SETUP_CALLBACK', 'wfMaintenanceSetup' );
87 }
88 
89 require_once "$IP/includes/Setup.php";
90 
91 // Initialize main config instance
92 $maintenance->setConfig( MediaWikiServices::getInstance()->getMainConfig() );
93 
94 // Sanity-check required extensions are installed
95 $maintenance->checkRequiredExtensions();
96 
97 // A good time when no DBs have writes pending is around lag checks.
98 // This avoids having long running scripts just OOM and lose all the updates.
99 $maintenance->setAgentAndTriggers();
100 
101 $maintenance->validateParamsAndArgs();
102 
103 // Do the work
104 try {
105  $success = $maintenance->execute();
106 } catch ( Exception $ex ) {
107  $success = false;
108  $exReportMessage = '';
109  while ( $ex ) {
110  $cls = get_class( $ex );
111  $exReportMessage .= "$cls from line {$ex->getLine()} of {$ex->getFile()}: {$ex->getMessage()}\n";
112  $exReportMessage .= $ex->getTraceAsString() . "\n";
113  $ex = $ex->getPrevious();
114  }
115  // Print the exception to stderr if possible, don't mix it in
116  // with stdout output.
117  if ( defined( 'STDERR' ) ) {
118  fwrite( STDERR, $exReportMessage );
119  } else {
120  echo $exReportMessage;
121  }
122 }
123 
124 // Potentially debug globals
125 $maintenance->globals();
126 
127 if ( $maintenance->getDbType() !== Maintenance::DB_NONE &&
128  // Service might be disabled, e.g. when running install.php
129  !MediaWikiServices::getInstance()->isServiceDisabled( 'DBLoadBalancerFactory' )
130 ) {
131  // Perform deferred updates.
132  $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
133  $lbFactory->commitMasterChanges( $maintClass );
135 }
136 
137 // log profiling info
139 
140 if ( isset( $lbFactory ) ) {
141  // Commit and close up!
142  $lbFactory->commitMasterChanges( 'doMaintenance' );
143  $lbFactory->shutdown( $lbFactory::SHUTDOWN_NO_CHRONPROT );
144 }
145 
146 // Exit with an error status if execute() returned false
147 if ( $success === false ) {
148  exit( 1 );
149 }
$maintClass
$maintClass
Definition: addChangeTag.php:62
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:146
$wgCacheDirectory
$wgCacheDirectory
Directory for caching data in the local filesystem.
Definition: DefaultSettings.php:2408
$success
$success
Definition: NoLocalSettings.php:42
$wgLocalisationCacheConf
$wgLocalisationCacheConf
Localisation cache configuration.
Definition: DefaultSettings.php:2724
$maintenance
$maintenance
Definition: doMaintenance.php:54
Maintenance\shouldExecute
static shouldExecute()
Should we execute the maintenance script, or just allow it to be included as a standalone class?...
Definition: Maintenance.php:184
Maintenance\DB_NONE
const DB_NONE
Constants for DB access type.
Definition: Maintenance.php:58
$IP
$IP
Definition: doMaintenance.php:50
DeferredUpdates\doUpdates
static doUpdates( $mode='run', $stage=self::ALL)
Consume the list of deferred updates and execute them.
Definition: DeferredUpdates.php:171
$self
$self
Definition: doMaintenance.php:61
wfLogProfilingData
wfLogProfilingData()
Definition: GlobalFunctions.php:1072