[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/maintenance/ -> update.php (source)

   1  #!/usr/bin/env php
   2  <?php
   3  /**
   4   * Run all updaters.
   5   *
   6   * This is used when the database schema is modified and we need to apply patches.
   7   * It is kept compatible with php 4 parsing so that it can give out a meaningful error.
   8   *
   9   * This program is free software; you can redistribute it and/or modify
  10   * it under the terms of the GNU General Public License as published by
  11   * the Free Software Foundation; either version 2 of the License, or
  12   * (at your option) any later version.
  13   *
  14   * This program is distributed in the hope that it will be useful,
  15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17   * GNU General Public License for more details.
  18   *
  19   * You should have received a copy of the GNU General Public License along
  20   * with this program; if not, write to the Free Software Foundation, Inc.,
  21   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22   * http://www.gnu.org/copyleft/gpl.html
  23   *
  24   * @file
  25   * @todo document
  26   * @ingroup Maintenance
  27   */
  28  
  29  if ( !function_exists( 'version_compare' ) || ( version_compare( PHP_VERSION, '5.3.2' ) < 0 ) ) {
  30      require dirname( __FILE__ ) . '/../includes/PHPVersionError.php';
  31      wfPHPVersionError( 'cli' );
  32  }
  33  
  34  $wgUseMasterForMaintenance = true;
  35  require_once  __DIR__ . '/Maintenance.php';
  36  
  37  /**
  38   * Maintenance script to run database schema updates.
  39   *
  40   * @ingroup Maintenance
  41   */
  42  class UpdateMediaWiki extends Maintenance {
  43  	function __construct() {
  44          parent::__construct();
  45          $this->mDescription = "MediaWiki database updater";
  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( 'nopurge', 'Do not purge the objectcache table after updates' );
  50          $this->addOption( 'noschema', 'Only do the updates that are not done during schema updates' );
  51          $this->addOption(
  52              'schema',
  53              'Output SQL to do the schema updates instead of doing them. Works '
  54                  . 'even when $wgAllowSchemaUpdates is false',
  55              false,
  56              true
  57          );
  58          $this->addOption( 'force', 'Override when $wgAllowSchemaUpdates disables this script' );
  59      }
  60  
  61  	function getDbType() {
  62          /* If we used the class constant PHP4 would give a parser error here */
  63          return 2; /* Maintenance::DB_ADMIN */
  64      }
  65  
  66  	function compatChecks() {
  67          // Avoid syntax error in PHP4
  68          $minimumPcreVersion = constant( 'Installer::MINIMUM_PCRE_VERSION' );
  69  
  70          list( $pcreVersion ) = explode( ' ', PCRE_VERSION, 2 );
  71          if ( version_compare( $pcreVersion, $minimumPcreVersion, '<' ) ) {
  72              $this->error(
  73                  "PCRE $minimumPcreVersion or later is required.\n" .
  74                  "Your PHP binary is linked with PCRE $pcreVersion.\n\n" .
  75                  "More information:\n" .
  76                  "https://www.mediawiki.org/wiki/Manual:Errors_and_symptoms/PCRE\n\n" .
  77                  "ABORTING.\n",
  78                  true );
  79          }
  80  
  81          $test = new PhpXmlBugTester();
  82          if ( !$test->ok ) {
  83              $this->error(
  84                  "Your system has a combination of PHP and libxml2 versions that is buggy\n" .
  85                  "and can cause hidden data corruption in MediaWiki and other web apps.\n" .
  86                  "Upgrade to libxml2 2.7.3 or later.\n" .
  87                  "ABORTING (see https://bugs.php.net/bug.php?id=45996).\n",
  88                  true );
  89          }
  90      }
  91  
  92  	function execute() {
  93          global $wgVersion, $wgLang, $wgAllowSchemaUpdates;
  94  
  95          if ( !$wgAllowSchemaUpdates
  96              && !( $this->hasOption( 'force' )
  97                  || $this->hasOption( 'schema' )
  98                  || $this->hasOption( 'noschema' ) )
  99          ) {
 100              $this->error( "Do not run update.php on this wiki. If you're seeing this you should\n"
 101                  . "probably ask for some help in performing your schema updates or use\n"
 102                  . "the --noschema and --schema options to get an SQL file for someone\n"
 103                  . "else to inspect and run.\n\n"
 104                  . "If you know what you are doing, you can continue with --force\n", true );
 105          }
 106  
 107          $this->fileHandle = null;
 108          if ( substr( $this->getOption( 'schema' ), 0, 2 ) === "--" ) {
 109              $this->error( "The --schema option requires a file as an argument.\n", true );
 110          } elseif ( $this->hasOption( 'schema' ) ) {
 111              $file = $this->getOption( 'schema' );
 112              $this->fileHandle = fopen( $file, "w" );
 113              if ( $this->fileHandle === false ) {
 114                  $err = error_get_last();
 115                  $this->error( "Problem opening the schema file for writing: $file\n\t{$err['message']}", true );
 116              }
 117          }
 118  
 119          $wgLang = Language::factory( 'en' );
 120  
 121          define( 'MW_UPDATER', true );
 122  
 123          $this->output( "MediaWiki {$wgVersion} Updater\n\n" );
 124  
 125          wfWaitForSlaves( 5 ); // let's not kill databases, shall we? ;) --tor
 126  
 127          if ( !$this->hasOption( 'skip-compat-checks' ) ) {
 128              $this->compatChecks();
 129          } else {
 130              $this->output( "Skipping compatibility checks, proceed at your own risk (Ctrl+C to abort)\n" );
 131              wfCountdown( 5 );
 132          }
 133  
 134          # Attempt to connect to the database as a privileged user
 135          # This will vomit up an error if there are permissions problems
 136          $db = wfGetDB( DB_MASTER );
 137  
 138          $this->output( "Going to run database updates for " . wfWikiID() . "\n" );
 139          if ( $db->getType() === 'sqlite' ) {
 140              $this->output( "Using SQLite file: '{$db->mDatabaseFile}'\n" );
 141          }
 142          $this->output( "Depending on the size of your database this may take a while!\n" );
 143  
 144          if ( !$this->hasOption( 'quick' ) ) {
 145              $this->output( "Abort with control-c in the next five seconds "
 146                  . "(skip this countdown with --quick) ... " );
 147              wfCountDown( 5 );
 148          }
 149  
 150          $time1 = new MWTimestamp();
 151  
 152          $shared = $this->hasOption( 'doshared' );
 153  
 154          $updates = array( 'core', 'extensions' );
 155          if ( !$this->hasOption( 'schema' ) ) {
 156              if ( $this->hasOption( 'noschema' ) ) {
 157                  $updates[] = 'noschema';
 158              }
 159              $updates[] = 'stats';
 160          }
 161  
 162          $updater = DatabaseUpdater::newForDb( $db, $shared, $this );
 163          $updater->doUpdates( $updates );
 164  
 165          foreach ( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
 166              $child = $this->runChild( $maint );
 167  
 168              // LoggedUpdateMaintenance is checking the updatelog itself
 169              $isLoggedUpdate = is_a( $child, 'LoggedUpdateMaintenance' );
 170  
 171              if ( !$isLoggedUpdate && $updater->updateRowExists( $maint ) ) {
 172                  continue;
 173              }
 174  
 175              $child->execute();
 176              if ( !$isLoggedUpdate ) {
 177                  $updater->insertUpdateRow( $maint );
 178              }
 179          }
 180  
 181          if ( !$this->hasOption( 'nopurge' ) ) {
 182              $updater->purgeCache();
 183          }
 184          $time2 = new MWTimestamp();
 185  
 186          $timeDiff = $time2->diff( $time1 );
 187          $this->output( "\nDone in " . $timeDiff->format( "%i:%S" ) . ".\n" );
 188      }
 189  
 190  	function afterFinalSetup() {
 191          global $wgLocalisationCacheConf;
 192  
 193          # Don't try to access the database
 194          # This needs to be disabled early since extensions will try to use the l10n
 195          # cache from $wgExtensionFunctions (bug 20471)
 196          $wgLocalisationCacheConf = array(
 197              'class' => 'LocalisationCache',
 198              'storeClass' => 'LCStoreNull',
 199              'storeDirectory' => false,
 200              'manualRecache' => false,
 201          );
 202      }
 203  }
 204  
 205  $maintClass = 'UpdateMediaWiki';
 206  require_once RUN_MAINTENANCE_IF_MAIN;


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1