diff --git a/override.php b/override.php index 858f1f9..3209c0b 100644 --- a/override.php +++ b/override.php @@ -33,6 +33,7 @@ // Check if an ID is provided $id = optional_param('id', null, PARAM_INT); +$delete = optional_param('delete', null, PARAM_BOOL); // Set the PAGE URL (and mandatory context). Note the ID being recorded, this is important. $PAGE->set_context(context_system::instance()); @@ -40,15 +41,21 @@ // Instantiate a persistent object if we received an ID. Typically receiving an ID // means that we are going to be updating an object rather than creating a new one. -$persistent = null; +$override = null; if (!empty($id)) { - $persistent = new override($id); + $override = new override($id); +} + +// Handle deletion +if (!empty($id) && !empty($delete) && $delete) { + $override->delete(); + redirect(new moodle_url('/admin/tool/heartbeat/status.php')); } // Create the form instance. We need to use the current URL and the custom data. $customdata = [ - 'persistent' => $persistent, + 'persistent' => $override, 'usermodified' => $USER->id // For the hidden userid field. ]; @@ -61,12 +68,12 @@ try { if (empty($data->id)) { // If there is no ID we need to create a new persistent. - $persistent = new Override(0, $data); - $persistent->create(); + $override = new Override(0, $data); + $override->create(); } else { // If we have an ID we need to update the persistent. - $persistent->from_record($data); - $persistent->update(); + $override->from_record($data); + $override->update(); } \core\notification::success(get_string('changessaved')); } catch (Exception $e) {