MDL-44753 SCORM: add check during SCORM restore to make sure valid launch sco is set
authorDan Marsden <dan@danmarsden.com>
Wed, 26 Mar 2014 08:35:18 +0000 (21:35 +1300)
committerDan Marsden <dan@danmarsden.com>
Tue, 1 Apr 2014 21:01:54 +0000 (10:01 +1300)
mod/scorm/backup/moodle2/restore_scorm_stepslib.php
mod/scorm/db/upgrade.php
mod/scorm/version.php

index 44c5676..4678037 100644 (file)
@@ -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);
index b7dd657..aff8f2e 100644 (file)
@@ -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;
index 59e0d62..2e497ef 100644 (file)
@@ -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;