MDL-40223 SCORM: pass limit into function instead of hardcoding to allow cross-db

This commit is contained in:
Dan Marsden 2013-11-19 13:20:34 +13:00
parent 27c58e5583
commit eef4c4c175
2 changed files with 11 additions and 6 deletions

View File

@ -197,9 +197,11 @@ class restore_scorm_activity_structure_step extends restore_activity_structure_s
$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 sortorder 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), 'sortorder', '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 File

@ -185,9 +185,12 @@ function xmldb_scorm_upgrade($oldversion) {
$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 sortorder 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), 'sortorder', '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);
}