From 35e3be9b5b4adbcd5865a6e0994196ebdcf84951 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sat, 11 Sep 2010 15:20:39 +0000 Subject: [PATCH] Moved drop_index_if_exists() to DatabaseUpdater and renamed it to dropIndex() for consistency with dropField() --- includes/installer/DatabaseUpdater.php | 18 ++++++++++++++++++ includes/installer/MysqlUpdater.php | 4 ++-- includes/installer/SqliteUpdater.php | 4 ++-- maintenance/updaters.inc | 15 --------------- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/includes/installer/DatabaseUpdater.php b/includes/installer/DatabaseUpdater.php index 0110235355..6ed2ef162e 100644 --- a/includes/installer/DatabaseUpdater.php +++ b/includes/installer/DatabaseUpdater.php @@ -328,6 +328,24 @@ abstract class DatabaseUpdater { } } + /** + * Drop an index from an existing table + * + * @param $table String: Name of the table to modify + * @param $index String: Name of the old index + * @param $patch String: Path to the patch file + * @param $fullpath Boolean: Whether to treat $patch path as a relative or not + */ + function dropIndex( $table, $index, $patch, $fullpath = false ) { + if ( $this->db->indexExists( $table, $index ) ) { + wfOut( "Dropping $index from table $table... " ); + $this->applyPatch( $patch, $fullpath ); + wfOut( "ok\n" ); + } else { + wfOut( "...$index key doesn't exist.\n" ); + } + } + /** * Modify an existing field * diff --git a/includes/installer/MysqlUpdater.php b/includes/installer/MysqlUpdater.php index efb4f5c04b..b7e16cc7bc 100644 --- a/includes/installer/MysqlUpdater.php +++ b/includes/installer/MysqlUpdater.php @@ -162,8 +162,8 @@ class MysqlUpdater extends DatabaseUpdater { array( 'addIndex', 'iwlinks', 'iwl_prefix_title_from', 'patch-rename-iwl_prefix.sql' ), array( 'addField', 'updatelog', 'ul_value', 'patch-ul_value.sql' ), array( 'addField', 'interwiki', 'iw_api', 'patch-iw_api_and_wikiid.sql' ), - array( 'drop_index_if_exists', 'iwlinks', 'iwl_prefix', 'patch-kill-iwl_prefix.sql' ), - array( 'drop_index_if_exists', 'iwlinks', 'iwl_prefix_from_title', 'patch-kill-iwl_pft.sql' ), + array( 'dropIndex', 'iwlinks', 'iwl_prefix', 'patch-kill-iwl_prefix.sql' ), + array( 'dropIndex', 'iwlinks', 'iwl_prefix_from_title', 'patch-kill-iwl_pft.sql' ), array( 'addField', 'categorylinks', 'cl_collation', 'patch-categorylinks-better-collation.sql' ), array( 'do_cl_fields_update' ), array( 'do_collation_update' ), diff --git a/includes/installer/SqliteUpdater.php b/includes/installer/SqliteUpdater.php index ce88f0e6f4..b2f0de3c14 100644 --- a/includes/installer/SqliteUpdater.php +++ b/includes/installer/SqliteUpdater.php @@ -45,8 +45,8 @@ class SqliteUpdater extends DatabaseUpdater { array( 'addIndex', 'iwlinks', 'iwl_prefix_title_from', 'patch-rename-iwl_prefix.sql' ), array( 'addField', 'updatelog', 'ul_value', 'patch-ul_value.sql' ), array( 'addField', 'interwiki', 'iw_api', 'patch-iw_api_and_wikiid.sql' ), - array( 'drop_index_if_exists', 'iwlinks', 'iwl_prefix', 'patch-kill-iwl_prefix.sql' ), - array( 'drop_index_if_exists', 'iwlinks', 'iwl_prefix_from_title', 'patch-kill-iwl_pft.sql' ), + array( 'dropIndex', 'iwlinks', 'iwl_prefix', 'patch-kill-iwl_prefix.sql' ), + array( 'dropIndex', 'iwlinks', 'iwl_prefix_from_title', 'patch-kill-iwl_pft.sql' ), array( 'addTable', 'msg_resource', 'patch-msg_resource.sql' ), array( 'addTable', 'module_deps', 'patch-module_deps.sql' ), ); diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index f74c015229..5d28cc1995 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -9,21 +9,6 @@ if ( !defined( 'MEDIAWIKI' ) ) { exit( 1 ); } -function drop_index_if_exists( $table, $index, $patch, $fullpath = false ) { - $dbw = wfGetDB( DB_MASTER ); - if ( $dbw->indexExists( $table, $index ) ) { - wfOut( "Dropping $index from table $table... " ); - if ( $fullpath ) { - $dbw->sourceFile( $patch ); - } else { - $dbw->sourceFile( archive( $patch ) ); - } - wfOut( "ok\n" ); - } else { - wfOut( "...$index doesn't exist.\n" ); - } -} - function archive( $name ) { return DatabaseBase::patchPath( $name ); } -- 2.20.1