Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-40223 SCORM: pass limit into function instead of hardcoding to al…

…low cross-db
  • Loading branch information...
commit bf79273a0fa4c9d68b0961f8a2734f1c46466101 1 parent 3c22f80
@danmarsden danmarsden authored
View
8 mod/scorm/backup/moodle2/restore_scorm_stepslib.php
@@ -197,9 +197,11 @@ protected function after_execute() {
$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)) {
+ $sqlselect = 'scorm = ? AND '.$DB->sql_isnotempty('scorm_scoes', 'launch', false, true);
+ // We use get_records here as we need to pass a limit in the query that works cross db.
+ $scoes = $DB->get_records_select('scorm_scoes', $sqlselect, array($scormid), 'id', 'id', 0, 1);
+ if (!empty($scoes)) {
+ $sco = reset($scoes); // We only care about the first record - the above query only returns one.
$scorm->launch = $sco->id;
}
}
View
10 mod/scorm/db/upgrade.php
@@ -108,10 +108,12 @@ function xmldb_scorm_upgrade($oldversion) {
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)) {
+ // 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);
+ // We use get_records here as we need to pass a limit in the query that works cross db.
+ $scoes = $DB->get_records_select('scorm_scoes', $sqlselect, array($scorm->id), 'id', 'id', 0, 1);
+ if (!empty($scoes)) {
+ $sco = reset($scoes); // We only care about the first record - the above query only returns one.
$scorm->launch = $sco->id;
$DB->update_record('scorm', $scorm);
}
Please sign in to comment.
Something went wrong with that request. Please try again.