Merge branch 'master_MDL-67440' of https://github.com/danmarsden/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2020-07-20 17:08:12 +02:00
commit 6c579b60f2

View file

@ -624,9 +624,25 @@ class manager {
LEFT JOIN {context} ctx ON ap.contextid = ctx.id LEFT JOIN {context} ctx ON ap.contextid = ctx.id
WHERE ctx.id IS NULL)"); WHERE ctx.id IS NULL)");
$contextsql = "SELECT id FROM {context} ctx"; // Cleanup analaytics predictions/calcs with MySQL friendly sub-select.
$DB->delete_records_select('analytics_predictions', "contextid NOT IN ($contextsql)"); $DB->execute("DELETE FROM {analytics_predictions} WHERE id IN (
$DB->delete_records_select('analytics_indicator_calc', "contextid NOT IN ($contextsql)"); SELECT oldpredictions.id
FROM (
SELECT p.id
FROM {analytics_predictions} p
LEFT JOIN {context} ctx ON p.contextid = ctx.id
WHERE ctx.id IS NULL
) oldpredictions
)");
$DB->execute("DELETE FROM {analytics_indicator_calc} WHERE id IN (
SELECT oldcalcs.id FROM (
SELECT c.id
FROM {analytics_indicator_calc} c
LEFT JOIN {context} ctx ON c.contextid = ctx.id
WHERE ctx.id IS NULL
) oldcalcs
)");
// Clean up stuff that depends on analysable ids that do not exist anymore. // Clean up stuff that depends on analysable ids that do not exist anymore.