Merge "Use LogFormatter to format rights log."
[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 * It is kept compatible with php 4 parsing so that it can give out a meaningful error.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
22 *
23 * @file
24 * @todo document
25 * @ingroup Maintenance
26 */
27
28 if ( !function_exists( 'version_compare' ) || ( version_compare( phpversion(), '5.3.2' ) < 0 ) ) {
29 echo "You are using PHP version " . phpversion() . " but MediaWiki needs PHP 5.3.2 or higher. ABORTING.\n" .
30 "Check if you have a newer php executable with a different name, such as php5.\n";
31 die( 1 );
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
44 function __construct() {
45 parent::__construct();
46 $this->mDescription = "MediaWiki database updater";
47 $this->addOption( 'skip-compat-checks', 'Skips compatibility checks, mostly for developers' );
48 $this->addOption( 'quick', 'Skip 5 second countdown before starting' );
49 $this->addOption( 'doshared', 'Also update shared tables' );
50 $this->addOption( 'nopurge', 'Do not purge the objectcache table after updates' );
51 $this->addOption( 'force', 'Override when $wgAllowSchemaUpdates disables this script' );
52 }
53
54 function getDbType() {
55 /* If we used the class constant PHP4 would give a parser error here */
56 return 2 /* Maintenance::DB_ADMIN */;
57 }
58
59 function compatChecks() {
60 $test = new PhpXmlBugTester();
61 if ( !$test->ok ) {
62 $this->error(
63 "Your system has a combination of PHP and libxml2 versions which is buggy\n" .
64 "and can cause hidden data corruption in MediaWiki and other web apps.\n" .
65 "Upgrade to PHP 5.2.9 or later and libxml2 2.7.3 or later!\n" .
66 "ABORTING (see http://bugs.php.net/bug.php?id=45996).\n",
67 true );
68 }
69
70 $test = new PhpRefCallBugTester;
71 $test->execute();
72 if ( !$test->ok ) {
73 $ver = phpversion();
74 $this->error(
75 "PHP $ver is not compatible with MediaWiki due to a bug involving\n" .
76 "reference parameters to __call. Upgrade to PHP 5.3.2 or higher, or \n" .
77 "downgrade to PHP 5.3.0 to fix this.\n" .
78 "ABORTING (see http://bugs.php.net/bug.php?id=50394 for details)\n",
79 true );
80 }
81 }
82
83 function execute() {
84 global $wgVersion, $wgTitle, $wgLang, $wgAllowSchemaUpdates;
85
86 if( !$wgAllowSchemaUpdates && !$this->hasOption( 'force' ) ) {
87 $this->error( "Do not run update.php on this wiki. If you're seeing this you should\n"
88 . "probably ask for some help in performing your schema updates.\n\n"
89 . "If you know what you are doing, you can continue with --force", true );
90 }
91
92 $wgLang = Language::factory( 'en' );
93 $wgTitle = Title::newFromText( "MediaWiki database updater" );
94
95 $this->output( "MediaWiki {$wgVersion} Updater\n\n" );
96
97 wfWaitForSlaves( 5 ); // let's not kill databases, shall we? ;) --tor
98
99 if ( !$this->hasOption( 'skip-compat-checks' ) ) {
100 $this->compatChecks();
101 } else {
102 $this->output( "Skipping compatibility checks, proceed at your own risk (Ctrl+C to abort)\n" );
103 wfCountdown( 5 );
104 }
105
106 # Attempt to connect to the database as a privileged user
107 # This will vomit up an error if there are permissions problems
108 $db = wfGetDB( DB_MASTER );
109
110 $this->output( "Going to run database updates for " . wfWikiID() . "\n" );
111 $this->output( "Depending on the size of your database this may take a while!\n" );
112
113 if ( !$this->hasOption( 'quick' ) ) {
114 $this->output( "Abort with control-c in the next five seconds (skip this countdown with --quick) ... " );
115 wfCountDown( 5 );
116 }
117
118 $shared = $this->hasOption( 'doshared' );
119
120 $updates = array( 'core', 'extensions', 'stats' );
121
122 $updater = DatabaseUpdater::newForDb( $db, $shared, $this );
123 $updater->doUpdates( $updates );
124
125 foreach( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
126 $child = $this->runChild( $maint );
127
128 // LoggedUpdateMaintenance is checking the updatelog itself
129 $isLoggedUpdate = ( $child instanceof LoggedUpdateMaintenance );
130
131 if ( !$isLoggedUpdate && $updater->updateRowExists( $maint ) ) {
132 continue;
133 }
134 $child->execute();
135 if ( !$isLoggedUpdate ) {
136 $updater->insertUpdateRow( $maint );
137 }
138 }
139
140 if( !$this->hasOption('nopurge') ) {
141 $updater->purgeCache();
142 }
143
144 $this->output( "\nDone.\n" );
145 }
146
147 function afterFinalSetup() {
148 global $wgLocalisationCacheConf;
149
150 # Don't try to access the database
151 # This needs to be disabled early since extensions will try to use the l10n
152 # cache from $wgExtensionFunctions (bug 20471)
153 $wgLocalisationCacheConf = array(
154 'class' => 'LocalisationCache',
155 'storeClass' => 'LCStore_Null',
156 'storeDirectory' => false,
157 'manualRecache' => false,
158 );
159 }
160 }
161
162 $maintClass = 'UpdateMediaWiki';
163 require_once( RUN_MAINTENANCE_IF_MAIN );