Merge branch 'MDL-77224-401' of https://github.com/paulholden/moodle into MOODLE_401_STABLE

This commit is contained in:
Andrew Nicols 2023-06-15 12:02:40 +08:00
commit 4997295c38
No known key found for this signature in database
GPG Key ID: 6D1E3157C8CFBF14
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;