From 958d091aac81214fcd78278050c6a1b8ab388560 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sun, 22 Aug 2010 11:57:31 +0000 Subject: [PATCH] Removed some specific methods from updaters.inc that can use generic ones --- includes/installer/DatabaseUpdater.php | 18 ++++++ includes/installer/MysqlUpdater.php | 18 +++--- maintenance/updaters.inc | 89 -------------------------- 3 files changed, 27 insertions(+), 98 deletions(-) diff --git a/includes/installer/DatabaseUpdater.php b/includes/installer/DatabaseUpdater.php index caa53129e6..4ceeaab2f7 100644 --- a/includes/installer/DatabaseUpdater.php +++ b/includes/installer/DatabaseUpdater.php @@ -220,6 +220,24 @@ abstract class DatabaseUpdater { wfOut( "ok\n" ); } } + + /** + * Drop a field from an existing table + * + * @param $table String Name of the table to modify + * @param $field String Name of the old field + * @param $patch String Path to the patch file + * @param $fullpath Boolean Whether to treat $patch path as a relative or not + */ + function dropField( $table, $field, $patch, $fullpath = false ) { + if ( $this->db->fieldExists( $table, $field ) ) { + wfOut( "Table $table contains $field field. Dropping... " ); + $this->applyPatch( $patch, $fullpath ); + wfOut( "ok\n" ); + } else { + wfOut( "...$table table does not contain $field field.\n" ); + } + } } class OracleUpdater extends DatabaseUpdater { diff --git a/includes/installer/MysqlUpdater.php b/includes/installer/MysqlUpdater.php index 9a4c77dc94..7d76860d71 100644 --- a/includes/installer/MysqlUpdater.php +++ b/includes/installer/MysqlUpdater.php @@ -40,16 +40,16 @@ class MysqlUpdater extends DatabaseUpdater { array( 'addTable', 'logging', 'patch-logging.sql' ), array( 'addField', 'user', 'user_token', 'patch-user_token.sql' ), array( 'do_watchlist_update' ), - array( 'do_user_update' ), + array( 'dropField', 'user', 'user_emailauthenticationtimestamp', 'patch-email-authentication.sql' ), // 1.5 array( 'do_schema_restructuring' ), array( 'addField', 'logging', 'log_params', 'patch-log_params.sql' ), - array( 'check_bin', 'logging', 'log_title', 'patch-logging-title.sql', ), + array( 'check_bin', 'logging', 'log_title', 'patch-logging-title.sql', ), array( 'addField', 'archive', 'ar_rev_id', 'patch-archive-rev_id.sql' ), array( 'addField', 'page', 'page_len', 'patch-page_len.sql' ), - array( 'do_inverse_timestamp' ), - array( 'do_text_id' ), + array( 'dropField', 'revision', 'inverse_timestamp', 'patch-inverse_timestamp.sql' ), + array( 'addField', 'revision', 'rev_text_id', 'patch-rev_text_id.sql' ), array( 'addField', 'revision', 'rev_deleted', 'patch-rev_deleted.sql' ), array( 'addField', 'image', 'img_width', 'patch-img_width.sql' ), array( 'addField', 'image', 'img_metadata', 'patch-img_metadata.sql' ), @@ -58,7 +58,7 @@ class MysqlUpdater extends DatabaseUpdater { array( 'doNamespaceSize' ), array( 'addField', 'image', 'img_media_type', 'patch-img_media_type.sql' ), array( 'do_pagelinks_update' ), - array( 'do_drop_img_type' ), + array( 'dropField', 'image', 'img_type', 'patch-drop_img_type.sql' ), array( 'do_user_unique_update' ), array( 'do_user_groups_update' ), array( 'addField', 'site_stats', 'ss_total_pages', 'patch-ss_total_articles.sql' ), @@ -69,7 +69,7 @@ class MysqlUpdater extends DatabaseUpdater { // 1.6 array( 'do_watchlist_null' ), - array( 'do_logging_timestamp_index' ), + array( 'addIndex', 'logging', 'times', 'patch-logging-times-index.sql' ), array( 'addField', 'ipblocks', 'ipb_range_start', 'patch-ipb_range_start.sql' ), array( 'do_page_random_update' ), array( 'addField', 'user', 'user_registration', 'patch-user_registration.sql' ), @@ -109,9 +109,9 @@ class MysqlUpdater extends DatabaseUpdater { array( 'addField', 'ipblocks', 'ipb_block_email', 'patch-ipb_emailban.sql' ), array( 'do_categorylinks_indices_update' ), array( 'addField', 'oldimage', 'oi_metadata', 'patch-oi_metadata.sql' ), - array( 'do_archive_user_index' ), - array( 'do_image_user_index' ), - array( 'do_oldimage_user_index' ), + array( 'addIndex', 'archive', 'usertext_timestamp', 'patch-archive-user-index.sql' ), + array( 'addIndex', 'image', 'img_usertext_timestamp', 'patch-image-user-index.sql' ), + array( 'addIndex', 'oldimage', 'oi_usertext_timestamp', 'patch-oldimage-user-index.sql' ), array( 'addField', 'archive', 'ar_page_id', 'patch-archive-page_id.sql' ), array( 'addField', 'image', 'img_sha1', 'patch-img_sha1.sql' ), diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index 371493a313..1a46c7c1e8 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -165,50 +165,6 @@ function do_image_name_unique_update() { } } -function do_logging_timestamp_index() { - global $wgDatabase; - if ( $wgDatabase->indexExists( 'logging', 'times' ) ) { - wfOut( "...timestamp key on logging already exists.\n" ); - } else { - wfOut( "Adding timestamp key on logging table... " ); - $wgDatabase->sourceFile( archive( "patch-logging-times-index.sql" ) ); - wfOut( "ok\n" ); - } -} - -function do_archive_user_index() { - global $wgDatabase; - if ( $wgDatabase->indexExists( 'archive', 'usertext_timestamp' ) ) { - wfOut( "...usertext,timestamp key on archive already exists.\n" ); - } else { - wfOut( "Adding usertext,timestamp key on archive table... " ); - $wgDatabase->sourceFile( archive( "patch-archive-user-index.sql" ) ); - wfOut( "ok\n" ); - } -} - -function do_image_user_index() { - global $wgDatabase; - if ( $wgDatabase->indexExists( 'image', 'img_usertext_timestamp' ) ) { - wfOut( "...usertext,timestamp key on image already exists.\n" ); - } else { - wfOut( "Adding usertext,timestamp key on image table... " ); - $wgDatabase->sourceFile( archive( "patch-image-user-index.sql" ) ); - wfOut( "ok\n" ); - } -} - -function do_oldimage_user_index() { - global $wgDatabase; - if ( $wgDatabase->indexExists( 'oldimage', 'oi_usertext_timestamp' ) ) { - wfOut( "...usertext,timestamp key on oldimage already exists.\n" ); - } else { - wfOut( "Adding usertext,timestamp key on oldimage table... " ); - $wgDatabase->sourceFile( archive( "patch-oldimage-user-index.sql" ) ); - wfOut( "ok\n" ); - } -} - function do_watchlist_update() { global $wgDatabase; $fname = 'do_watchlist_update'; @@ -277,17 +233,6 @@ function do_copy_newtalk_to_watchlist() { wfOut( "Done.\n" ); } -function do_user_update() { - global $wgDatabase; - if ( $wgDatabase->fieldExists( 'user', 'user_emailauthenticationtimestamp' ) ) { - wfOut( "User table contains old email authentication field. Dropping... " ); - $wgDatabase->sourceFile( archive( 'patch-email-authentication.sql' ) ); - wfOut( "ok\n" ); - } else { - wfOut( "...user table does not contain old email authentication field.\n" ); - } -} - /** * 1.4 betas were missing the 'binary' marker from logging.log_title, * which causes a collation mismatch error on joins in MySQL 4.1. @@ -475,28 +420,6 @@ function do_schema_restructuring() { } } -function do_inverse_timestamp() { - global $wgDatabase; - if ( $wgDatabase->fieldExists( 'revision', 'inverse_timestamp' ) ) { - wfOut( "Removing revision.inverse_timestamp and fixing indexes... " ); - $wgDatabase->sourceFile( archive( 'patch-inverse_timestamp.sql' ) ); - wfOut( "ok\n" ); - } else { - wfOut( "...revision timestamp indexes already up to 2005-03-13\n" ); - } -} - -function do_text_id() { - global $wgDatabase; - if ( $wgDatabase->fieldExists( 'revision', 'rev_text_id' ) ) { - wfOut( "...rev_text_id already in place.\n" ); - } else { - wfOut( "Adding rev_text_id field... " ); - $wgDatabase->sourceFile( archive( 'patch-rev_text_id.sql' ) ); - wfOut( "ok\n" ); - } -} - function do_pagelinks_update() { global $wgDatabase; if ( $wgDatabase->tableExists( 'pagelinks' ) ) { @@ -537,18 +460,6 @@ function do_pagelinks_namespace( $namespace ) { wfOut( "ok\n" ); } -function do_drop_img_type() { - global $wgDatabase; - - if ( $wgDatabase->fieldExists( 'image', 'img_type' ) ) { - wfOut( "Dropping unused img_type field in image table... " ); - $wgDatabase->sourceFile( archive( 'patch-drop_img_type.sql' ) ); - wfOut( "ok\n" ); - } else { - wfOut( "...no img_type field in image table; Good.\n" ); - } -} - function do_old_links_update() { if( !defined( 'MW_NO_SETUP' ) ) { define( 'MW_NO_SETUP', true ); -- 2.20.1