From 9ee0af7e28b82dfdfc5c4b6f338885e44aabbc17 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 21 Mar 2018 08:13:13 +0400 Subject: Reworked the event handler Signed-off-by: Valentin Popov --- classes/handler.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'classes/handler.php') diff --git a/classes/handler.php b/classes/handler.php index c2c737f..3bc69cf 100644 --- a/classes/handler.php +++ b/classes/handler.php @@ -26,7 +26,6 @@ namespace local_webhooks; defined("MOODLE_INTERNAL") || die(); -require_once(__DIR__ . "/../locallib.php"); require_once(__DIR__ . "/../lib.php"); /** @@ -42,15 +41,15 @@ class handler { * @param object $event */ public static function events($event) { + /* Gets the information about the event */ $data = $event->get_data(); - if (!is_array($recordlist = local_webhooks_cache_get($data["eventname"]))) { - $recordlist = local_webhooks_search_services_by_event($data["eventname"], true); - local_webhooks_cache_set($data["eventname"], $recordlist); - } - - foreach ($recordlist as $record) { - local_webhooks_send_request($data, $record); + /* Gets a list of involved services */ + if (!empty($records = local_webhooks_get_list_records_by_event($data["eventname"]))) { + foreach ($records as $record) { + /* Sends an alert */ + local_webhooks_send_request($data, $record); + } } } } \ No newline at end of file -- cgit v1.2.3