Skip to content

Commit

Permalink
Merge branch 'MDL-66309-m37' of https://github.com/sammarshallou/moodle
Browse files Browse the repository at this point in the history
… into MOODLE_37_STABLE
  • Loading branch information
stronk7 committed Aug 26, 2019
2 parents c4e65af + df8633b commit 4e41fc8
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions blocks/recentlyaccesseditems/db/upgrade.php
Expand Up @@ -50,8 +50,22 @@ function xmldb_block_recentlyaccesseditems_upgrade($oldversion, $block) {
// Automatically generated Moodle v3.7.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2019052001) {
$sql = "courseid NOT IN (SELECT c.id from {course} c) OR cmid NOT IN (SELECT cm.id from {course_modules} cm)";
$DB->delete_records_select("block_recentlyaccesseditems", $sql);
// Query the items to be deleted as a list of IDs. We cannot delete directly from this as a
// subquery because MySQL does not support delete with subqueries.
$fordeletion = $DB->get_fieldset_sql("
SELECT rai.id
FROM {block_recentlyaccesseditems} rai
LEFT JOIN {course} c ON c.id = rai.courseid
LEFT JOIN {course_modules} cm ON cm.id = rai.cmid
WHERE c.id IS NULL OR cm.id IS NULL");

// Delete the array in chunks of 500 (Oracle does not support more than 1000 parameters,
// let's leave some leeway, there are likely only one chunk anyway).
$chunks = array_chunk($fordeletion, 500);
foreach ($chunks as $chunk) {
$DB->delete_records_list('block_recentlyaccesseditems', 'id', $chunk);
}

upgrade_block_savepoint(true, 2019052001, 'recentlyaccesseditems', false);
}

Expand Down

0 comments on commit 4e41fc8

Please sign in to comment.