Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-34233 SCORM backup - change to using set_source_sql to preserve o…

…rder of records in backup.
  • Loading branch information...
commit 001ff67298b6b8e7b76c4d7081c35d9df38f3cd8 1 parent 9592f5d
Dan Marsden authored
79  mod/scorm/backup/moodle2/backup_scorm_stepslib.php
@@ -127,25 +127,72 @@ protected function define_structure() {
127 127
         // Define sources
128 128
         $scorm->set_source_table('scorm', array('id' => backup::VAR_ACTIVITYID));
129 129
 
130  
-        $sco->set_source_table('scorm_scoes', array('scorm' => backup::VAR_PARENTID));
131  
-
132  
-        $scodata->set_source_table('scorm_scoes_data', array('scoid' => backup::VAR_PARENTID));
133  
-
134  
-        $seqrulecond->set_source_table('scorm_seq_ruleconds', array('scoid' => backup::VAR_PARENTID));
135  
-
136  
-        $seqrulecondsdata->set_source_table('scorm_seq_rulecond', array('ruleconditionsid' => backup::VAR_PARENTID));
137  
-
138  
-        $seqrolluprule->set_source_table('scorm_seq_rolluprule', array('scoid' => backup::VAR_PARENTID));
139  
-
140  
-        $seqrolluprulecond->set_source_table('scorm_seq_rolluprulecond', array('rollupruleid' => backup::VAR_PARENTID));
141  
-
142  
-        $seqobjective->set_source_table('scorm_seq_objective', array('scoid' => backup::VAR_PARENTID));
143  
-
144  
-        $seqmapinfo->set_source_table('scorm_seq_mapinfo', array('objectiveid' => backup::VAR_PARENTID));
  130
+        // Use set_source_sql for other calls as set_source_table returns records in reverse order
  131
+        // and order is important for several SCORM fields - esp scorm_scoes.
  132
+        $sco->set_source_sql('
  133
+                SELECT *
  134
+                FROM {scorm_scoes}
  135
+                WHERE scorm = :scorm
  136
+                ORDER BY id',
  137
+            array('scorm' => backup::VAR_PARENTID));
  138
+
  139
+        $scodata->set_source_sql('
  140
+                SELECT *
  141
+                FROM {scorm_scoes_data}
  142
+                WHERE scoid = :scoid
  143
+                ORDER BY id',
  144
+            array('scoid' => backup::VAR_PARENTID));
  145
+
  146
+        $seqrulecond->set_source_sql('
  147
+                SELECT *
  148
+                FROM {scorm_seq_ruleconds}
  149
+                WHERE scoid = :scoid
  150
+                ORDER BY id',
  151
+            array('scoid' => backup::VAR_PARENTID));
  152
+
  153
+        $seqrulecondsdata->set_source_sql('
  154
+                SELECT *
  155
+                FROM {scorm_seq_rulecond}
  156
+                WHERE ruleconditionsid = :ruleconditionsid
  157
+                ORDER BY id',
  158
+            array('ruleconditionsid' => backup::VAR_PARENTID));
  159
+
  160
+        $seqrolluprule->set_source_sql('
  161
+                SELECT *
  162
+                FROM {scorm_seq_rolluprule}
  163
+                WHERE scoid = :scoid
  164
+                ORDER BY id',
  165
+            array('scoid' => backup::VAR_PARENTID));
  166
+
  167
+        $seqrolluprulecond->set_source_sql('
  168
+                SELECT *
  169
+                FROM {scorm_seq_rolluprulecond}
  170
+                WHERE rollupruleid = :rollupruleid
  171
+                ORDER BY id',
  172
+            array('rollupruleid' => backup::VAR_PARENTID));
  173
+
  174
+        $seqobjective->set_source_sql('
  175
+                SELECT *
  176
+                FROM {scorm_seq_objective}
  177
+                WHERE scoid = :scoid
  178
+                ORDER BY id',
  179
+            array('scoid' => backup::VAR_PARENTID));
  180
+
  181
+        $seqmapinfo->set_source_sql('
  182
+                SELECT *
  183
+                FROM {scorm_seq_mapinfo}
  184
+                WHERE objectiveid = :objectiveid
  185
+                ORDER BY id',
  186
+            array('objectiveid' => backup::VAR_PARENTID));
145 187
 
146 188
         // All the rest of elements only happen if we are including user info
147 189
         if ($userinfo) {
148  
-            $scotrack->set_source_table('scorm_scoes_track', array('scoid' => backup::VAR_PARENTID));
  190
+            $scotrack->set_source_sql('
  191
+                SELECT *
  192
+                FROM {scorm_scoes_track}
  193
+                WHERE scoid = :scoid
  194
+                ORDER BY id',
  195
+                array('scoid' => backup::VAR_PARENTID));
149 196
         }
150 197
 
151 198
         // Define id annotations

0 notes on commit 001ff67

Please sign in to comment.
Something went wrong with that request. Please try again.