* Use Maintenance::runChild() to get the child script instance
[lhc/web/wiklou.git] / maintenance / update.php
1 <?php
2 /**
3 * Run all updaters.
4 *
5 * This is used when the database schema is modified and we need to apply patches.
6 *
7 * @file
8 * @todo document
9 * @ingroup Maintenance
10 */
11
12 $wgUseMasterForMaintenance = true;
13 require_once( 'Maintenance.php' );
14
15 class UpdateMediaWiki extends Maintenance {
16
17 public function __construct() {
18 parent::__construct();
19 $this->mDescription = "MediaWiki database updater";
20 $this->addOption( 'skip-compat-checks', 'Skips compatibility checks, mostly for developers' );
21 $this->addOption( 'quick', 'Skip 5 second countdown before starting' );
22 $this->addOption( 'doshared', 'Also update shared tables' );
23 $this->addOption( 'nopurge', 'Do not purge the objectcache table after updates' );
24 }
25
26 public function getDbType() {
27 return Maintenance::DB_ADMIN;
28 }
29
30 public function execute() {
31 global $wgVersion, $wgTitle;
32
33 $wgTitle = Title::newFromText( "MediaWiki database updater" );
34
35 $this->output( "MediaWiki {$wgVersion} Updater\n\n" );
36
37 if ( !$this->hasOption( 'skip-compat-checks' ) ) {
38 install_version_checks();
39 } else {
40 $this->output( "Skipping compatibility checks, proceed at your own risk (Ctrl+C to abort)\n" );
41 wfCountdown( 5 );
42 }
43
44 # Attempt to connect to the database as a privileged user
45 # This will vomit up an error if there are permissions problems
46 $db = wfGetDB( DB_MASTER );
47
48 $this->output( "Going to run database updates for " . wfWikiID() . "\n" );
49 $this->output( "Depending on the size of your database this may take a while!\n" );
50
51 if ( !$this->hasOption( 'quick' ) ) {
52 $this->output( "Abort with control-c in the next five seconds (skip this countdown with --quick) ... " );
53 wfCountDown( 5 );
54 }
55
56 $shared = $this->hasOption( 'doshared' );
57 $purge = !$this->hasOption( 'nopurge' );
58
59 $updater = DatabaseUpdater::newForDb( $db, $shared );
60 $updater->doUpdates( $purge );
61
62 foreach( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
63 $this->runChild( $maint )->execute();
64 }
65
66 $this->output( "\nDone.\n" );
67 }
68
69 protected function afterFinalSetup() {
70 global $wgLocalisationCacheConf;
71
72 # Don't try to access the database
73 # This needs to be disabled early since extensions will try to use the l10n
74 # cache from $wgExtensionSetupFunctions (bug 20471)
75 $wgLocalisationCacheConf = array(
76 'class' => 'LocalisationCache',
77 'storeClass' => 'LCStore_Null',
78 'storeDirectory' => false,
79 'manualRecache' => false,
80 );
81 }
82 }
83
84 $maintClass = 'UpdateMediaWiki';
85 require_once( DO_MAINTENANCE );