From 70d2f4be3cce27278fa699fcb34a145516d5e1eb Mon Sep 17 00:00:00 2001 From: Penny Leach Date: Mon, 25 Jan 2010 00:59:21 +0000 Subject: [PATCH] mnet MDL-17629 upgrade to fix referntial integrity in mnet hostids for localhost and all hosts records --- lib/db/upgrade.php | 5 +++++ lib/db/upgradelib.php | 18 ++++++++++++++++++ version.php | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 28345c2439f..16105fd74ac 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -3314,6 +3314,11 @@ function xmldb_main_upgrade($oldversion=0) { upgrade_main_savepoint($result, 2007101571.01); } + if ($result && $oldversion < 2007101571.02) { + upgrade_fix_incorrect_mnethostids(); + upgrade_main_savepoint($result, 2007101571.02); + } + return $result; } diff --git a/lib/db/upgradelib.php b/lib/db/upgradelib.php index 6eac2f8f315..969d8b9276b 100644 --- a/lib/db/upgradelib.php +++ b/lib/db/upgradelib.php @@ -607,6 +607,17 @@ function upgrade_fix_incorrect_mnethostids() { $current_mnet_localhost_host = get_record('mnet_host', 'wwwroot', addslashes($CFG->wwwroot)); /// By wwwroot $current_mnet_all_hosts_host = get_record_select('mnet_host', sql_isempty('mnet_host', 'wwwroot', false, false)); /// By empty wwwroot + if (!$moodleapplicationid = get_field('mnet_application', 'id', 'name', 'moodle')) { + $m = (object)array( + 'name' => 'moodle', + 'display_name' => 'Moodle', + 'xmlrpc_server_url' => '/mnet/xmlrpc/server.php', + 'sso_land_url' => '/auth/mnet/land.php', + 'sso_jump_url' => '/auth/mnet/land.php', + ); + $moodleapplicationid = insert_record('mnet_application', $m); + } + /// Create localhost_host if necessary (pretty improbable but better to be 100% in the safe side) /// Code stolen from mnet_environment->init if (!$current_mnet_localhost_host) { @@ -619,6 +630,7 @@ function upgrade_fix_incorrect_mnethostids() { $current_mnet_localhost_host->last_log_id = 0; $current_mnet_localhost_host->deleted = 0; $current_mnet_localhost_host->name = ''; + $current_mnet_localhost_host->applicationid = $moodleapplicationid; /// Get the ip of the server if (empty($_SERVER['SERVER_ADDR'])) { /// SERVER_ADDR is only returned by Apache-like webservers @@ -648,6 +660,7 @@ function upgrade_fix_incorrect_mnethostids() { $current_mnet_all_hosts_host->last_log_id = 0; $current_mnet_all_hosts_host->deleted = 0; $current_mnet_all_hosts_host->name = 'All Hosts'; + $current_mnet_all_hosts_host->applicationid = $moodleapplicationid; $current_mnet_all_hosts_host->id = insert_record('mnet_host', $current_mnet_all_hosts_host, true); } @@ -689,6 +702,11 @@ function upgrade_fix_incorrect_mnethostids() { set_field('user', 'mnethostid', $current_mnet_localhost_host->id, 'id', $rec->id); } rs_close($rs); + + // fix up any host records that have incorrect ids + set_field_select('mnet_host', 'applicationid', $moodleapplicationid, "id = $current_mnet_localhost_host->id or id = $current_mnet_all_hosts_host->id"); + + } ?> diff --git a/version.php b/version.php index af14fdd9622..b29e80b2a27 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2007101571.01; // YYYYMMDD = date of the 1.9 branch (don't change) + $version = 2007101571.02; // YYYYMMDD = date of the 1.9 branch (don't change) // X = release number 1.9.[0,1,2,3,4,5...] // Y.YY = micro-increments between releases