aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2018-02-18 21:05:58 +0300
committerValentin Popov <info@valentineus.link>2018-02-18 21:05:58 +0300
commit4f75d9c5c8b927f2c0d125b47ab86bde74275a89 (patch)
tree926a3c8963fc1bd108885982fe335642794c6465
parent29bdbc745614b8ac19259229a028efa03d8d4ddb (diff)
downloadlocal_webhooks-4f75d9c5c8b927f2c0d125b47ab86bde74275a89.tar.xz
local_webhooks-4f75d9c5c8b927f2c0d125b47ab86bde74275a89.zip
Event handler is rewritten to work with the cache
-rw-r--r--classes/handler.php14
1 files changed, 8 insertions, 6 deletions
diff --git a/classes/handler.php b/classes/handler.php
index 3349f9f..eb0905f 100644
--- a/classes/handler.php
+++ b/classes/handler.php
@@ -26,6 +26,7 @@ namespace local_webhooks;
defined("MOODLE_INTERNAL") || die();
+require_once(__DIR__ . "/../locallib.php");
require_once(__DIR__ . "/../lib.php");
/**
@@ -43,12 +44,13 @@ class handler {
public static function events($event) {
$data = $event->get_data();
- if ($callbacks = local_webhooks_get_list_records()) {
- foreach ($callbacks as $callback) {
- if (boolval($callback->enable) && !empty($callback->events[$data["eventname"]])) {
- local_webhooks_send_request($data, $callback);
- }
- }
+ if (!is_array($recordlist = local_webhooks_cache_get($data["eventname"]))) {
+ $recordlist = local_webhooks_search_services_by_event($data["eventname"]);
+ local_webhooks_cache_set($data["eventname"], $recordlist);
+ }
+
+ foreach ($recordlist as $record) {
+ local_webhooks_send_request($data, $record);
}
}
} \ No newline at end of file