Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-40223 SCORM: update scorm->launch param after restore - also chec…

…k that scorm->launch is valid.
  • Loading branch information...
commit 3c22f80a989432ee86d3f638a827e171eb1cc462 1 parent b3f2d75
@danmarsden danmarsden authored
View
18 mod/scorm/backup/moodle2/restore_scorm_stepslib.php
@@ -184,9 +184,27 @@ protected function process_scorm_sco_track($data) {
}
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 id 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
22 mod/scorm/db/upgrade.php
@@ -99,6 +99,28 @@ function xmldb_scorm_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2013050101, 'scorm');
}
+ if ($oldversion < 2013050102) {
+ // 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 id 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, 2013050102, 'scorm');
+ }
+
return true;
}
View
2  mod/scorm/version.php
@@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
-$module->version = 2013050101; // The current module version (Date: YYYYMMDDXX)
+$module->version = 2013050102; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2013050100; // Requires this Moodle version
$module->component = 'mod_scorm'; // Full name of the plugin (used for diagnostics)
$module->cron = 300;
Please sign in to comment.
Something went wrong with that request. Please try again.