summaryrefslogtreecommitdiff
path: root/classes/handler.php
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2017-11-23 17:54:31 +0300
committerValentin Popov <info@valentineus.link>2017-11-23 17:54:31 +0300
commitf8b85a270cdcdbb6bc12287cef554147b8b5be82 (patch)
tree14b3899de629a955d7288100d71faf8a43f0ba51 /classes/handler.php
parent4bf6f61131af5a3b7847e5e0491eb218120faba2 (diff)
downloadlocal_webhooks-f8b85a270cdcdbb6bc12287cef554147b8b5be82.tar.xz
local_webhooks-f8b85a270cdcdbb6bc12287cef554147b8b5be82.zip
Refactoring the code of the event handler
Diffstat (limited to 'classes/handler.php')
-rw-r--r--classes/handler.php40
1 files changed, 3 insertions, 37 deletions
diff --git a/classes/handler.php b/classes/handler.php
index 6f9c63a..4e102af 100644
--- a/classes/handler.php
+++ b/classes/handler.php
@@ -53,15 +53,11 @@ class handler {
private static function transmitter($data) {
global $DB;
- $callbacks = $DB->get_recordset("local_webhooks_service");
-
- if ($callbacks->valid()) {
+ if ($callbacks = local_webhooks_get_list_records()) {
foreach ($callbacks as $callback) {
self::handler_callback($data, $callback);
}
}
-
- $callbacks->close();
}
/**
@@ -74,13 +70,8 @@ class handler {
global $CFG;
if (boolval($callback->enable)) {
- $events = array();
- if (!empty($callback->events)) {
- $events = unserialize(gzuncompress(base64_decode($callback->events)));
- }
-
if (!empty($events[$data["eventname"]])) {
- $urlparse = parse_url($CFG->wwwroot);
+ $urlparse = parse_url($CFG->wwwroot);
$data["host"] = $urlparse['host'];
if (!empty($callback->token)) {
@@ -106,33 +97,8 @@ class handler {
$curl = new \curl();
$curl->setHeader(array("Content-Type: application/$callback->type"));
$curl->post($callback->url, json_encode($data));
+
$response = $curl->getResponse();
- self::logger($callback, $response);
return $response;
}
-
- /**
- * Event logging.
- *
- * @param array $response
- * @param object $callback
- */
- private static function logger($callback, $response) {
- $status = "Error sending request";
- if (!empty($response["HTTP/1.1"])) {
- $status = $response["HTTP/1.1"];
- }
-
- $event = \local_webhooks\event\response_answer::create(
- array(
- "context" => \context_system::instance(0),
- "objectid" => $callback->id,
- "other" => array(
- "status" => $status
- )
- )
- );
-
- $event->trigger();
- }
} \ No newline at end of file