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