Move DatabaseType to Database.php
[lhc/web/wiklou.git] / maintenance / update.php
index d2dcbf9..5809e60 100644 (file)
@@ -1,65 +1,95 @@
 <?php
-require_once 'counter.php';
 /**
  * Run all updaters.
  *
+ * This is used when the database schema is modified and we need to apply patches.
+ *
+ * @file
  * @todo document
- * @package MediaWiki
- * @subpackage Maintenance
+ * @ingroup Maintenance
  */
 
-/** */
 $wgUseMasterForMaintenance = true;
-$options = array( 'quick' );
-require_once( "commandLine.inc" );
-require_once( "updaters.inc" );
-$wgTitle = Title::newFromText( "MediaWiki database updater" );
-$dbclass = 'Database' . ucfirst( $wgDBtype ) ;
-
-echo( "MediaWiki {$wgVersion} Updater\n\n" );
-
-# Do a pre-emptive check to ensure we've got credentials supplied
-# We can't, at this stage, check them, but we can detect their absence,
-# which seems to cause most of the problems people whinge about
-if( !isset( $wgDBadminuser ) || !isset( $wgDBadminpassword ) ) {
-       echo( "No superuser credentials could be found. Please provide the details\n" );
-       echo( "of a user with appropriate permissions to update the database. See\n" );
-       echo( "AdminSettings.sample for more details.\n\n" );
-       exit();
-}
+require_once( 'Maintenance.php' );
 
-# Attempt to connect to the database as a privileged user
-# This will vomit up an error if there are permissions problems
-$wgDatabase = new $dbclass( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname, 1 );
+class UpdateMediaWiki extends Maintenance {
 
-if( !$wgDatabase->isOpen() ) {
-       # Appears to have failed
-       echo( "A connection to the database could not be established. Check the\n" );
-       echo( "values of \$wgDBadminuser and \$wgDBadminpassword.\n" );
-       exit();
-}
+       public function __construct() {
+               parent::__construct();
+               $this->mDescription = "MediaWiki database updater";
+               $this->addOption( 'skip-compat-checks', 'Skips compatibility checks, mostly for developers' );
+               $this->addOption( 'quick', 'Skip 5 second countdown before starting' );
+               $this->addOption( 'doshared', 'Also update shared tables' );
+               $this->addOption( 'nopurge', 'Do not purge the objectcache table after updates' );
+       }
 
-print "Going to run database updates for ".wfWikiID()."\n";
-print "Depending on the size of your database this may take a while!\n";
+       public function getDbType() {
+               return self::DB_ADMIN;
+       }
 
-if( !isset( $options['quick'] ) ) {
-       print "Abort with control-c in the next five seconds... ";
+       public function execute() {
+               global $wgVersion, $wgTitle;
 
-       for ($i = 6; $i >= 1;) {
-               print_c($i, --$i);
-               sleep(1);
-       }
-       echo "\n";
-}
+               $wgTitle = Title::newFromText( "MediaWiki database updater" );
 
-if ( isset( $options['doshared'] ) ) {
-       $doShared = true;
-} else {
-       $doShared = false;
-}
+               $this->output( "MediaWiki {$wgVersion} Updater\n\n" );
+
+               if ( !isset( $options['skip-compat-checks'] ) ) {
+                       install_version_checks();
+               } else {
+                       $this->output( "Skipping compatibility checks, proceed at your own risk (Ctrl+C to abort)\n" );
+                       wfCountdown( 5 );
+               }
+
+               # Attempt to connect to the database as a privileged user
+               # This will vomit up an error if there are permissions problems
+               $db = wfGetDB( DB_MASTER );
+
+               $this->output( "Going to run database updates for " . wfWikiID() . "\n" );
+               $this->output( "Depending on the size of your database this may take a while!\n" );
 
-do_all_updates( $doShared );
+               if ( !$this->hasOption( 'quick' ) ) {
+                       $this->output( "Abort with control-c in the next five seconds (skip this countdown with --quick) ... " );
+                       wfCountDown( 5 );
+               }
 
-print "Done.\n";
+               $shared = $this->hasOption( 'doshared' );
+               $purge = !$this->hasOption( 'nopurge' );
+
+               $updater = DatabaseUpdater::newForDb( $db, $shared );
+               $updater->doUpdates( $purge );
+
+               if ( !defined( 'MW_NO_SETUP' ) ) {
+                       define( 'MW_NO_SETUP', true );
+               }
+
+               foreach( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
+                       call_user_func_array( array( new $maint, 'execute' ), array() );
+               }
+
+               if ( $db->getType() === 'postgres' ) {
+                       return;
+               }
+
+               do_stats_init();
+
+               $this->output( "Done.\n" );
+       }
+
+       protected function afterFinalSetup() {
+               global $wgLocalisationCacheConf;
+
+               # Don't try to access the database
+               # This needs to be disabled early since extensions will try to use the l10n
+               # cache from $wgExtensionSetupFunctions (bug 20471)
+               $wgLocalisationCacheConf = array(
+                       'class' => 'LocalisationCache',
+                       'storeClass' => 'LCStore_Null',
+                       'storeDirectory' => false,
+                       'manualRecache' => false,
+               );
+       }
+}
 
-?>
+$maintClass = 'UpdateMediaWiki';
+require_once( DO_MAINTENANCE );