From: Alexandre Emsenhuber Date: Thu, 27 Dec 2012 17:37:40 +0000 (+0100) Subject: (bug 43116) Don't run database updates for shared tables unless --doshared is provided X-Git-Tag: 1.31.0-rc.0~21166^2 X-Git-Url: http://git.cyclocoop.org/%22.%28%24lien.?a=commitdiff_plain;h=56226548248240621a0017f33f85fe6971a08ffb;p=lhc%2Fweb%2Fwiklou.git (bug 43116) Don't run database updates for shared tables unless --doshared is provided Added DatabaseUpdater::doTable() to check whether updates should executed on the given table. Change-Id: I83fd722b604f9bc8a834681d234a0d80964dedc5 --- diff --git a/includes/installer/DatabaseUpdater.php b/includes/installer/DatabaseUpdater.php index dde21933b2..2fe96765f9 100644 --- a/includes/installer/DatabaseUpdater.php +++ b/includes/installer/DatabaseUpdater.php @@ -464,6 +464,26 @@ abstract class DatabaseUpdater { $this->db->fieldExists( 'updatelog', 'ul_value', __METHOD__ ); } + /** + * Returns whether updates should be executed on the database table $name. + * Updates will be prevented if the table is a shared table and it is not + * specified to run updates on shared tables. + * + * @param $name String table name + * @return bool + */ + protected function doTable( $name ) { + global $wgSharedDB, $wgSharedTables; + + // Don't bother to check $wgSharedTables if there isn't a shared database + // or the user actually also wants to do updates on the shared database. + if ( $wgSharedDB === null || $this->shared ) { + return true; + } + + return !in_array( $name, $wgSharedTables ); + } + /** * Before 1.17, we used to handle updates via stuff like * $wgExtNewTables/Fields/Indexes. This is nasty :) We refactored a lot @@ -474,11 +494,7 @@ abstract class DatabaseUpdater { */ protected function getOldGlobalUpdates() { global $wgExtNewFields, $wgExtNewTables, $wgExtModifiedFields, - $wgExtNewIndexes, $wgSharedDB, $wgSharedTables; - - $doUser = $this->shared ? - $wgSharedDB && in_array( 'user', $wgSharedTables ) : - !$wgSharedDB || !in_array( 'user', $wgSharedTables ); + $wgExtNewIndexes; $updates = array(); @@ -489,12 +505,10 @@ abstract class DatabaseUpdater { } foreach ( $wgExtNewFields as $fieldRecord ) { - if ( $fieldRecord[0] != 'user' || $doUser ) { - $updates[] = array( - 'addField', $fieldRecord[0], $fieldRecord[1], - $fieldRecord[2], true - ); - } + $updates[] = array( + 'addField', $fieldRecord[0], $fieldRecord[1], + $fieldRecord[2], true + ); } foreach ( $wgExtNewIndexes as $fieldRecord ) { @@ -591,6 +605,10 @@ abstract class DatabaseUpdater { * @return Boolean false if this was skipped because schema changes are skipped */ protected function addTable( $name, $patch, $fullpath = false ) { + if ( !$this->doTable( $name ) ) { + return true; + } + if ( $this->db->tableExists( $name, __METHOD__ ) ) { $this->output( "...$name table already exists.\n" ); } else { @@ -608,6 +626,10 @@ abstract class DatabaseUpdater { * @return Boolean false if this was skipped because schema changes are skipped */ protected function addField( $table, $field, $patch, $fullpath = false ) { + if ( !$this->doTable( $table ) ) { + return true; + } + if ( !$this->db->tableExists( $table, __METHOD__ ) ) { $this->output( "...$table table does not exist, skipping new field patch.\n" ); } elseif ( $this->db->fieldExists( $table, $field, __METHOD__ ) ) { @@ -627,6 +649,10 @@ abstract class DatabaseUpdater { * @return Boolean false if this was skipped because schema changes are skipped */ protected function addIndex( $table, $index, $patch, $fullpath = false ) { + if ( !$this->doTable( $table ) ) { + return true; + } + if ( !$this->db->tableExists( $table, __METHOD__ ) ) { $this->output( "...skipping: '$table' table doesn't exist yet.\n" ); return false; @@ -648,6 +674,10 @@ abstract class DatabaseUpdater { * @return Boolean false if this was skipped because schema changes are skipped */ protected function dropField( $table, $field, $patch, $fullpath = false ) { + if ( !$this->doTable( $table ) ) { + return true; + } + if ( $this->db->fieldExists( $table, $field, __METHOD__ ) ) { return $this->applyPatch( $patch, $fullpath, "Table $table contains $field field. Dropping" ); } else { @@ -666,6 +696,10 @@ abstract class DatabaseUpdater { * @return Boolean false if this was skipped because schema changes are skipped */ protected function dropIndex( $table, $index, $patch, $fullpath = false ) { + if ( !$this->doTable( $table ) ) { + return true; + } + if ( $this->db->indexExists( $table, $index, __METHOD__ ) ) { return $this->applyPatch( $patch, $fullpath, "Dropping $index index from table $table" ); } else { @@ -686,6 +720,10 @@ abstract class DatabaseUpdater { * @return Boolean false if this was skipped because schema changes are skipped */ public function dropTable( $table, $patch = false, $fullpath = false ) { + if ( !$this->doTable( $table ) ) { + return true; + } + if ( $this->db->tableExists( $table, __METHOD__ ) ) { $msg = "Dropping table $table"; @@ -713,6 +751,10 @@ abstract class DatabaseUpdater { * @return Boolean false if this was skipped because schema changes are skipped */ public function modifyField( $table, $field, $patch, $fullpath = false ) { + if ( !$this->doTable( $table ) ) { + return true; + } + $updateKey = "$table-$field-$patch"; if ( !$this->db->tableExists( $table, __METHOD__ ) ) { $this->output( "...$table table does not exist, skipping modify field patch.\n" ); diff --git a/includes/installer/MysqlUpdater.php b/includes/installer/MysqlUpdater.php index bbeb685c0a..7068528daf 100644 --- a/includes/installer/MysqlUpdater.php +++ b/includes/installer/MysqlUpdater.php @@ -240,6 +240,10 @@ class MysqlUpdater extends DatabaseUpdater { * @param $patchFile String: path to the patch to correct the field */ protected function checkBin( $table, $field, $patchFile ) { + if ( !$this->doTable( $table ) ) { + return true; + } + $tableName = $this->db->tableName( $table ); $res = $this->db->query( "SELECT $field FROM $tableName LIMIT 0", __METHOD__ ); $flags = explode( ' ', mysql_field_flags( $res->result, 0 ) ); @@ -260,6 +264,10 @@ class MysqlUpdater extends DatabaseUpdater { * @return Boolean */ protected function indexHasField( $table, $index, $field ) { + if ( !$this->doTable( $table ) ) { + return true; + } + $info = $this->db->indexInfo( $table, $index, __METHOD__ ); if ( $info ) { foreach ( $info as $row ) { @@ -279,6 +287,10 @@ class MysqlUpdater extends DatabaseUpdater { protected function doInterwikiUpdate() { global $IP; + if ( !$this->doTable( 'interwiki' ) ) { + return true; + } + if ( $this->db->tableExists( "interwiki", __METHOD__ ) ) { $this->output( "...already have interwiki table\n" ); return; @@ -567,6 +579,10 @@ class MysqlUpdater extends DatabaseUpdater { } protected function doUserUniqueUpdate() { + if ( !$this->doTable( 'user' ) ) { + return true; + } + $duper = new UserDupes( $this->db, array( $this, 'output' ) ); if ( $duper->hasUniqueIndex() ) { $this->output( "...already have unique user_name index.\n" ); @@ -580,6 +596,10 @@ class MysqlUpdater extends DatabaseUpdater { } protected function doUserGroupsUpdate() { + if ( !$this->doTable( 'user_groups' ) ) { + return true; + } + if ( $this->db->tableExists( 'user_groups', __METHOD__ ) ) { $info = $this->db->fieldInfo( 'user_groups', 'ug_group' ); if ( $info->type() == 'int' ) { @@ -779,12 +799,21 @@ class MysqlUpdater extends DatabaseUpdater { protected function doEnableProfiling() { global $wgProfileToDatabase; + + if ( !$this->doTable( 'profiling' ) ) { + return true; + } + if ( $wgProfileToDatabase === true && ! $this->db->tableExists( 'profiling', __METHOD__ ) ) { $this->applyPatch( 'patch-profiling.sql', false, 'Add profiling table' ); } } protected function doMaybeProfilingMemoryUpdate() { + if ( !$this->doTable( 'profiling' ) ) { + return true; + } + if ( !$this->db->tableExists( 'profiling', __METHOD__ ) ) { return true; } elseif ( $this->db->fieldExists( 'profiling', 'pf_memory', __METHOD__ ) ) { @@ -856,6 +885,10 @@ class MysqlUpdater extends DatabaseUpdater { } protected function doUserNewTalkTimestampNotNull() { + if ( !$this->doTable( 'user_newtalk' ) ) { + return true; + } + $info = $this->db->fieldInfo( 'user_newtalk', 'user_last_timestamp' ); if ( $info === false ) { return;