MDL-64205 privacy: Delete orphaned data request records on upgrade
As a result of the bug, some requests can be orphaned - the linked user record may not exist any more. This is a cleanup of such records.
This commit is contained in:
committed by
David Monllao
parent
32b1faf8b7
commit
c041f919f0
@@ -215,5 +215,19 @@ function xmldb_tool_dataprivacy_upgrade($oldversion) {
|
||||
upgrade_plugin_savepoint(true, 2017051554, 'tool', 'dataprivacy');
|
||||
}
|
||||
|
||||
if ($oldversion < 2017051556) {
|
||||
// Delete orphaned data privacy requests.
|
||||
$sql = "SELECT r.id
|
||||
FROM {tool_dataprivacy_request} r LEFT JOIN {user} u ON r.userid = u.id
|
||||
WHERE u.id IS NULL";
|
||||
$orphaned = $DB->get_fieldset_sql($sql);
|
||||
|
||||
if ($orphaned) {
|
||||
$DB->delete_records_list('tool_dataprivacy_request', 'id', $orphaned);
|
||||
}
|
||||
|
||||
upgrade_plugin_savepoint(true, 2017051556, 'tool', 'dataprivacy');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
$plugin->version = 2017051555;
|
||||
$plugin->version = 2017051556;
|
||||
$plugin->requires = 2017051507.00; // Moodle 3.3.7 (Build: 20180517) and upwards.
|
||||
$plugin->component = 'tool_dataprivacy';
|
||||
|
||||
Reference in New Issue
Block a user