MediaWiki
1.34.0
doMaintenance.php
Go to the documentation of this file.
1
<?php
27
use
MediaWiki\MediaWikiServices
;
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
// Get an object to start us off
48
$maintenance
=
new
$maintClass
();
49
50
// Basic sanity checks and such
51
$maintenance
->setup();
52
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();
56
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() );
60
}
61
62
// Custom setup for Maintenance entry point
63
if
( !defined(
'MW_SETUP_CALLBACK'
) ) {
64
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
) )
72
) {
73
$wgLocalisationCacheConf
[
'storeClass'
] = LCStoreNull::class;
74
}
75
}
76
77
$maintenance
->finalSetup();
78
}
79
80
define(
'MW_SETUP_CALLBACK'
,
'wfMaintenanceSetup'
);
81
}
82
83
require_once
"$IP/includes/Setup.php"
;
84
85
// Initialize main config instance
86
$maintenance
->setConfig( MediaWikiServices::getInstance()->getMainConfig() );
87
88
// Sanity-check required extensions are installed
89
$maintenance
->checkRequiredExtensions();
90
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();
94
95
$maintenance
->validateParamsAndArgs();
96
97
// Do the work
98
try
{
99
$success
=
$maintenance
->execute();
100
}
catch
( Exception $ex ) {
101
$success
=
false
;
102
$exReportMessage =
''
;
103
while
( $ex ) {
104
$cls = get_class( $ex );
105
$exReportMessage .=
"$cls from line {$ex->getLine()} of {$ex->getFile()}: {$ex->getMessage()}\n"
;
106
$exReportMessage .= $ex->getTraceAsString() .
"\n"
;
107
$ex = $ex->getPrevious();
108
}
109
// Print the exception to stderr if possible, don't mix it in
110
// with stdout output.
111
if
( defined(
'STDERR'
) ) {
112
fwrite( STDERR, $exReportMessage );
113
}
else
{
114
echo $exReportMessage;
115
}
116
}
117
118
// Potentially debug globals
119
$maintenance
->globals();
120
121
if
(
$maintenance
->getDbType() !==
Maintenance::DB_NONE
&&
122
// Service might be disabled, e.g. when running install.php
123
!MediaWikiServices::getInstance()->isServiceDisabled(
'DBLoadBalancerFactory'
)
124
) {
125
// Perform deferred updates.
126
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
127
$lbFactory->commitMasterChanges(
$maintClass
);
128
DeferredUpdates::doUpdates
();
129
}
130
131
// log profiling info
132
wfLogProfilingData
();
133
134
if
( isset( $lbFactory ) ) {
135
// Commit and close up!
136
$lbFactory->commitMasterChanges(
'doMaintenance'
);
137
$lbFactory->shutdown( $lbFactory::SHUTDOWN_NO_CHRONPROT );
138
}
139
140
// Exit with an error status if execute() returned false
141
if
(
$success
===
false
) {
142
exit( 1 );
143
}
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition:
MediaWikiServices.php:117
$maintClass
$maintClass
Definition:
CountFancyCaptchas.php:54
$wgCacheDirectory
$wgCacheDirectory
Directory for caching data in the local filesystem.
Definition:
DefaultSettings.php:2326
$success
$success
Definition:
NoLocalSettings.php:42
$wgLocalisationCacheConf
$wgLocalisationCacheConf
Localisation cache configuration.
Definition:
DefaultSettings.php:2624
Maintenance\shouldExecute
static shouldExecute()
Should we execute the maintenance script, or just allow it to be included as a standalone class?...
Definition:
Maintenance.php:210
Maintenance\DB_NONE
const DB_NONE
Constants for DB access type.
Definition:
Maintenance.php:87
DeferredUpdates\doUpdates
static doUpdates( $mode='run', $stage=self::ALL)
Do any deferred updates and clear the list.
Definition:
DeferredUpdates.php:139
$self
$self
Definition:
doMaintenance.php:55
$maintenance
$maintenance
Definition:
doMaintenance.php:48
wfLogProfilingData
wfLogProfilingData()
Definition:
GlobalFunctions.php:1086
maintenance
doMaintenance.php
Generated on Thu Dec 19 2019 14:55:27 for MediaWiki by
1.8.16