Skip to content

Commit

Permalink
MDL-40223 SCORM: update scorm->launch param after restore - also chec…
Browse files Browse the repository at this point in the history
…k that scorm->launch is valid.
  • Loading branch information
danmarsden committed Nov 17, 2013
1 parent 9f887be commit e0a4008
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
18 changes: 18 additions & 0 deletions mod/scorm/backup/moodle2/restore_scorm_stepslib.php
Expand Up @@ -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);
}
}
}
22 changes: 22 additions & 0 deletions mod/scorm/db/upgrade.php
Expand Up @@ -96,6 +96,28 @@ function xmldb_scorm_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2012112901, 'scorm');
}

if ($oldversion < 2012112902) {
// 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, 2012112902, 'scorm');
}

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion mod/scorm/version.php
Expand Up @@ -25,7 +25,7 @@

defined('MOODLE_INTERNAL') || die();

$module->version = 2012112901; // The current module version (Date: YYYYMMDDXX)
$module->version = 2012112902; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2012112900; // Requires this Moodle version
$module->component = 'mod_scorm'; // Full name of the plugin (used for diagnostics)
$module->cron = 300;

0 comments on commit e0a4008

Please sign in to comment.