require_once 'convertLinks.inc';
require_once 'userDupes.inc';
-require_once 'deleteDefaultMessages.php';
# Extension updates
require_once( "$IP/includes/Hooks.php" );
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
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' ),
+
+ // 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' ),
),
'sqlite' => array(
array( 'do_active_users_init' ),
array( 'add_field', 'ipblocks', 'ipb_allow_usertalk', 'patch-ipb_allow_usertalk.sql' ),
array( 'sqlite_initial_indexes' ),
+
+ // 1.15
+ 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' ),
),
);
# $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
# Helper function: check if the given key is present in the updatelog table.
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 {
} else {
wfOut( "Creating $name table..." );
if( $fullpath ) {
- dbsource( $patch, $wgDatabase );
+ $wgDatabase->sourceFile( $patch );
} else {
- dbsource( archive($patch), $wgDatabase );
+ $wgDatabase->sourceFile( archive($patch) );
}
wfOut( "ok\n" );
}
} 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" );
}
} 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;
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" );
}
$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;
}
$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;
}
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" );
}
}
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" );
}
}
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" );
}
}
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" );
}
}
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" );
}
}
} 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
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" );
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" );
}
}
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" );
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" );
}
}
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();
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" );
}
}
+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 );
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" );
}
}
}
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" );
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" );
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" );
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
$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" );
!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" );
}
}
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" );
}
}
$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" );
}
}
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" );
}
}
wfOut( "ok.\n" );
return;
}
-
- global $IP;
- require_once "$IP/maintenance/initStats.inc";
- wfInitStats();
+ SiteStatsInit::doAllAndUpdate( false );
}
function do_active_users_init() {
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();
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..." );
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' ) ) {
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
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(
array("archive", "ar_page_id", "INTEGER"),
array("archive", "ar_parent_id", "INTEGER"),
array("image", "img_sha1", "TEXT NOT NULL DEFAULT ''"),
+ array("ipblocks", "ipb_allow_usertalk", "SMALLINT NOT NULL DEFAULT 0"),
array("ipblocks", "ipb_anon_only", "SMALLINT NOT NULL DEFAULT 0"),
array("ipblocks", "ipb_by_text", "TEXT NOT NULL DEFAULT ''"),
array("ipblocks", "ipb_block_email", "SMALLINT NOT NULL DEFAULT 0"),
array("ipblocks", "ipb_create_account", "SMALLINT NOT NULL DEFAULT 1"),
array("ipblocks", "ipb_deleted", "SMALLINT NOT NULL DEFAULT 0"),
array("ipblocks", "ipb_enable_autoblock", "SMALLINT NOT NULL DEFAULT 1"),
- array("ipblocks", "ipb_allow_usertalk", "SMALLINT NOT NULL DEFAULT 0"),
array("filearchive", "fa_deleted", "SMALLINT NOT NULL DEFAULT 0"),
array("logging", "log_deleted", "SMALLINT NOT NULL DEFAULT 0"),
array("logging", "log_id", "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('log_log_id_seq')"),
array("logging", "log_params", "TEXT"),
array("mwuser", "user_editcount", "INTEGER"),
+ array("mwuser", "user_hidden", "SMALLINT NOT NULL DEFAULT 0"),
array("mwuser", "user_newpass_time", "TIMESTAMPTZ"),
array("oldimage", "oi_deleted", "SMALLINT NOT NULL DEFAULT 0"),
- array("oldimage", "oi_metadata", "BYTEA NOT NULL DEFAULT ''"),
- array("oldimage", "oi_media_type", "TEXT"),
array("oldimage", "oi_major_mime", "TEXT NOT NULL DEFAULT 'unknown'"),
+ array("oldimage", "oi_media_type", "TEXT"),
+ array("oldimage", "oi_metadata", "BYTEA NOT NULL DEFAULT ''"),
array("oldimage", "oi_minor_mime", "TEXT NOT NULL DEFAULT 'unknown'"),
array("oldimage", "oi_sha1", "TEXT NOT NULL DEFAULT ''"),
array("page_restrictions", "pr_id", "INTEGER NOT NULL UNIQUE DEFAULT nextval('pr_id_val')"),
array("recentchanges", "rc_new_len", "INTEGER"),
array("recentchanges", "rc_old_len", "INTEGER"),
array("recentchanges", "rc_params", "TEXT"),
- array("revision", "rev_len", "INTEGER"),
array("revision", "rev_deleted", "SMALLINT NOT NULL DEFAULT 0"),
- array("user_newtalk", "user_last_timestamp", "TIMESTAMPTZ"),
- array("site_stats", "ss_active_users", "INTEGER DEFAULT '-1'"),
+ array("revision", "rev_len", "INTEGER"),
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"),
);
array("ipblocks", "ipb_enable_autoblock", "smallint", "CASE WHEN ipb_enable_autoblock=' ' THEN 0 ELSE ipb_enable_autoblock::smallint END DEFAULT 1"),
array("ipblocks", "ipb_block_email", "smallint", "CASE WHEN ipb_block_email=' ' THEN 0 ELSE ipb_block_email::smallint END DEFAULT 0"),
array("ipblocks", "ipb_address", "text", "ipb_address::text"),
- array("ipblocks", "ipb_deleted", "smallint", "ipb_deleted::smallint"),
+ array("ipblocks", "ipb_deleted", "smallint", "ipb_deleted::smallint DEFAULT 0"),
array("math", "math_inputhash", "bytea", "decode(math_inputhash,'escape')"),
array("math", "math_outputhash", "bytea", "decode(math_outputhash,'escape')"),
array("mwuser", "user_token", "text", ""),
array("user_newtalk", "user_ip", "text", "host(user_ip)"),
);
+ # table, column, nullability
+ $nullchanges = array(
+ array("oldimage", "oi_bits", "NULL"),
+ array("oldimage", "oi_timestamp", "NULL"),
+ array("oldimage", "oi_major_mime", "NULL"),
+ array("oldimage", "oi_minor_mime", "NULL"),
+ );
+
$newindexes = array(
array("archive", "archive_user_text", "(ar_user_text)"),
array("image", "img_sha1", "(img_sha1)"),
array("oldimage", "oi_sha1", "(oi_sha1)"),
array("revision", "rev_text_id_idx", "(rev_text_id)"),
- array("recentchanges", "rc_timestamp_nobot", "(rc_timestamp) WHERE rc_bot = 0"),
+ 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(
}
wfOut( "Creating table \"$nt[0]\"\n" );
- dbsource(archive($nt[1]));
+ $wgDatabase->sourceFile(archive($nt[1]));
}
## Needed before newcols
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" );
}
}
+ foreach ($nullchanges as $nc) {
+ $fi = $wgDatabase->fieldInfo($nc[0], $nc[1]);
+ if (is_null($fi)) {
+ wfOut( "... error: expected column $nc[0].$nc[1] to exist\n" );
+ exit(1);
+ }
+ if ($fi->nullable()) {
+ ## It's NULL - does it need to be NOT NULL?
+ if ('NOT NULL' === $nc[2]) {
+ wfOut( "Changing \"$nc[0].$nc[1]\" to not allow NULLs\n" );
+ $wgDatabase->query( "ALTER TABLE $nc[0] ALTER $nc[1] SET NOT NULL" );
+ }
+ else {
+ wfOut( "... column \"$nc[0].$nc[1]\" is already set as NULL\n" );
+ }
+ }
+ else {
+ ## It's NOT NULL - does it need to be NULL?
+ if ('NULL' === $nc[2]) {
+ wfOut( "Changing \"$nc[0].$nc[1]\" to allow NULLs\n" );
+ $wgDatabase->query( "ALTER TABLE $nc[0] ALTER $nc[1] DROP NOT NULL" );
+ }
+ else {
+ wfOut( "... column \"$nc[0].$nc[1]\" is already set as NOT NULL\n" );
+ }
+ }
+ }
+
if ($wgDatabase->fieldInfo('oldimage','oi_deleted')->type() !== 'smallint') {
wfOut( "Changing \"oldimage.oi_deleted\" to type \"smallint\"\n" );
$wgDatabase->query( "ALTER TABLE oldimage ALTER oi_deleted DROP DEFAULT" );
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 foriegn 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" );
$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" );
}
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
}
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])) {
continue;
}
wfOut( "Creating table \"$nt[0]\"\n" );
- dbsource($nt[1]);
+ $wgDatabase->sourceFile($nt[1]);
}
# Add missing extension fields
foreach ( $wgExtPGNewFields as $nc ) {
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])) {
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',