From c87a50cb45e121110090a95c00e504e05dfda54c Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Wed, 26 Mar 2014 21:35:18 +1300 Subject: [PATCH] MDL-44753 SCORM: add check during SCORM restore to make sure valid launch sco is set --- .../backup/moodle2/restore_scorm_stepslib.php | 10 ++++ mod/scorm/db/upgrade.php | 50 +++++++++---------- mod/scorm/version.php | 2 +- 3 files changed, 36 insertions(+), 26 deletions(-) diff --git a/mod/scorm/backup/moodle2/restore_scorm_stepslib.php b/mod/scorm/backup/moodle2/restore_scorm_stepslib.php index 44c5676ef37..46780371f1f 100644 --- a/mod/scorm/backup/moodle2/restore_scorm_stepslib.php +++ b/mod/scorm/backup/moodle2/restore_scorm_stepslib.php @@ -199,6 +199,16 @@ class restore_scorm_activity_structure_step extends restore_activity_structure_s $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)) { + // Check that this sco has a valid launch value. + $scolaunch = $DB->get_field('scorm_scoes', 'launch', array('id' => $scorm->launch)); + if (empty($scolaunch)) { + // This is not a valid sco - set to empty so we can find a valid launch 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); diff --git a/mod/scorm/db/upgrade.php b/mod/scorm/db/upgrade.php index b7dd657ba1f..aff8f2e6fbd 100644 --- a/mod/scorm/db/upgrade.php +++ b/mod/scorm/db/upgrade.php @@ -202,7 +202,30 @@ function xmldb_scorm_upgrade($oldversion) { upgrade_mod_savepoint(true, 2013110501, 'scorm'); } - if ($oldversion < 2014021700) { + if ($oldversion < 2014031700) { + // Define field displayactivityname to be added to scorm. + $table = new xmldb_table('scorm'); + $field = new xmldb_field( + 'displayactivityname', + XMLDB_TYPE_INTEGER, + '4', + null, + XMLDB_NOTNULL, + null, + '1', + 'completionscorerequired' + ); + + // Conditionally launch add field displayactivityname. + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Scorm savepoint reached. + upgrade_mod_savepoint(true, 2014031700, 'scorm'); + } + + if ($oldversion < 2014040200) { // Fix invalid $scorm->launch records that launch an org sco instead of a real sco. $sql = "SELECT s.*, c.identifier FROM {scorm} s @@ -249,30 +272,7 @@ function xmldb_scorm_upgrade($oldversion) { } $scorms->close(); - upgrade_mod_savepoint(true, 2014021700, 'scorm'); - } - - if ($oldversion < 2014031700) { - // Define field displayactivityname to be added to scorm. - $table = new xmldb_table('scorm'); - $field = new xmldb_field( - 'displayactivityname', - XMLDB_TYPE_INTEGER, - '4', - null, - XMLDB_NOTNULL, - null, - '1', - 'completionscorerequired' - ); - - // Conditionally launch add field displayactivityname. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Scorm savepoint reached. - upgrade_mod_savepoint(true, 2014031700, 'scorm'); + upgrade_mod_savepoint(true, 2014040200, 'scorm'); } return true; diff --git a/mod/scorm/version.php b/mod/scorm/version.php index 59e0d62e462..2e497ef69ff 100644 --- a/mod/scorm/version.php +++ b/mod/scorm/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2014032600; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2014040200; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2013110500; // Requires this Moodle version. $plugin->component = 'mod_scorm'; // Full name of the plugin (used for diagnostics). $plugin->cron = 300;