mnet MDL-17629 upgrade to fix referntial integrity in mnet hostids for localhost and all hosts records

merged from MOODLE_19_STABLE
This commit is contained in:
Penny Leach
2010-01-25 00:59:22 +00:00
parent cc36919f53
commit 7062a798f2
3 changed files with 22 additions and 1 deletions
+4
View File
@@ -2868,6 +2868,10 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
upgrade_main_savepoint($result, 2010011200);
}
if ($result && $oldversion < 2010012500) {
upgrade_fix_incorrect_mnethostids();
upgrade_main_savepoint($result, 2010012500);
}
return $result;
}
+17
View File
@@ -243,6 +243,17 @@ function upgrade_fix_incorrect_mnethostids() {
$current_mnet_localhost_host = $DB->get_record('mnet_host', array('wwwroot' => $CFG->wwwroot)); /// By wwwroot
$current_mnet_all_hosts_host = $DB->get_record_select('mnet_host', $DB->sql_isempty('mnet_host', 'wwwroot', false, false)); /// By empty wwwroot
if (!$moodleapplicationid = $DB->get_field('mnet_application', 'id', array('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 = $DB->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) {
@@ -255,6 +266,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
@@ -284,6 +296,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 = $DB->insert_record('mnet_host', $current_mnet_all_hosts_host, true);
}
@@ -329,6 +342,10 @@ function upgrade_fix_incorrect_mnethostids() {
}
$rs->close();
}
// fix up any host records that have incorrect ids
$DB->set_field_select('mnet_host', 'applicationid', $moodleapplicationid, 'id = ? or id = ?', array($current_mnet_localhost_host->id, $current_mnet_all_hosts_host->id));
}
/**
+1 -1
View File
@@ -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 = 2010011400; // YYYYMMDD = date of the last version bump
$version = 2010012500; // YYYYMMDD = date of the last version bump
// XX = daily increments
$release = '2.0 dev (Build: 20100125)'; // Human-friendly version name