From 3ea8f29329fcbb55d9367173fba1b4abeb927377 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sat, 18 Nov 2017 08:34:23 +0400 Subject: Adding event calls --- editservice.php | 12 +++++++++++- managerservice.php | 15 +++++++++++++++ restorebackup.php | 4 ++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/editservice.php b/editservice.php index 8b065ff..4564909 100644 --- a/editservice.php +++ b/editservice.php @@ -71,9 +71,19 @@ if ($data = $mform->get_data()) { if ($editing) { $data->id = $serviceid; $DB->update_record("local_webhooks_service", $data); + + /* Run the event */ + $event = \local_webhooks\event\service_updated::create(array("context" => $context, "objectid" => $data->id)); + $event->trigger(); + redirect($managerservice, new lang_string("eventwebserviceserviceupdated", "webservice")); } else { - $DB->insert_record("local_webhooks_service", $data); + $servicenewid = $DB->insert_record("local_webhooks_service", $data); + + /* Run the event */ + $event = \local_webhooks\event\service_added::create(array("context" => $context, "objectid" => $servicenewid)); + $event->trigger(); + redirect($managerservice, new lang_string("eventwebserviceservicecreated", "webservice")); } } diff --git a/managerservice.php b/managerservice.php index f75e54e..f15ef21 100644 --- a/managerservice.php +++ b/managerservice.php @@ -49,6 +49,11 @@ $PAGE->set_context($context); /* Delete the service */ if (boolval($deleteid) && confirm_sesskey()) { $DB->delete_records("local_webhooks_service", array("id" => $deleteid)); + + /* Run the event */ + $event = \local_webhooks\event\service_deleted::create(array("context" => $context, "objectid" => $deleteid)); + $event->trigger(); + redirect($PAGE->url, new lang_string("eventwebserviceservicedeleted", "webservice")); } @@ -59,6 +64,11 @@ $callbacks = $DB->get_records_select("local_webhooks_service", null, null, $DB-> if (boolval($backupservices)) { $filecontent = base64_encode(gzcompress(serialize($callbacks), 9)); $filename = "webhooks_" . date("U") . ".backup"; + + /* Run the event */ + $event = \local_webhooks\event\backup_performed::create(array("context" => $context, "objectid" => 0)); + $event->trigger(); + send_file($filecontent, $filename, 0, 0, true, true); } @@ -69,6 +79,11 @@ if (boolval($hideshowid) && confirm_sesskey()) { if (!empty($callback)) { $callback->enable = !boolval($callback->enable); $DB->update_record("local_webhooks_service", $callback); + + /* Run the event */ + $event = \local_webhooks\event\service_updated::create(array("context" => $context, "objectid" => $hideshowid)); + $event->trigger(); + redirect($PAGE->url, new lang_string("eventwebserviceserviceupdated", "webservice")); } } diff --git a/restorebackup.php b/restorebackup.php index be466ef..75a6fb7 100644 --- a/restorebackup.php +++ b/restorebackup.php @@ -56,6 +56,10 @@ if (boolval($data) && confirm_sesskey()) { $DB->insert_record("local_webhooks_service", $callback); } + /* Run the event */ + $event = \local_webhooks\event\backup_restored::create(array("context" => $context, "objectid" => 0)); + $event->trigger(); + redirect($managerservice, new lang_string("restorefinished", "moodle")); } -- cgit v1.2.3