30 require_once __DIR__ .
'/Maintenance.php';
44 parent::__construct();
46 $this->
addOption(
'skip-compat-checks',
'Skips compatibility checks, mostly for developers' );
47 $this->
addOption(
'quick',
'Skip 5 second countdown before starting' );
48 $this->
addOption(
'doshared',
'Also update shared tables' );
49 $this->
addOption(
'noschema',
'Only do the updates that are not done during schema updates' );
52 'Output SQL to do the schema updates instead of doing them. Works '
53 .
'even when $wgAllowSchemaUpdates is false',
57 $this->
addOption(
'force',
'Override when $wgAllowSchemaUpdates disables this script' );
59 'skip-external-dependencies',
60 'Skips checking whether external dependencies are up to date, mostly for developers'
63 'skip-config-validation',
64 'Skips checking whether the existing configuration is valid'
72 private function compatChecks() {
75 $pcreVersion = explode(
' ', PCRE_VERSION, 2 )[0];
76 if ( version_compare( $pcreVersion, $minimumPcreVersion,
'<' ) ) {
78 "PCRE $minimumPcreVersion or later is required.\n" .
79 "Your PHP binary is linked with PCRE $pcreVersion.\n\n" .
80 "More information:\n" .
81 "https://www.mediawiki.org/wiki/Manual:Errors_and_symptoms/PCRE\n\n" .
94 $this->
fatalError(
"Do not run update.php on this wiki. If you're seeing this you should\n"
95 .
"probably ask for some help in performing your schema updates or use\n"
96 .
"the --noschema and --schema options to get an SQL file for someone\n"
97 .
"else to inspect and run.\n\n"
98 .
"If you know what you are doing, you can continue with --force\n" );
101 $this->fileHandle =
null;
102 if ( substr( $this->
getOption(
'schema',
'' ), 0, 2 ) ===
"--" ) {
103 $this->
fatalError(
"The --schema option requires a file as an argument.\n" );
104 } elseif ( $this->
hasOption(
'schema' ) ) {
106 $this->fileHandle = fopen(
$file,
"w" );
107 if ( $this->fileHandle ===
false ) {
108 $err = error_get_last();
109 $this->
fatalError(
"Problem opening the schema file for writing: $file\n\t{$err['message']}" );
114 if ( !$this->
hasOption(
'skip-config-validation' ) ) {
115 $this->validateSettings();
119 $wgMessagesDirs[
'MediawikiInstaller'] = dirname( __DIR__ ) .
'/includes/installer/i18n';
121 $lang = MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage(
'en' );
128 define(
'MW_UPDATER',
true );
132 MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->waitForReplication();
134 if ( !$this->
hasOption(
'skip-compat-checks' ) ) {
135 $this->compatChecks();
137 $this->
output(
"Skipping compatibility checks, proceed at your own risk (Ctrl+C to abort)\n" );
142 if ( !$this->
hasOption(
'skip-external-dependencies' ) ) {
143 $composerLockUpToDate = $this->
runChild( CheckComposerLockUpToDate::class );
144 $composerLockUpToDate->execute();
147 "Skipping checking whether external dependencies are up to date, proceed at your own risk\n"
151 # Attempt to connect to the database as a privileged user
152 # This will vomit up an error if there are permissions problems
155 # Check to see whether the database server meets the minimum requirements
158 $status = $dbInstallerClass::meetsMinimumRequirement( $db->getServerVersion() );
159 if ( !$status->isOK() ) {
161 $text = $status->getWikiText();
165 $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
166 $this->
output(
"Going to run database updates for $dbDomain\n" );
167 if ( $db->getType() ===
'sqlite' ) {
169 '@phan-var DatabaseSqlite $db';
170 $this->
output(
"Using SQLite file: '{$db->getDbFilePath()}'\n" );
172 $this->
output(
"Depending on the size of your database this may take a while!\n" );
175 $this->
output(
"Abort with control-c in the next five seconds "
176 .
"(skip this countdown with --quick) ..." );
180 $time1 = microtime(
true );
182 $shared = $this->
hasOption(
'doshared' );
184 $updates = [
'core',
'extensions' ];
187 $updates[] =
'noschema';
189 $updates[] =
'stats';
198 if ( $updater->fieldExists(
'archive',
'ar_user' ) ) {
200 "Can not upgrade from versions older than 1.35, please upgrade to that version or later first."
204 $updater->doUpdates( $updates );
206 foreach ( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
212 if ( !$isLoggedUpdate && $updater->updateRowExists( $maint ) ) {
217 if ( !$isLoggedUpdate ) {
218 $updater->insertUpdateRow( $maint );
222 $updater->setFileAccess();
224 $updater->purgeCache();
226 $time2 = microtime(
true );
228 $timeDiff =
$lang->formatTimePeriod( $time2 - $time1 );
229 $this->
output(
"\nDone in $timeDiff.\n" );
235 # Don't try to access the database
236 # This needs to be disabled early since extensions will try to use the l10n
237 # cache from $wgExtensionFunctions (T22471)
239 'class' => LocalisationCache::class,
240 'storeClass' => LCStoreNull::class,
241 'storeDirectory' =>
false,
242 'manualRecache' =>
false,
252 $this->
getHookRunner()->onMaintenanceUpdateAddParams( $params );
257 foreach ( $params as $name => $param ) {
261 isset( $param[
'require'] ) ? $param[
'require'] :
false,
262 isset( $param[
'withArg'] ) ? $param[
'withArg'] :
false,
263 isset( $param[
'shortName'] ) ? $param[
'shortName'] :
false,
264 isset( $param[
'multiOccurrence'] ) ? $param[
'multiOccurrence'] :
false
268 parent::validateParamsAndArgs();
271 private function formatWarnings( array $warnings ) {
273 foreach ( $warnings as $warning ) {
274 $warning = wordwrap( $warning, 75,
"\n " );
275 $text .=
"* $warning\n";
280 private function validateSettings() {
281 $settings = SettingsBuilder::getInstance();
284 if ( $settings->getWarnings() ) {
285 $warnings = $settings->getWarnings();
288 $status = $settings->validate();
289 if ( !$status->isOK() ) {
290 foreach ( $status->getErrorsByType(
'error' ) as $msg ) {
291 $msg =
wfMessage( $msg[
'message'], ...$msg[
'params'] );
292 $warnings[] = $msg->text();
296 $deprecations = $settings->detectDeprecatedConfig();
297 foreach ( $deprecations as $key => $msg ) {
298 $warnings[] =
"$key is deprecated: $msg";
301 $obsolete = $settings->detectObsoleteConfig();
302 foreach ( $obsolete as $key => $msg ) {
303 $warnings[] =
"$key is obsolete: $msg";
307 $this->
fatalError(
"Some of your configuration settings caused a warning:\n\n"
308 . $this->formatWarnings( $warnings ) .
"\n"
309 .
"Please correct the issue before running update.php again.\n"
310 .
"If you know what you are doing, you can bypass this check\n"
311 .
"using --skip-config-validation.\n" );
317 require_once RUN_MAINTENANCE_IF_MAIN;
const MW_VERSION
The running version of MediaWiki.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode) $wgLang
static newForDB(IMaintainableDatabase $db, $shared=false, Maintenance $maintenance=null)
const MINIMUM_PCRE_VERSION
The oldest version of PCRE we can support.
static getDBInstallerClass( $type)
Get the DatabaseInstaller class name for this type.
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
execute()
Do the actual work.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
output( $out, $channel=null)
Throw some output to the user.
getHookRunner()
Get a HookRunner for running core hooks.
hasOption( $name)
Checks to see if a particular option was set.
countDown( $seconds)
Count down from $seconds to zero on the terminal, with a one-second pause between showing each number...
runChild( $maintClass, $classFile=null)
Run a child maintenance script.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
static getMain()
Get the RequestContext object associated with the main request.
$wgMessagesDirs
Config variable stub for the MessagesDirs setting, for use by phpdoc and IDEs.
$wgAllowSchemaUpdates
Config variable stub for the AllowSchemaUpdates setting, for use by phpdoc and IDEs.
$wgLocalisationCacheConf
Config variable stub for the LocalisationCacheConf setting, for use by phpdoc and IDEs.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
if(!isset( $args[0])) $lang