mnet MDL-17629 upgrade to fix referntial integrity in mnet hostids for localhost and all hosts records
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user