Skip to content

Commit

Permalink
Deleted the "format_designer_options" table records using Moodle events.
Browse files Browse the repository at this point in the history
  • Loading branch information
vasanthlmsace committed Jul 31, 2024
1 parent a325df7 commit ac76780
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
26 changes: 26 additions & 0 deletions classes/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,30 @@ public static function course_section_created($event) {
$format->update_section_format_options($sectiondata);
}
}


/**
* After course module deleted, deleted the format_designer_options data related to the format_designer options.
*
* @param object $event
* @return void
*/
public static function course_module_deleted($event) {
global $DB;
$courseid = $event->courseid;
$cmid = $event->objectid;
$DB->delete_records('format_designer_options', ['courseid' => $courseid, 'cmid' => $cmid]);
}

/**
* After course deleted, deleted the format_designer_options data related to the format_designer options.
*
* @param object $event
* @return void
*/
public static function course_deleted($event) {
global $DB;
$courseid = $event->courseid;
$DB->delete_records('format_designer_options', ['courseid' => $courseid]);
}
}
8 changes: 8 additions & 0 deletions db/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@
'eventname' => 'core\event\course_section_created',
'callback' => '\format_designer\events::course_section_created',
],
[
'eventname' => 'core\event\course_module_deleted',
'callback' => '\format_designer\events::course_module_deleted',
],
[
'eventname' => 'core\event\course_deleted',
'callback' => '\format_designer\events::course_deleted',
],
];
12 changes: 12 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,17 @@ function xmldb_format_designer_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2023040601, 'format', 'designer');
}


if ($oldversion < 2024073000) {
$deletesql = <<<EOF
SELECT fdo.id AS optionid
FROM {format_designer_options} fdo
LEFT JOIN {course_modules} cm ON cm.id = fdo.cmid
WHERE cm.id IS NULL
EOF;
$DB->delete_records_subquery('format_designer_options', 'id', 'optionid', $deletesql);
upgrade_plugin_savepoint(true, 2024073000, 'format', 'designer');
}

return true;
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2024061900; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2024073100; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2020061500; // Requires this Moodle version.
$plugin->component = 'format_designer'; // Full name of the plugin (used for diagnostics).
$plugin->release = 'Version 1.5';
Expand Down

0 comments on commit ac76780

Please sign in to comment.