MDL-40223 SCORM: update scorm->launch param after restore - also check that scorm->launch is valid.

This commit is contained in:
Dan Marsden 2013-11-07 14:27:25 +13:00
parent b58bc15af5
commit 27c58e5583
3 changed files with 41 additions and 1 deletions

View File

@ -184,9 +184,27 @@ class restore_scorm_activity_structure_step extends restore_activity_structure_s
}
protected function after_execute() {
global $DB;
// Add scorm related files, no need to match by itemname (just internally handled context)
$this->add_related_files('mod_scorm', 'intro', null);
$this->add_related_files('mod_scorm', 'content', null);
$this->add_related_files('mod_scorm', 'package', null);
// Fix launch param in scorm table to use new sco id.
$scormid = $this->get_new_parentid('scorm');
$scorm = $DB->get_record('scorm', array('id' => $scormid));
$scorm->launch = $this->get_mappingid('scorm_sco', $scorm->launch, '');
if (empty($scorm->launch)) {
// This scorm has an invalid launch param - we need to calculate it and get the first launchable sco.
$sqlselect = 'scorm = ? AND '.$DB->sql_isnotempty('scorm_scoes', 'launch', false, true). ' ORDER BY sortorder LIMIT 1';
$sco = $DB->get_record_select('scorm_scoes', $sqlselect, array($scorm->id));
if (!empty($sco)) {
$scorm->launch = $sco->id;
}
}
if (!empty($scorm->launch)) {
$DB->update_record('scorm', $scorm);
}
}
}

View File

@ -175,6 +175,28 @@ function xmldb_scorm_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2013090100, 'scorm');
}
if ($oldversion < 2013110501) {
// Fix invalid $scorm->launch records.
// Get all scorms that have a launch value that references a sco from a different scorm.
$sql = "SELECT s.*
FROM {scorm} s
LEFT JOIN {scorm_scoes} c ON s.launch = c.id
WHERE c.id IS null OR s.id <> c.scorm";
$scorms = $DB->get_recordset_sql($sql);
foreach ($scorms as $scorm) {
// Find the first launchable sco for this SCORM.
$sqlselect = 'scorm = ? AND '.$DB->sql_isnotempty('scorm_scoes', 'launch', false, true). ' ORDER BY sortorder LIMIT 1';
$sco = $DB->get_record_select('scorm_scoes', $sqlselect, array($scorm->id));
if (!empty($sco)) {
$scorm->launch = $sco->id;
$DB->update_record('scorm', $scorm);
}
}
$scorms->close();
upgrade_mod_savepoint(true, 2013110501, 'scorm');
}
return true;
}

View File

@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
$module->version = 2013110500; // The current module version (Date: YYYYMMDDXX)
$module->version = 2013110501; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2013110500; // Requires this Moodle version
$module->component = 'mod_scorm'; // Full name of the plugin (used for diagnostics)
$module->cron = 300;