From 05512c5440ff6d2bbb31e6e5d886c83e8510f15d Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 23 Nov 2017 19:18:32 +0400 Subject: Repeated refactoring of the event handler --- classes/handler.php | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) (limited to 'classes/handler.php') diff --git a/classes/handler.php b/classes/handler.php index 4e102af..cb32112 100644 --- a/classes/handler.php +++ b/classes/handler.php @@ -26,6 +26,8 @@ namespace local_webhooks; defined("MOODLE_INTERNAL") || die(); +require_once(__DIR__ . "/../lib.php"); + require_once($CFG->libdir . "/filelib.php"); /** @@ -42,16 +44,6 @@ class handler { */ public static function events($event) { $data = $event->get_data(); - self::transmitter($data); - } - - /** - * Transmitter, processing event and services. - * - * @param array $data - */ - private static function transmitter($data) { - global $DB; if ($callbacks = local_webhooks_get_list_records()) { foreach ($callbacks as $callback) { @@ -70,17 +62,12 @@ class handler { global $CFG; if (boolval($callback->enable)) { - if (!empty($events[$data["eventname"]])) { - $urlparse = parse_url($CFG->wwwroot); - $data["host"] = $urlparse['host']; - - if (!empty($callback->token)) { - $data["token"] = $callback->token; - } + if (!empty($data["eventname"])) { + $urlparse = parse_url($CFG->wwwroot); - if (!empty($callback->other)) { - $data["extra"] = $callback->other; - } + $data["host"] = $urlparse['host']; + $data["token"] = $callback->token; + $data["extra"] = $callback->other; self::send($data, $callback); } @@ -95,7 +82,7 @@ class handler { */ private static function send($data, $callback) { $curl = new \curl(); - $curl->setHeader(array("Content-Type: application/$callback->type")); + $curl->setHeader(array("Content-Type: application/" . $callback->type)); $curl->post($callback->url, json_encode($data)); $response = $curl->getResponse(); -- cgit v1.2.3