X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2Fupdaters.inc;h=fbc989362c559f4e146928d09a17f7d13ce3cc6f;hb=11c921c459dd8a2bc4da585cfea1555712fbc778;hp=b9f491e8def28228f3191f10b51c83c66216c8cc;hpb=7d3e76c415859151e7d955bffa69ae4574c0acb7;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index b9f491e8de..fbc989362c 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -11,7 +11,6 @@ if ( !defined( 'MEDIAWIKI' ) ) { require_once 'convertLinks.inc'; require_once 'userDupes.inc'; -require_once 'deleteDefaultMessages.php'; # Extension updates require_once( "$IP/includes/Hooks.php" ); @@ -38,6 +37,7 @@ $wgUpdates = array( array( 'add_table', 'categorylinks', 'patch-categorylinks.sql' ), // do_linkscc_1_3_update obsolete array( 'do_old_links_update' ), + array( 'fix_ancient_imagelinks' ), array( 'add_field', 'recentchanges', 'rc_ip', 'patch-rc_ip.sql' ), // 1.4 @@ -143,18 +143,27 @@ $wgUpdates = array( array( 'check_bin', 'protected_titles', 'pt_title', 'patch-pt_title-encoding.sql', ), array( 'maybe_do_profiling_memory_update' ), array( 'do_filearchive_indices_update' ), - array( 'update_password_format' ), // 1.14 array( 'add_field', 'site_stats', 'ss_active_users', 'patch-ss_active_users.sql' ), array( 'do_active_users_init' ), array( 'add_field', 'ipblocks', 'ipb_allow_usertalk', 'patch-ipb_allow_usertalk.sql' ), - array( 'do_unique_pl_tl_il' ), // 1.15 + array( 'do_unique_pl_tl_il' ), array( 'add_table', 'change_tag', 'patch-change_tag.sql' ), array( 'add_table', 'tag_summary', 'patch-change_tag.sql' ), array( 'add_table', 'valid_tag', 'patch-change_tag.sql' ), + + // 1.16 + array( 'add_table', 'user_properties', 'patch-user_properties.sql' ), + array( 'add_table', 'log_search', 'patch-log_search.sql' ), + array( 'do_log_search_population' ), + array( 'add_field', 'logging', 'log_user_text', 'patch-log_user_text.sql' ), + array( 'add_table', 'l10n_cache', 'patch-l10n_cache.sql' ), + array( 'add_table', 'external_user', 'patch-external_user.sql' ), + array( 'add_index', 'log_search', 'ls_field_val', 'patch-log_search-rename-index.sql' ), + array( 'add_index', 'change_tag', 'change_tag_rc_tag', 'patch-change_tag-indexes.sql' ), ), 'sqlite' => array( @@ -168,6 +177,13 @@ $wgUpdates = array( array( 'add_table', 'change_tag', 'patch-change_tag.sql' ), array( 'add_table', 'tag_summary', 'patch-change_tag.sql' ), array( 'add_table', 'valid_tag', 'patch-change_tag.sql' ), + + // 1.16 + array( 'add_table', 'user_properties', 'patch-user_properties.sql' ), + array( 'add_table', 'log_search', 'patch-log_search.sql' ), + array( 'do_log_search_population' ), + array( 'add_field', 'redirect', 'rd_interwiki', 'patch-rd_interwiki.sql' ), + array( 'add_table', 'l10n_cache', 'patch-l10n_cache.sql' ), ), ); @@ -176,8 +192,10 @@ $wgUpdates = array( # $wgDBtype should be checked to specifiy the proper file $wgExtNewTables = array(); // table, dir $wgExtNewFields = array(); // table, column, dir -$wgExtPGNewFields = array(); // table, column attributes; for PostgreSQL +$wgExtPGNewFields = array(); // table, column, column attributes; for PostgreSQL +$wgExtPGAlteredFields = array(); // table, column, new type, conversion method; for PostgreSQL $wgExtNewIndexes = array(); // table, index, dir +$wgExtModifiedFields = array(); //table, index, dir # Helper function: check if the given key is present in the updatelog table. # Obviously, only use this for updates that occur after the updatelog table was @@ -200,7 +218,7 @@ function rename_table( $from, $to, $patch ) { wfOut( "...can't move table $from to $to, $to already exists.\n" ); } else { wfOut( "Moving table $from to $to..." ); - dbsource( archive($patch), $wgDatabase ); + $wgDatabase->sourceFile( archive($patch) ); wfOut( "ok\n" ); } } else { @@ -217,14 +235,33 @@ function add_table( $name, $patch, $fullpath=false ) { } else { wfOut( "Creating $name table..." ); if( $fullpath ) { - dbsource( $patch, $wgDatabase ); + $wgDatabase->sourceFile( $patch ); + } else { + $wgDatabase->sourceFile( archive($patch) ); + } + wfOut( "ok\n" ); + } +} + +function modify_field($table, $field, $patch, $fullpath=false){ + global $wgDatabase; + if ( !$wgDatabase->tableExists( $table ) ) { + wfOut( "...$table table does not exist, skipping modify field patch\n" ); + } elseif (! $wgDatabase->fieldExists( $table, $field ) ) { + wfOut( "...$field field does not exist in $table table, skipping modify field patch\n" ); + } else { + wfOut( "Modifying $field field of table $table..." ); + if( $fullpath ) { + $wgDatabase->sourceFile( $patch ); } else { - dbsource( archive($patch), $wgDatabase ); + $wgDatabase->sourceFile( archive($patch) ); } wfOut( "ok\n" ); } } + + function add_field( $table, $field, $patch, $fullpath=false ) { global $wgDatabase; if ( !$wgDatabase->tableExists( $table ) ) { @@ -234,9 +271,9 @@ function add_field( $table, $field, $patch, $fullpath=false ) { } else { wfOut( "Adding $field field to table $table..." ); if( $fullpath ) { - dbsource( $patch, $wgDatabase ); + $wgDatabase->sourceFile( $patch ); } else { - dbsource( archive($patch), $wgDatabase ); + $wgDatabase->sourceFile( archive($patch) ); } wfOut( "ok\n" ); } @@ -249,49 +286,14 @@ function add_index( $table, $index, $patch, $fullpath=false ) { } else { wfOut( "Adding $index key to table $table... " ); if( $fullpath ) { - dbsource( $patch, $wgDatabase ); + $wgDatabase->sourceFile( $patch ); } else { - dbsource( archive($patch), $wgDatabase ); + $wgDatabase->sourceFile( archive($patch) ); } wfOut( "ok\n" ); } } -function do_revision_updates() { - global $wgSoftwareRevision; - if ( $wgSoftwareRevision < 1001 ) { - update_passwords(); - } -} - -function update_passwords() { - wfDebugDieBacktrace( "This function needs to be updated or removed.\n" ); - - global $wgDatabase; - $fname = "Update script: update_passwords()"; - wfOut( "\nIt appears that you need to update the user passwords in your\n" . - "database. If you have already done this (if you've run this update\n" . - "script once before, for example), doing so again will make all your\n" . - "user accounts inaccessible, so be sure you only do this once.\n" . - "Update user passwords? (yes/no)" ); - - $resp = readconsole(); - if ( ! ( "Y" == $resp{0} || "y" == $resp{0} ) ) { return; } - - $sql = "SELECT user_id,user_password FROM user"; - $source = $wgDatabase->query( $sql, $fname ); - - while ( $row = $wgDatabase->fetchObject( $source ) ) { - $id = $row->user_id; - $oldpass = $row->user_password; - $newpass = md5( "{$id}-{$oldpass}" ); - - $sql = "UPDATE user SET user_password='{$newpass}' " . - "WHERE user_id={$id}"; - $wgDatabase->query( $sql, $fname ); - } -} - function do_interwiki_update() { # Check that interwiki table exists; if it doesn't source it global $wgDatabase, $IP; @@ -300,10 +302,10 @@ function do_interwiki_update() { return true; } wfOut( "Creating interwiki table: " ); - dbsource( archive("patch-interwiki.sql") ); + $wgDatabase->sourceFile( archive("patch-interwiki.sql") ); wfOut( "ok\n" ); wfOut( "Adding default interwiki definitions: " ); - dbsource( "$IP/maintenance/interwiki.sql" ); + $wgDatabase->sourceFile( "$IP/maintenance/interwiki.sql" ); wfOut( "ok\n" ); } @@ -313,7 +315,7 @@ function do_index_update() { $meta = $wgDatabase->fieldInfo( "recentchanges", "rc_timestamp" ); if( !$meta->isMultipleKey() ) { wfOut( "Updating indexes to 20031107: " ); - dbsource( archive("patch-indexes.sql") ); + $wgDatabase->sourceFile( archive("patch-indexes.sql") ); wfOut( "ok\n" ); return true; } @@ -327,7 +329,7 @@ function do_image_index_update() { $meta = $wgDatabase->fieldInfo( "image", "img_major_mime" ); if( !$meta->isMultipleKey() ) { wfOut( "Updating indexes to 20050912: " ); - dbsource( archive("patch-mimesearch-indexes.sql") ); + $wgDatabase->sourceFile( archive("patch-mimesearch-indexes.sql") ); wfOut( "ok\n" ); return true; } @@ -341,7 +343,7 @@ function do_image_name_unique_update() { wfOut( "...image primary key already set.\n" ); } else { wfOut( "Making img_name the primary key... " ); - dbsource( archive("patch-image_name_primary.sql"), $wgDatabase ); + $wgDatabase->sourceFile( archive("patch-image_name_primary.sql") ); wfOut( "ok\n" ); } } @@ -352,7 +354,7 @@ function do_logging_timestamp_index() { wfOut( "...timestamp key on logging already exists.\n" ); } else { wfOut( "Adding timestamp key on logging table... " ); - dbsource( archive("patch-logging-times-index.sql"), $wgDatabase ); + $wgDatabase->sourceFile( archive("patch-logging-times-index.sql") ); wfOut( "ok\n" ); } } @@ -363,7 +365,7 @@ function do_archive_user_index() { wfOut( "...usertext,timestamp key on archive already exists.\n" ); } else { wfOut( "Adding usertext,timestamp key on archive table... " ); - dbsource( archive("patch-archive-user-index.sql"), $wgDatabase ); + $wgDatabase->sourceFile( archive("patch-archive-user-index.sql") ); wfOut( "ok\n" ); } } @@ -374,7 +376,7 @@ function do_image_user_index() { wfOut( "...usertext,timestamp key on image already exists.\n" ); } else { wfOut( "Adding usertext,timestamp key on image table... " ); - dbsource( archive("patch-image-user-index.sql"), $wgDatabase ); + $wgDatabase->sourceFile( archive("patch-image-user-index.sql") ); wfOut( "ok\n" ); } } @@ -385,7 +387,7 @@ function do_oldimage_user_index() { wfOut( "...usertext,timestamp key on oldimage already exists.\n" ); } else { wfOut( "Adding usertext,timestamp key on oldimage table... " ); - dbsource( archive("patch-oldimage-user-index.sql"), $wgDatabase ); + $wgDatabase->sourceFile( archive("patch-oldimage-user-index.sql") ); wfOut( "ok\n" ); } } @@ -398,7 +400,7 @@ function do_watchlist_update() { } else { wfOut( "Adding wl_notificationtimestamp field for email notification management." ); /* ALTER TABLE watchlist ADD (wl_notificationtimestamp varchar(14) binary NOT NULL default '0'); */ - dbsource( archive( 'patch-email-notification.sql' ), $wgDatabase ); + $wgDatabase->sourceFile( archive( 'patch-email-notification.sql' ) ); wfOut( "ok\n" ); } # Check if we need to add talk page rows to the watchlist @@ -464,7 +466,7 @@ function do_user_update() { global $wgDatabase; if( $wgDatabase->fieldExists( 'user', 'user_emailauthenticationtimestamp' ) ) { wfOut( "User table contains old email authentication field. Dropping... " ); - dbsource( archive( 'patch-email-authentication.sql' ), $wgDatabase ); + $wgDatabase->sourceFile( archive( 'patch-email-authentication.sql' ) ); wfOut( "ok\n" ); } else { wfOut( "...user table does not contain old email authentication field.\n" ); @@ -488,7 +490,7 @@ function check_bin( $table, $field, $patchFile ) { wfOut( "$table table has correct $field encoding.\n" ); } else { wfOut( "Fixing $field encoding on $table table... " ); - dbsource( archive( $patchFile ), $wgDatabase ); + $wgDatabase->sourceFile( archive( $patchFile ) ); wfOut( "ok\n" ); } } @@ -663,7 +665,7 @@ function do_inverse_timestamp() { global $wgDatabase; if( $wgDatabase->fieldExists( 'revision', 'inverse_timestamp' ) ) { wfOut( "Removing revision.inverse_timestamp and fixing indexes... " ); - dbsource( archive( 'patch-inverse_timestamp.sql' ), $wgDatabase ); + $wgDatabase->sourceFile( archive( 'patch-inverse_timestamp.sql' ) ); wfOut( "ok\n" ); } else { wfOut( "revision timestamp indexes already up to 2005-03-13\n" ); @@ -676,7 +678,7 @@ function do_text_id() { wfOut( "...rev_text_id already in place.\n" ); } else { wfOut( "Adding rev_text_id field... " ); - dbsource( archive( 'patch-rev_text_id.sql' ), $wgDatabase ); + $wgDatabase->sourceFile( archive( 'patch-rev_text_id.sql' ) ); wfOut( "ok\n" ); } } @@ -725,7 +727,7 @@ function do_pagelinks_update() { wfOut( "...already have pagelinks table.\n" ); } else { wfOut( "Converting links and brokenlinks tables to pagelinks... " ); - dbsource( archive( 'patch-pagelinks.sql' ), $wgDatabase ); + $wgDatabase->sourceFile( archive( 'patch-pagelinks.sql' ) ); wfOut( "ok\n" ); flush(); @@ -764,7 +766,7 @@ function do_drop_img_type() { if( $wgDatabase->fieldExists( 'image', 'img_type' ) ) { wfOut( "Dropping unused img_type field in image table... " ); - dbsource( archive( 'patch-drop_img_type.sql' ), $wgDatabase ); + $wgDatabase->sourceFile( archive( 'patch-drop_img_type.sql' ) ); wfOut( "ok\n" ); } else { wfOut( "No img_type field in image table; Good.\n" ); @@ -780,6 +782,19 @@ function do_old_links_update() { } } +function fix_ancient_imagelinks() { + global $wgDatabase; + $info = $wgDatabase->fieldInfo( 'imagelinks', 'il_from' ); + if ( $info && $info->type() === 'string' ) { + wfOut( "Fixing ancient broken imagelinks table.\n" ); + wfOut( "NOTE: you will have to run maintenance/refreshLinks.php after this.\n" ); + $wgDatabase->sourceFile( archive( 'patch-fix-il_from.sql' ) ); + wfOut( "ok\n" ); + } else { + wfOut( "...il_from OK\n" ); + } +} + function do_user_unique_update() { global $wgDatabase; $duper = new UserDupes( $wgDatabase ); @@ -790,7 +805,7 @@ function do_user_unique_update() { wfOut( "WARNING: This next step will probably fail due to unfixed duplicates...\n" ); } wfOut( "Adding unique index on user_name... " ); - dbsource( archive( 'patch-user_nameindex.sql' ), $wgDatabase ); + $wgDatabase->sourceFile( archive( 'patch-user_nameindex.sql' ) ); wfOut( "ok\n" ); } } @@ -805,13 +820,13 @@ function do_user_groups_update() { } wfOut( "Adding user_groups table... " ); - dbsource( archive( 'patch-user_groups.sql' ), $wgDatabase ); + $wgDatabase->sourceFile( archive( 'patch-user_groups.sql' ) ); wfOut( "ok\n" ); if( !$wgDatabase->tableExists( 'user_rights' ) ) { if( $wgDatabase->fieldExists( 'user', 'user_rights' ) ) { wfOut( "Upgrading from a 1.3 or older database? Breaking out user_rights for conversion..." ); - dbsource( archive( 'patch-user_rights.sql' ), $wgDatabase ); + $wgDatabase->sourceFile( archive( 'patch-user_rights.sql' ) ); wfOut( "ok\n" ); } else { wfOut( "*** WARNING: couldn't locate user_rights table or field for upgrade.\n" ); @@ -857,7 +872,7 @@ function do_user_groups_reformat() { wfOut( "ok\n" ); wfOut( "Re-adding fresh user_groups table... " ); - dbsource( archive( 'patch-user_groups.sql' ), $wgDatabase ); + $wgDatabase->sourceFile( archive( 'patch-user_groups.sql' ) ); wfOut( "ok\n" ); wfOut( "***\n" ); @@ -878,7 +893,7 @@ function do_watchlist_null() { if( !$info->nullable() ) { wfOut( "Making wl_notificationtimestamp nullable... " ); - dbsource( archive( 'patch-watchlist-null.sql' ), $wgDatabase ); + $wgDatabase->sourceFile( archive( 'patch-watchlist-null.sql' ) ); wfOut( "ok\n" ); } else { wfOut( "...wl_notificationtimestamp is already nullable.\n" ); @@ -910,7 +925,7 @@ function do_templatelinks_update() { return; } wfOut( "Creating templatelinks table...\n" ); - dbsource( archive('patch-templatelinks.sql'), $wgDatabase ); + $wgDatabase->sourceFile( archive('patch-templatelinks.sql') ); wfOut( "Populating...\n" ); if ( isset( $wgLoadBalancer ) && $wgLoadBalancer->getServerCount() > 1 ) { // Slow, replication-friendly update @@ -966,7 +981,7 @@ function do_rc_indices_update() { $info = $wgDatabase->indexInfo( 'recentchanges', $index, __METHOD__ ); if( !$info ) { wfOut( "...index `{$index}` not found; adding..." ); - dbsource( archive( $patch ) ); + $wgDatabase->sourceFile( archive( $patch ) ); wfOut( "done.\n" ); } else { wfOut( "...index `{$index}` seems ok.\n" ); @@ -991,21 +1006,23 @@ function index_has_field($table, $index, $field) { } function do_backlinking_indices_update() { + global $wgDatabase; wfOut( "Checking for backlinking indices...\n" ); if (!index_has_field('pagelinks', 'pl_namespace', 'pl_from') || !index_has_field('templatelinks', 'tl_namespace', 'tl_from') || !index_has_field('imagelinks', 'il_to', 'il_from')) { - dbsource( archive( 'patch-backlinkindexes.sql' ) ); + $wgDatabase->sourceFile( archive( 'patch-backlinkindexes.sql' ) ); wfOut( "...backlinking indices updated\n" ); } } function do_categorylinks_indices_update() { + global $wgDatabase; wfOut( "Checking for categorylinks indices...\n" ); if (!index_has_field('categorylinks', 'cl_sortkey', 'cl_from')) { - dbsource( archive( 'patch-categorylinksindex.sql' ) ); + $wgDatabase->sourceFile( archive( 'patch-categorylinksindex.sql' ) ); wfOut( "...categorylinks indices updated\n" ); } } @@ -1016,7 +1033,7 @@ function do_filearchive_indices_update() { $info = $wgDatabase->indexInfo( 'filearchive', 'fa_user_timestamp', __METHOD__ ); if ( !$info ) { - dbsource( archive( 'patch-filearhive-user-index.sql' ) ); + $wgDatabase->sourceFile( archive( 'patch-filearchive-user-index.sql' ) ); wfOut( "...filearchive indices updated\n" ); } } @@ -1029,7 +1046,7 @@ function maybe_do_profiling_memory_update() { wfOut( "profiling table has pf_memory field.\n" ); } else { wfOut( "Adding pf_memory field to table profiling..." ); - dbsource( archive( 'patch-profiling-memory.sql' ), $wgDatabase ); + $wgDatabase->sourceFile( archive( 'patch-profiling-memory.sql' ) ); wfOut( "ok\n" ); } } @@ -1047,10 +1064,7 @@ function do_stats_init() { wfOut( "ok.\n" ); return; } - - global $IP; - require_once "$IP/maintenance/initStats.inc"; - wfInitStats(); + SiteStatsInit::doAllAndCommit( false ); } function do_active_users_init() { @@ -1079,7 +1093,7 @@ function purge_cache() { } function do_all_updates( $shared = false, $purge = true ) { - global $wgNewTables, $wgNewFields, $wgRenamedTables, $wgSharedDB, $wgSharedTables, $wgDatabase, $wgDBtype, $IP; + global $wgNewTables, $wgExtModifiedFields, $wgNewFields, $wgRenamedTables, $wgSharedDB, $wgSharedTables, $wgDatabase, $wgDBtype, $IP; wfRunHooks('LoadExtensionSchemaUpdates'); @@ -1119,10 +1133,19 @@ function do_all_updates( $shared = false, $purge = true ) { add_index( $fieldRecord[0], $fieldRecord[1], $fieldRecord[2], true ); flush(); } + # Add modified extension fields + foreach ( $wgExtModifiedFields as $fieldRecord ) { + modify_field($fieldRecord[0], $fieldRecord[1], $fieldRecord[2], true); + flush(); + } wfOut( "Deleting old default messages (this may take a long time!)..." ); - deleteDefaultMessages(); + if( !defined( 'MW_NO_SETUP' ) ) { + define( 'MW_NO_SETUP', true ); + } + require_once 'deleteDefaultMessages.php'; + DeleteDefaultMessages::reallyExecute(); wfOut( "Done\n" ); do_stats_init(); @@ -1156,8 +1179,8 @@ function do_restrictions_update() { wfOut( "...$name table already exists.\n" ); } else { wfOut( "Creating $name table..." ); - dbsource( archive($patch), $wgDatabase ); - dbsource( archive($patch2), $wgDatabase ); + $wgDatabase->sourceFile( archive($patch) ); + $wgDatabase->sourceFile( archive($patch2) ); wfOut( "ok\n" ); wfOut( "Migrating old restrictions to new table..." ); @@ -1241,29 +1264,6 @@ function do_populate_parent_id() { populate_rev_parent_id( $wgDatabase ); } -function update_password_format() { - if ( update_row_exists( 'password format' ) ) { - wfOut( "...password hash format already changed\n" ); - return; - } - - wfOut( "Updating password hash format..." ); - - global $wgDatabase, $wgPasswordSalt; - $user = $wgDatabase->tableName( 'user' ); - if ( $wgPasswordSalt ) { - $sql = "UPDATE $user SET user_password=CONCAT(':B:', user_id, ':', user_password) " . - "WHERE user_password NOT LIKE ':%'"; - } else { - $sql = "UPDATE $user SET user_password=CONCAT(':A:', user_password) " . - "WHERE user_password NOT LIKE ':%'"; - } - $wgDatabase->query( $sql, __METHOD__ ); - $wgDatabase->insert( 'updatelog', array( 'ul_key' => 'password format' ), __METHOD__ ); - - wfOut( "done\n" ); -} - function sqlite_initial_indexes() { global $wgDatabase; if ( update_row_exists( 'initial_indexes' ) ) { @@ -1282,11 +1282,26 @@ function do_unique_pl_tl_il() { wfOut( "...pl_namespace, tl_namespace, il_to indices are already UNIQUE.\n" ); } else { wfOut( "Making pl_namespace, tl_namespace and il_to indices UNIQUE... " ); - dbsource( archive( 'patch-pl-tl-il-unique.sql' ), $wgDatabase ); + $wgDatabase->sourceFile( archive( 'patch-pl-tl-il-unique.sql' ) ); wfOut( "ok\n" ); } } +function do_log_search_population() { + global $wgDatabase; + if( update_row_exists( 'populate log_search' ) ) { + wfOut( "...log_search table already populated.\n" ); + return; + } + require_once( 'populateLogSearch.inc' ); + wfOut( +"Populating log_search table, printing progress markers. For large\n" . +"databases, you may want to hit Ctrl-C and do this manually with\n" . +"maintenance/populateLogSearch.php.\n" ); + migrate_log_params( $wgDatabase ); + wfOut( "Done populating log_search table.\n" ); +} + /*********************************************************************** * Start PG crap * TODO: merge with above @@ -1500,8 +1515,11 @@ function do_postgres_updates() { array("redirect", "patch-redirect.sql"), array("updatelog", "patch-updatelog.sql"), array('change_tag', 'patch-change_tag.sql'), - array('tag_summary', 'patch-change_tag.sql'), - array('valid_tag', 'patch-change_tag.sql'), + array('tag_summary', 'patch-change_tag.sql'), + array('valid_tag', 'patch-change_tag.sql'), + array('user_properties', 'patch-user_properties.sql'), + array('log_search', 'patch-log_search.sql'), + array('l10n_cache', 'patch-l10n_cache.sql'), ); $newcols = array( @@ -1544,6 +1562,8 @@ function do_postgres_updates() { array("revision", "rev_parent_id", "INTEGER DEFAULT NULL"), array("site_stats", "ss_active_users", "INTEGER DEFAULT '-1'"), array("user_newtalk", "user_last_timestamp", "TIMESTAMPTZ"), + array("logging", "log_user_text", "TEXT NOT NULL DEFAULT ''"), + array("logging", "log_page", "INTEGER"), ); @@ -1612,6 +1632,8 @@ function do_postgres_updates() { array("recentchanges", "rc_timestamp_bot", "(rc_timestamp) WHERE rc_bot = 0"), array("templatelinks", "templatelinks_from", "(tl_from)"), array("watchlist", "wl_user", "(wl_user)"), + array("logging", "logging_user_type_time", "(log_user, log_type, log_timestamp)"), + array("logging", "logging_page_id_time", "(log_page,log_timestamp)"), ); $newrules = array( @@ -1634,7 +1656,7 @@ function do_postgres_updates() { } wfOut( "Creating table \"$nt[0]\"\n" ); - dbsource(archive($nt[1])); + $wgDatabase->sourceFile(archive($nt[1])); } ## Needed before newcols @@ -1648,7 +1670,7 @@ function do_postgres_updates() { wfOut( "Dropping rule \"archive_delete\"\n" ); $wgDatabase->query("DROP RULE archive_delete ON archive"); } - dbsource(archive("patch-remove-archive2.sql")); + $wgDatabase->sourceFile(archive("patch-remove-archive2.sql")); } else wfOut( "... obsolete table \"archive2\" does not exist\n" ); @@ -1743,21 +1765,27 @@ function do_postgres_updates() { continue; } wfOut( "Adding rule \"$nr[1]\" to table \"$nr[0]\"\n" ); - dbsource(archive($nr[2])); + $wgDatabase->sourceFile(archive($nr[2])); } - if ($wgDatabase->hasConstraint("oldimage_oi_name_fkey")) { - wfOut( "Making foreign key on table \"oldimage\" (to image) a cascade delete\n" ); - $wgDatabase->query( "ALTER TABLE oldimage DROP CONSTRAINT oldimage_oi_name_fkey" ); - $wgDatabase->query( "ALTER TABLE oldimage ADD CONSTRAINT oldimage_oi_name_fkey_cascade ". - "FOREIGN KEY (oi_name) REFERENCES image(img_name) ON DELETE CASCADE" ); + if ($wgDatabase->hasConstraint("oldimage_oi_name_fkey_cascaded")) { + wfOut( "... table \"oldimage\" has correct cascading delete/update foreign key to image\n" ); + } + else { + if ($wgDatabase->hasConstraint("oldimage_oi_name_fkey")) { + $wgDatabase->query( "ALTER TABLE oldimage DROP CONSTRAINT oldimage_oi_name_fkey" ); + } + if ($wgDatabase->hasConstraint("oldimage_oi_name_fkey_cascade")) { + $wgDatabase->query( "ALTER TABLE oldimage DROP CONSTRAINT oldimage_oi_name_fkey_cascade" ); + } + wfOut( "Making foreign key on table \"oldimage\" (to image) a cascade delete/update\n" ); + $wgDatabase->query( "ALTER TABLE oldimage ADD CONSTRAINT oldimage_oi_name_fkey_cascaded ". + "FOREIGN KEY (oi_name) REFERENCES image(img_name) ON DELETE CASCADE ON UPDATE CASCADE" ); } - else - wfOut( "... table \"oldimage\" has correct cascade delete foreign key to image\n" ); if (!$wgDatabase->triggerExists("page", "page_deleted")) { wfOut( "Adding function and trigger \"page_deleted\" to table \"page\"\n" ); - dbsource(archive('patch-page_deleted.sql')); + $wgDatabase->sourceFile(archive('patch-page_deleted.sql')); } else wfOut( "... table \"page\" has \"page_deleted\" trigger\n" ); @@ -1765,7 +1793,7 @@ function do_postgres_updates() { $fi = $wgDatabase->fieldInfo("recentchanges", "rc_cur_id"); if (!$fi->nullable()) { wfOut( "Removing NOT NULL constraint from \"recentchanges.rc_cur_id\"\n" ); - dbsource(archive('patch-rc_cur_id-not-null.sql')); + $wgDatabase->sourceFile(archive('patch-rc_cur_id-not-null.sql')); } else wfOut( "... column \"recentchanges.rc_cur_id\" has a NOT NULL constraint\n" ); @@ -1791,7 +1819,7 @@ function do_postgres_updates() { } else { wfOut( "Changing constraint \"revision_rev_user_fkey\" to ON DELETE RESTRICT\n" ); - dbsource(archive('patch-revision_rev_user_fkey.sql')); + $wgDatabase->sourceFile(archive('patch-revision_rev_user_fkey.sql')); } # Fix ipb_address index @@ -1804,10 +1832,10 @@ function do_postgres_updates() { } else { wfOut( "Adding ipb_address_unique index\n" ); - dbsource(archive('patch-ipb_address_unique.sql')); + $wgDatabase->sourceFile(archive('patch-ipb_address_unique.sql')); } - global $wgExtNewTables, $wgExtPGNewFields, $wgExtNewIndexes; + global $wgExtNewTables, $wgExtPGNewFields, $wgExtPGAlteredFields, $wgExtNewIndexes; # Add missing extension tables foreach ( $wgExtNewTables as $nt ) { if ($wgDatabase->tableExists($nt[0])) { @@ -1815,7 +1843,7 @@ function do_postgres_updates() { continue; } wfOut( "Creating table \"$nt[0]\"\n" ); - dbsource($nt[1]); + $wgDatabase->sourceFile($nt[1]); } # Add missing extension fields foreach ( $wgExtPGNewFields as $nc ) { @@ -1827,6 +1855,26 @@ function do_postgres_updates() { wfOut( "Adding column \"$nc[0].$nc[1]\"\n" ); $wgDatabase->query( "ALTER TABLE $nc[0] ADD $nc[1] $nc[2]" ); } + # Change altered columns + foreach ( $wgExtPGAlteredFields as $nc ) { + $fi = $wgDatabase->fieldInfo($nc[0], $nc[1]); + if (is_null($fi)) { + wfOut( "WARNING! Column \"$nc[0].$nc[1]\" does not exist but had an alter request! Please report this.\n" ); + continue; + } + $oldtype = $fi->type(); + $newtype = strtolower( $nc[2] ); + if ($oldtype === $newtype) { + wfOut( "... column \"$nc[0].$nc[1]\" has correct type of \"$newtype\"\n" ); + continue; + } + $command = "ALTER TABLE $nc[0] ALTER $nc[1] TYPE $nc[2]"; + if ( isset( $nc[3] ) ) { + $command .= " USING $nc[3]"; + } + wfOut( "Altering column \"$nc[0].$nc[1]\" from type \"$oldtype\" to \"$newtype\"\n" ); + $wgDatabase->query( $command ); + } # Add missing extension indexes foreach ( $wgExtNewIndexes as $ni ) { if (pg_index_exists($ni[0], $ni[1])) { @@ -1834,17 +1882,22 @@ function do_postgres_updates() { continue; } wfOut( "Creating index \"$ni[1]\" on table \"$ni[0]\"\n" ); - dbsource($ni[2]); + if ( preg_match( '/^\(/', $ni[2] ) ) { + $wgDatabase->query( "CREATE INDEX $ni[1] ON $ni[0] $ni[2]" ); + } + else { + $wgDatabase->sourceFile($ni[2]); + } } # Tweak the page_title tsearch2 trigger to filter out slashes # This is create or replace, so harmless to call if not needed - dbsource(archive('patch-ts2pagetitle.sql')); + $wgDatabase->sourceFile(archive('patch-ts2pagetitle.sql')); ## If the server is 8.3 or higher, rewrite the tsearch2 triggers ## in case they have the old 'default' versions if ( $numver >= 8.3 ) - dbsource(archive('patch-tsearch2funcs.sql')); + $wgDatabase->sourceFile(archive('patch-tsearch2funcs.sql')); ## Put a new row in the mediawiki_version table $wgDatabase->insert( 'mediawiki_version',