3 * DBMS-specific updater helper.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 require_once __DIR__
. '/../../maintenance/Maintenance.php';
27 * Class for handling database updates. Roughly based off of updaters.inc, with
28 * a few improvements :)
33 abstract class DatabaseUpdater
{
34 protected static $updateCounter = 0;
37 * Array of updates to perform on the database
41 protected $updates = array();
44 * Array of updates that were skipped
48 protected $updatesSkipped = array();
51 * List of extension-provided database updates
54 protected $extensionUpdates = array();
57 * Handle to the database subclass
63 protected $shared = false;
66 * Scripts to run after database update
67 * Should be a subclass of LoggedUpdateMaintenance
69 protected $postDatabaseUpdateMaintenance = array(
70 'DeleteDefaultMessages',
71 'PopulateRevisionLength',
72 'PopulateRevisionSha1',
74 'FixExtLinksProtocolRelative',
75 'PopulateFilearchiveSha1',
76 'PopulateBacklinkNamespace'
80 * File handle for SQL output.
84 protected $fileHandle = null;
87 * Flag specifying whether or not to skip schema (e.g. SQL-only) updates.
91 protected $skipSchema = false;
94 * Hold the value of $wgContentHandlerUseDB during the upgrade.
96 protected $holdContentHandlerUseDB = true;
101 * @param DatabaseBase $db To perform updates on
102 * @param bool $shared Whether to perform updates on shared tables
103 * @param Maintenance $maintenance Maintenance object which created us
105 protected function __construct( DatabaseBase
&$db, $shared, Maintenance
$maintenance = null ) {
107 $this->db
->setFlag( DBO_DDLMODE
); // For Oracle's handling of schema files
108 $this->shared
= $shared;
109 if ( $maintenance ) {
110 $this->maintenance
= $maintenance;
111 $this->fileHandle
= $maintenance->fileHandle
;
113 $this->maintenance
= new FakeMaintenance
;
115 $this->maintenance
->setDB( $db );
116 $this->initOldGlobals();
117 $this->loadExtensions();
118 Hooks
::run( 'LoadExtensionSchemaUpdates', array( $this ) );
122 * Initialize all of the old globals. One day this should all become
123 * something much nicer
125 private function initOldGlobals() {
126 global $wgExtNewTables, $wgExtNewFields, $wgExtPGNewFields,
127 $wgExtPGAlteredFields, $wgExtNewIndexes, $wgExtModifiedFields;
129 # For extensions only, should be populated via hooks
130 # $wgDBtype should be checked to specifiy the proper file
131 $wgExtNewTables = array(); // table, dir
132 $wgExtNewFields = array(); // table, column, dir
133 $wgExtPGNewFields = array(); // table, column, column attributes; for PostgreSQL
134 $wgExtPGAlteredFields = array(); // table, column, new type, conversion method; for PostgreSQL
135 $wgExtNewIndexes = array(); // table, index, dir
136 $wgExtModifiedFields = array(); // table, index, dir
140 * Loads LocalSettings.php, if needed, and initialises everything needed for
141 * LoadExtensionSchemaUpdates hook.
143 private function loadExtensions() {
144 if ( !defined( 'MEDIAWIKI_INSTALL' ) ) {
145 return; // already loaded
147 $vars = Installer
::getExistingLocalSettings();
149 $registry = ExtensionRegistry
::getInstance();
150 $queue = $registry->getQueue();
151 // Don't accidentally load extensions in the future
152 $registry->clearQueue();
154 // This will automatically add "AutoloadClasses" to $wgAutoloadClasses
155 $data = $registry->readFromQueue( $queue );
156 $hooks = array( 'wgHooks' => array( 'LoadExtensionSchemaUpdates' => array() ) );
157 if ( isset( $data['globals']['wgHooks']['LoadExtensionSchemaUpdates'] ) ) {
158 $hooks = $data['globals']['wgHooks']['LoadExtensionSchemaUpdates'];
160 if ( $vars && isset( $vars['wgHooks']['LoadExtensionSchemaUpdates'] ) ) {
161 $hooks = array_merge_recursive( $hooks, $vars['wgHooks']['LoadExtensionSchemaUpdates'] );
163 global $wgHooks, $wgAutoloadClasses;
164 $wgHooks['LoadExtensionSchemaUpdates'] = $hooks;
165 if ( $vars && isset( $vars['wgAutoloadClasses'] ) ) {
166 $wgAutoloadClasses +
= $vars['wgAutoloadClasses'];
171 * @param DatabaseBase $db
172 * @param bool $shared
173 * @param Maintenance $maintenance
175 * @throws MWException
176 * @return DatabaseUpdater
178 public static function newForDB( &$db, $shared = false, $maintenance = null ) {
179 $type = $db->getType();
180 if ( in_array( $type, Installer
::getDBTypes() ) ) {
181 $class = ucfirst( $type ) . 'Updater';
183 return new $class( $db, $shared, $maintenance );
185 throw new MWException( __METHOD__
. ' called for unsupported $wgDBtype' );
190 * Get a database connection to run updates
192 * @return DatabaseBase
194 public function getDB() {
199 * Output some text. If we're running from web, escape the text first.
201 * @param string $str Text to output
203 public function output( $str ) {
204 if ( $this->maintenance
->isQuiet() ) {
207 global $wgCommandLineMode;
208 if ( !$wgCommandLineMode ) {
209 $str = htmlspecialchars( $str );
216 * Add a new update coming from an extension. This should be called by
217 * extensions while executing the LoadExtensionSchemaUpdates hook.
221 * @param array $update The update to run. Format is the following:
222 * first item is the callback function, it also can be a
223 * simple string with the name of a function in this class,
224 * following elements are parameters to the function.
225 * Note that callback functions will receive this object as
228 public function addExtensionUpdate( array $update ) {
229 $this->extensionUpdates
[] = $update;
233 * Convenience wrapper for addExtensionUpdate() when adding a new table (which
234 * is the most common usage of updaters in an extension)
238 * @param string $tableName Name of table to create
239 * @param string $sqlPath Full path to the schema file
241 public function addExtensionTable( $tableName, $sqlPath ) {
242 $this->extensionUpdates
[] = array( 'addTable', $tableName, $sqlPath, true );
248 * @param string $tableName
249 * @param string $indexName
250 * @param string $sqlPath
252 public function addExtensionIndex( $tableName, $indexName, $sqlPath ) {
253 $this->extensionUpdates
[] = array( 'addIndex', $tableName, $indexName, $sqlPath, true );
260 * @param string $tableName
261 * @param string $columnName
262 * @param string $sqlPath
264 public function addExtensionField( $tableName, $columnName, $sqlPath ) {
265 $this->extensionUpdates
[] = array( 'addField', $tableName, $columnName, $sqlPath, true );
272 * @param string $tableName
273 * @param string $columnName
274 * @param string $sqlPath
276 public function dropExtensionField( $tableName, $columnName, $sqlPath ) {
277 $this->extensionUpdates
[] = array( 'dropField', $tableName, $columnName, $sqlPath, true );
281 * Drop an index from an extension table
285 * @param string $tableName The table name
286 * @param string $indexName The index name
287 * @param string $sqlPath The path to the SQL change path
289 public function dropExtensionIndex( $tableName, $indexName, $sqlPath ) {
290 $this->extensionUpdates
[] = array( 'dropIndex', $tableName, $indexName, $sqlPath, true );
297 * @param string $tableName
298 * @param string $sqlPath
300 public function dropExtensionTable( $tableName, $sqlPath ) {
301 $this->extensionUpdates
[] = array( 'dropTable', $tableName, $sqlPath, true );
305 * Rename an index on an extension table
309 * @param string $tableName The table name
310 * @param string $oldIndexName The old index name
311 * @param string $newIndexName The new index name
312 * @param string $sqlPath The path to the SQL change path
313 * @param bool $skipBothIndexExistWarning Whether to warn if both the old
314 * and the new indexes exist. [facultative; by default, false]
316 public function renameExtensionIndex( $tableName, $oldIndexName, $newIndexName,
317 $sqlPath, $skipBothIndexExistWarning = false
319 $this->extensionUpdates
[] = array(
324 $skipBothIndexExistWarning,
333 * @param string $tableName The table name
334 * @param string $fieldName The field to be modified
335 * @param string $sqlPath The path to the SQL change path
337 public function modifyExtensionField( $tableName, $fieldName, $sqlPath ) {
338 $this->extensionUpdates
[] = array( 'modifyField', $tableName, $fieldName, $sqlPath, true );
345 * @param string $tableName
348 public function tableExists( $tableName ) {
349 return ( $this->db
->tableExists( $tableName, __METHOD__
) );
353 * Add a maintenance script to be run after the database updates are complete.
355 * Script should subclass LoggedUpdateMaintenance
359 * @param string $class Name of a Maintenance subclass
361 public function addPostDatabaseUpdateMaintenance( $class ) {
362 $this->postDatabaseUpdateMaintenance
[] = $class;
366 * Get the list of extension-defined updates
370 protected function getExtensionUpdates() {
371 return $this->extensionUpdates
;
379 public function getPostDatabaseUpdateMaintenance() {
380 return $this->postDatabaseUpdateMaintenance
;
386 * Writes the schema updates desired to a file for the DB Admin to run.
387 * @param array $schemaUpdate
389 private function writeSchemaUpdateFile( $schemaUpdate = array() ) {
390 $updates = $this->updatesSkipped
;
391 $this->updatesSkipped
= array();
393 foreach ( $updates as $funcList ) {
394 $func = $funcList[0];
396 $origParams = $funcList[2];
397 call_user_func_array( $func, $arg );
399 $this->updatesSkipped
[] = $origParams;
406 * @param array $what What updates to perform
408 public function doUpdates( $what = array( 'core', 'extensions', 'stats' ) ) {
411 $this->db
->begin( __METHOD__
);
412 $what = array_flip( $what );
413 $this->skipSchema
= isset( $what['noschema'] ) ||
$this->fileHandle
!== null;
414 if ( isset( $what['core'] ) ) {
415 $this->runUpdates( $this->getCoreUpdateList(), false );
417 if ( isset( $what['extensions'] ) ) {
418 $this->runUpdates( $this->getOldGlobalUpdates(), false );
419 $this->runUpdates( $this->getExtensionUpdates(), true );
422 if ( isset( $what['stats'] ) ) {
426 $this->setAppliedUpdates( $wgVersion, $this->updates
);
428 if ( $this->fileHandle
) {
429 $this->skipSchema
= false;
430 $this->writeSchemaUpdateFile();
431 $this->setAppliedUpdates( "$wgVersion-schema", $this->updatesSkipped
);
434 $this->db
->commit( __METHOD__
);
438 * Helper function for doUpdates()
440 * @param array $updates Array of updates to run
441 * @param bool $passSelf Whether to pass this object we calling external functions
443 private function runUpdates( array $updates, $passSelf ) {
444 $updatesDone = array();
445 $updatesSkipped = array();
446 foreach ( $updates as $params ) {
447 $origParams = $params;
448 $func = array_shift( $params );
449 if ( !is_array( $func ) && method_exists( $this, $func ) ) {
450 $func = array( $this, $func );
451 } elseif ( $passSelf ) {
452 array_unshift( $params, $this );
454 $ret = call_user_func_array( $func, $params );
456 if ( $ret !== false ) {
457 $updatesDone[] = $origParams;
460 $updatesSkipped[] = array( $func, $params, $origParams );
463 $this->updatesSkipped
= array_merge( $this->updatesSkipped
, $updatesSkipped );
464 $this->updates
= array_merge( $this->updates
, $updatesDone );
468 * @param string $version
469 * @param array $updates
471 protected function setAppliedUpdates( $version, $updates = array() ) {
472 $this->db
->clearFlag( DBO_DDLMODE
);
473 if ( !$this->canUseNewUpdatelog() ) {
476 $key = "updatelist-$version-" . time() . self
::$updateCounter;
477 self
::$updateCounter++
;
478 $this->db
->insert( 'updatelog',
479 array( 'ul_key' => $key, 'ul_value' => serialize( $updates ) ),
481 $this->db
->setFlag( DBO_DDLMODE
);
485 * Helper function: check if the given key is present in the updatelog table.
486 * Obviously, only use this for updates that occur after the updatelog table was
488 * @param string $key Name of the key to check for
491 public function updateRowExists( $key ) {
492 $row = $this->db
->selectRow(
496 array( 'ul_key' => $key ),
504 * Helper function: Add a key to the updatelog table
505 * Obviously, only use this for updates that occur after the updatelog table was
507 * @param string $key Name of key to insert
508 * @param string $val [optional] Value to insert along with the key
510 public function insertUpdateRow( $key, $val = null ) {
511 $this->db
->clearFlag( DBO_DDLMODE
);
512 $values = array( 'ul_key' => $key );
513 if ( $val && $this->canUseNewUpdatelog() ) {
514 $values['ul_value'] = $val;
516 $this->db
->insert( 'updatelog', $values, __METHOD__
, 'IGNORE' );
517 $this->db
->setFlag( DBO_DDLMODE
);
521 * Updatelog was changed in 1.17 to have a ul_value column so we can record
522 * more information about what kind of updates we've done (that's what this
523 * class does). Pre-1.17 wikis won't have this column, and really old wikis
524 * might not even have updatelog at all
528 protected function canUseNewUpdatelog() {
529 return $this->db
->tableExists( 'updatelog', __METHOD__
) &&
530 $this->db
->fieldExists( 'updatelog', 'ul_value', __METHOD__
);
534 * Returns whether updates should be executed on the database table $name.
535 * Updates will be prevented if the table is a shared table and it is not
536 * specified to run updates on shared tables.
538 * @param string $name Table name
541 protected function doTable( $name ) {
542 global $wgSharedDB, $wgSharedTables;
544 // Don't bother to check $wgSharedTables if there isn't a shared database
545 // or the user actually also wants to do updates on the shared database.
546 if ( $wgSharedDB === null ||
$this->shared
) {
550 if ( in_array( $name, $wgSharedTables ) ) {
551 $this->output( "...skipping update to shared table $name.\n" );
559 * Before 1.17, we used to handle updates via stuff like
560 * $wgExtNewTables/Fields/Indexes. This is nasty :) We refactored a lot
561 * of this in 1.17 but we want to remain back-compatible for a while. So
562 * load up these old global-based things into our update list.
566 protected function getOldGlobalUpdates() {
567 global $wgExtNewFields, $wgExtNewTables, $wgExtModifiedFields,
572 foreach ( $wgExtNewTables as $tableRecord ) {
574 'addTable', $tableRecord[0], $tableRecord[1], true
578 foreach ( $wgExtNewFields as $fieldRecord ) {
580 'addField', $fieldRecord[0], $fieldRecord[1],
581 $fieldRecord[2], true
585 foreach ( $wgExtNewIndexes as $fieldRecord ) {
587 'addIndex', $fieldRecord[0], $fieldRecord[1],
588 $fieldRecord[2], true
592 foreach ( $wgExtModifiedFields as $fieldRecord ) {
594 'modifyField', $fieldRecord[0], $fieldRecord[1],
595 $fieldRecord[2], true
603 * Get an array of updates to perform on the database. Should return a
604 * multi-dimensional array. The main key is the MediaWiki version (1.12,
605 * 1.13...) with the values being arrays of updates, identical to how
606 * updaters.inc did it (for now)
610 abstract protected function getCoreUpdateList();
613 * Append an SQL fragment to the open file handle.
615 * @param string $filename File name to open
617 public function copyFile( $filename ) {
618 $this->db
->sourceFile( $filename, false, false, false,
619 array( $this, 'appendLine' )
624 * Append a line to the open filehandle. The line is assumed to
625 * be a complete SQL statement.
627 * This is used as a callback for sourceLine().
629 * @param string $line Text to append to the file
630 * @return bool False to skip actually executing the file
631 * @throws MWException
633 public function appendLine( $line ) {
634 $line = rtrim( $line ) . ";\n";
635 if ( fwrite( $this->fileHandle
, $line ) === false ) {
636 throw new MWException( "trouble writing file" );
643 * Applies a SQL patch
645 * @param string $path Path to the patch file
646 * @param bool $isFullPath Whether to treat $path as a relative or not
647 * @param string $msg Description of the patch
648 * @return bool False if patch is skipped.
650 protected function applyPatch( $path, $isFullPath = false, $msg = null ) {
651 if ( $msg === null ) {
652 $msg = "Applying $path patch";
654 if ( $this->skipSchema
) {
655 $this->output( "...skipping schema change ($msg).\n" );
660 $this->output( "$msg ..." );
662 if ( !$isFullPath ) {
663 $path = $this->db
->patchPath( $path );
665 if ( $this->fileHandle
!== null ) {
666 $this->copyFile( $path );
668 $this->db
->sourceFile( $path );
670 $this->output( "done.\n" );
676 * Add a new table to the database
678 * @param string $name Name of the new table
679 * @param string $patch Path to the patch file
680 * @param bool $fullpath Whether to treat $patch path as a relative or not
681 * @return bool False if this was skipped because schema changes are skipped
683 protected function addTable( $name, $patch, $fullpath = false ) {
684 if ( !$this->doTable( $name ) ) {
688 if ( $this->db
->tableExists( $name, __METHOD__
) ) {
689 $this->output( "...$name table already exists.\n" );
691 return $this->applyPatch( $patch, $fullpath, "Creating $name table" );
698 * Add a new field to an existing table
700 * @param string $table Name of the table to modify
701 * @param string $field Name of the new field
702 * @param string $patch Path to the patch file
703 * @param bool $fullpath Whether to treat $patch path as a relative or not
704 * @return bool False if this was skipped because schema changes are skipped
706 protected function addField( $table, $field, $patch, $fullpath = false ) {
707 if ( !$this->doTable( $table ) ) {
711 if ( !$this->db
->tableExists( $table, __METHOD__
) ) {
712 $this->output( "...$table table does not exist, skipping new field patch.\n" );
713 } elseif ( $this->db
->fieldExists( $table, $field, __METHOD__
) ) {
714 $this->output( "...have $field field in $table table.\n" );
716 return $this->applyPatch( $patch, $fullpath, "Adding $field field to table $table" );
723 * Add a new index to an existing table
725 * @param string $table Name of the table to modify
726 * @param string $index Name of the new index
727 * @param string $patch Path to the patch file
728 * @param bool $fullpath Whether to treat $patch path as a relative or not
729 * @return bool False if this was skipped because schema changes are skipped
731 protected function addIndex( $table, $index, $patch, $fullpath = false ) {
732 if ( !$this->doTable( $table ) ) {
736 if ( !$this->db
->tableExists( $table, __METHOD__
) ) {
737 $this->output( "...skipping: '$table' table doesn't exist yet.\n" );
738 } elseif ( $this->db
->indexExists( $table, $index, __METHOD__
) ) {
739 $this->output( "...index $index already set on $table table.\n" );
741 return $this->applyPatch( $patch, $fullpath, "Adding index $index to table $table" );
748 * Drop a field from an existing table
750 * @param string $table Name of the table to modify
751 * @param string $field Name of the old field
752 * @param string $patch Path to the patch file
753 * @param bool $fullpath Whether to treat $patch path as a relative or not
754 * @return bool False if this was skipped because schema changes are skipped
756 protected function dropField( $table, $field, $patch, $fullpath = false ) {
757 if ( !$this->doTable( $table ) ) {
761 if ( $this->db
->fieldExists( $table, $field, __METHOD__
) ) {
762 return $this->applyPatch( $patch, $fullpath, "Table $table contains $field field. Dropping" );
764 $this->output( "...$table table does not contain $field field.\n" );
771 * Drop an index from an existing table
773 * @param string $table Name of the table to modify
774 * @param string $index Name of the index
775 * @param string $patch Path to the patch file
776 * @param bool $fullpath Whether to treat $patch path as a relative or not
777 * @return bool False if this was skipped because schema changes are skipped
779 protected function dropIndex( $table, $index, $patch, $fullpath = false ) {
780 if ( !$this->doTable( $table ) ) {
784 if ( $this->db
->indexExists( $table, $index, __METHOD__
) ) {
785 return $this->applyPatch( $patch, $fullpath, "Dropping $index index from table $table" );
787 $this->output( "...$index key doesn't exist.\n" );
794 * Rename an index from an existing table
796 * @param string $table Name of the table to modify
797 * @param string $oldIndex Old name of the index
798 * @param string $newIndex New name of the index
799 * @param bool $skipBothIndexExistWarning Whether to warn if both the
800 * old and the new indexes exist.
801 * @param string $patch Path to the patch file
802 * @param bool $fullpath Whether to treat $patch path as a relative or not
803 * @return bool False if this was skipped because schema changes are skipped
805 protected function renameIndex( $table, $oldIndex, $newIndex,
806 $skipBothIndexExistWarning, $patch, $fullpath = false
808 if ( !$this->doTable( $table ) ) {
812 // First requirement: the table must exist
813 if ( !$this->db
->tableExists( $table, __METHOD__
) ) {
814 $this->output( "...skipping: '$table' table doesn't exist yet.\n" );
819 // Second requirement: the new index must be missing
820 if ( $this->db
->indexExists( $table, $newIndex, __METHOD__
) ) {
821 $this->output( "...index $newIndex already set on $table table.\n" );
822 if ( !$skipBothIndexExistWarning &&
823 $this->db
->indexExists( $table, $oldIndex, __METHOD__
)
825 $this->output( "...WARNING: $oldIndex still exists, despite it has " .
826 "been renamed into $newIndex (which also exists).\n" .
827 " $oldIndex should be manually removed if not needed anymore.\n" );
833 // Third requirement: the old index must exist
834 if ( !$this->db
->indexExists( $table, $oldIndex, __METHOD__
) ) {
835 $this->output( "...skipping: index $oldIndex doesn't exist.\n" );
840 // Requirements have been satisfied, patch can be applied
841 return $this->applyPatch(
844 "Renaming index $oldIndex into $newIndex to table $table"
849 * If the specified table exists, drop it, or execute the
850 * patch if one is provided.
854 * @param string $table Table to drop.
855 * @param string|bool $patch String of patch file that will drop the table. Default: false.
856 * @param bool $fullpath Whether $patch is a full path. Default: false.
857 * @return bool False if this was skipped because schema changes are skipped
859 public function dropTable( $table, $patch = false, $fullpath = false ) {
860 if ( !$this->doTable( $table ) ) {
864 if ( $this->db
->tableExists( $table, __METHOD__
) ) {
865 $msg = "Dropping table $table";
867 if ( $patch === false ) {
868 $this->output( "$msg ..." );
869 $this->db
->dropTable( $table, __METHOD__
);
870 $this->output( "done.\n" );
872 return $this->applyPatch( $patch, $fullpath, $msg );
875 $this->output( "...$table doesn't exist.\n" );
882 * Modify an existing field
884 * @param string $table Name of the table to which the field belongs
885 * @param string $field Name of the field to modify
886 * @param string $patch Path to the patch file
887 * @param bool $fullpath Whether to treat $patch path as a relative or not
888 * @return bool False if this was skipped because schema changes are skipped
890 public function modifyField( $table, $field, $patch, $fullpath = false ) {
891 if ( !$this->doTable( $table ) ) {
895 $updateKey = "$table-$field-$patch";
896 if ( !$this->db
->tableExists( $table, __METHOD__
) ) {
897 $this->output( "...$table table does not exist, skipping modify field patch.\n" );
898 } elseif ( !$this->db
->fieldExists( $table, $field, __METHOD__
) ) {
899 $this->output( "...$field field does not exist in $table table, " .
900 "skipping modify field patch.\n" );
901 } elseif ( $this->updateRowExists( $updateKey ) ) {
902 $this->output( "...$field in table $table already modified by patch $patch.\n" );
904 $this->insertUpdateRow( $updateKey );
906 return $this->applyPatch( $patch, $fullpath, "Modifying $field field of table $table" );
913 * Set any .htaccess files or equivilent for storage repos
915 * Some zones (e.g. "temp") used to be public and may have been initialized as such
917 public function setFileAccess() {
918 $repo = RepoGroup
::singleton()->getLocalRepo();
919 $zonePath = $repo->getZonePath( 'temp' );
920 if ( $repo->getBackend()->directoryExists( array( 'dir' => $zonePath ) ) ) {
921 // If the directory was never made, then it will have the right ACLs when it is made
922 $status = $repo->getBackend()->secure( array(
927 if ( $status->isOK() ) {
928 $this->output( "Set the local repo temp zone container to be private.\n" );
930 $this->output( "Failed to set the local repo temp zone container to be private.\n" );
936 * Purge the objectcache table
938 public function purgeCache() {
939 global $wgLocalisationCacheConf;
940 # We can't guarantee that the user will be able to use TRUNCATE,
941 # but we know that DELETE is available to us
942 $this->output( "Purging caches..." );
943 $this->db
->delete( 'objectcache', '*', __METHOD__
);
944 if ( $wgLocalisationCacheConf['manualRecache'] ) {
945 $this->rebuildLocalisationCache();
947 $blobStore = new MessageBlobStore();
949 $this->db
->delete( 'module_deps', '*', __METHOD__
);
950 $this->output( "done.\n" );
954 * Check the site_stats table is not properly populated.
956 protected function checkStats() {
957 $this->output( "...site_stats is populated..." );
958 $row = $this->db
->selectRow( 'site_stats', '*', array( 'ss_row_id' => 1 ), __METHOD__
);
959 if ( $row === false ) {
960 $this->output( "data is missing! rebuilding...\n" );
961 } elseif ( isset( $row->site_stats
) && $row->ss_total_pages
== -1 ) {
962 $this->output( "missing ss_total_pages, rebuilding...\n" );
964 $this->output( "done.\n" );
968 SiteStatsInit
::doAllAndCommit( $this->db
);
971 # Common updater functions
974 * Sets the number of active users in the site_stats table
976 protected function doActiveUsersInit() {
977 $activeUsers = $this->db
->selectField( 'site_stats', 'ss_active_users', false, __METHOD__
);
978 if ( $activeUsers == -1 ) {
979 $activeUsers = $this->db
->selectField( 'recentchanges',
980 'COUNT( DISTINCT rc_user_text )',
981 array( 'rc_user != 0', 'rc_bot' => 0, "rc_log_type != 'newusers'" ), __METHOD__
983 $this->db
->update( 'site_stats',
984 array( 'ss_active_users' => intval( $activeUsers ) ),
985 array( 'ss_row_id' => 1 ), __METHOD__
, array( 'LIMIT' => 1 )
988 $this->output( "...ss_active_users user count set...\n" );
992 * Populates the log_user_text field in the logging table
994 protected function doLogUsertextPopulation() {
995 if ( !$this->updateRowExists( 'populate log_usertext' ) ) {
997 "Populating log_user_text field, printing progress markers. For large\n" .
998 "databases, you may want to hit Ctrl-C and do this manually with\n" .
999 "maintenance/populateLogUsertext.php.\n"
1002 $task = $this->maintenance
->runChild( 'PopulateLogUsertext' );
1004 $this->output( "done.\n" );
1009 * Migrate log params to new table and index for searching
1011 protected function doLogSearchPopulation() {
1012 if ( !$this->updateRowExists( 'populate log_search' ) ) {
1014 "Populating log_search table, printing progress markers. For large\n" .
1015 "databases, you may want to hit Ctrl-C and do this manually with\n" .
1016 "maintenance/populateLogSearch.php.\n" );
1018 $task = $this->maintenance
->runChild( 'PopulateLogSearch' );
1020 $this->output( "done.\n" );
1025 * Updates the timestamps in the transcache table
1028 protected function doUpdateTranscacheField() {
1029 if ( $this->updateRowExists( 'convert transcache field' ) ) {
1030 $this->output( "...transcache tc_time already converted.\n" );
1035 return $this->applyPatch( 'patch-tc-timestamp.sql', false,
1036 "Converting tc_time from UNIX epoch to MediaWiki timestamp" );
1040 * Update CategoryLinks collation
1042 protected function doCollationUpdate() {
1043 global $wgCategoryCollation;
1044 if ( $this->db
->fieldExists( 'categorylinks', 'cl_collation', __METHOD__
) ) {
1045 if ( $this->db
->selectField(
1048 'cl_collation != ' . $this->db
->addQuotes( $wgCategoryCollation ),
1052 $this->output( "...collations up-to-date.\n" );
1057 $this->output( "Updating category collations..." );
1058 $task = $this->maintenance
->runChild( 'UpdateCollation' );
1060 $this->output( "...done.\n" );
1065 * Migrates user options from the user table blob to user_properties
1067 protected function doMigrateUserOptions() {
1068 if ( $this->db
->tableExists( 'user_properties' ) ) {
1069 $cl = $this->maintenance
->runChild( 'ConvertUserOptions', 'convertUserOptions.php' );
1071 $this->output( "done.\n" );
1076 * Enable profiling table when it's turned on
1078 protected function doEnableProfiling() {
1081 if ( !$this->doTable( 'profiling' ) ) {
1085 $profileToDb = false;
1086 if ( isset( $wgProfiler['output'] ) ) {
1087 $out = $wgProfiler['output'];
1088 if ( $out === 'db' ) {
1089 $profileToDb = true;
1090 } elseif ( is_array( $out ) && in_array( 'db', $out ) ) {
1091 $profileToDb = true;
1095 if ( $profileToDb && !$this->db
->tableExists( 'profiling', __METHOD__
) ) {
1096 $this->applyPatch( 'patch-profiling.sql', false, 'Add profiling table' );
1101 * Rebuilds the localisation cache
1103 protected function rebuildLocalisationCache() {
1105 * @var $cl RebuildLocalisationCache
1107 $cl = $this->maintenance
->runChild( 'RebuildLocalisationCache', 'rebuildLocalisationCache.php' );
1108 $this->output( "Rebuilding localisation cache...\n" );
1111 $this->output( "done.\n" );
1115 * Turns off content handler fields during parts of the upgrade
1116 * where they aren't available.
1118 protected function disableContentHandlerUseDB() {
1119 global $wgContentHandlerUseDB;
1121 if ( $wgContentHandlerUseDB ) {
1122 $this->output( "Turning off Content Handler DB fields for this part of upgrade.\n" );
1123 $this->holdContentHandlerUseDB
= $wgContentHandlerUseDB;
1124 $wgContentHandlerUseDB = false;
1129 * Turns content handler fields back on.
1131 protected function enableContentHandlerUseDB() {
1132 global $wgContentHandlerUseDB;
1134 if ( $this->holdContentHandlerUseDB
) {
1135 $this->output( "Content Handler DB fields should be usable now.\n" );
1136 $wgContentHandlerUseDB = $this->holdContentHandlerUseDB
;