MDL-77224 mod_h5pactivity: clean up attempt data on activity deletion.

This commit is contained in:
Paul Holden 2023-03-16 20:24:52 +00:00
parent 76fe404dd5
commit d9c8e2561e
No known key found for this signature in database
GPG Key ID: A81A96D6045F6164
3 changed files with 23 additions and 1 deletions

View File

@ -249,5 +249,20 @@ function xmldb_h5pactivity_upgrade($oldversion) {
// Automatically generated Moodle v4.1.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2022112801) {
// Remove any orphaned attempt/result records (pointing to non-existing activities).
$DB->delete_records_select('h5pactivity_attempts', 'NOT EXISTS (
SELECT 1 FROM {h5pactivity} h5p WHERE h5p.id = {h5pactivity_attempts}.h5pactivityid
)');
$DB->delete_records_select('h5pactivity_attempts_results', 'NOT EXISTS (
SELECT 1 FROM {h5pactivity_attempts} attempt WHERE attempt.id = {h5pactivity_attempts_results}.attemptid
)');
// H5pactivity savepoint reached.
upgrade_mod_savepoint(true, 2022112801, 'h5pactivity');
}
return true;
}

View File

@ -145,6 +145,13 @@ function h5pactivity_delete_instance(int $id): bool {
return false;
}
// Remove activity record, and all associated attempt data.
$attemptids = $DB->get_fieldset_select('h5pactivity_attempts', 'id', 'h5pactivityid = ?', [$id]);
if ($attemptids) {
$DB->delete_records_list('h5pactivity_attempts_results', 'attemptid', $attemptids);
$DB->delete_records_list('h5pactivity_attempts', 'id', $attemptids);
}
$DB->delete_records('h5pactivity', ['id' => $id]);
h5pactivity_grade_item_delete($activity);

View File

@ -25,5 +25,5 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'mod_h5pactivity';
$plugin->version = 2022112800;
$plugin->version = 2022112801;
$plugin->requires = 2022111800;