summaryrefslogtreecommitdiff
path: root/lib.php
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2018-02-19 11:36:09 +0300
committerValentin Popov <info@valentineus.link>2018-02-19 11:36:09 +0300
commit66b5928e6edbdffc2039682c64a01aedfa717091 (patch)
tree3747a6b41873cf8a8f0d62e431a7c12c7b836b84 /lib.php
parent4f75d9c5c8b927f2c0d125b47ab86bde74275a89 (diff)
downloadlocal_webhooks-66b5928e6edbdffc2039682c64a01aedfa717091.tar.xz
local_webhooks-66b5928e6edbdffc2039682c64a01aedfa717091.zip
Added clearing the cache when changing data
Diffstat (limited to 'lib.php')
-rw-r--r--lib.php36
1 files changed, 34 insertions, 2 deletions
diff --git a/lib.php b/lib.php
index e3f034e..422c108 100644
--- a/lib.php
+++ b/lib.php
@@ -52,7 +52,7 @@ function local_webhooks_change_status($serviceid) {
*/
function local_webhooks_search_services_by_event($eventname) {
$recordlist = local_webhooks_get_list_records();
- $result = array();
+ $result = array();
foreach ($recordlist as $record) {
if (boolval($record->enable) && !empty($record->events[$eventname])) {
@@ -126,7 +126,13 @@ function local_webhooks_create_record($record) {
}
$result = $DB->insert_record("local_webhooks_service", $record, true, false);
+
+ /* Clear the plugin cache */
+ local_webhooks_cache_delete_all();
+
+ /* Event notification */
local_webhooks_events::service_added($result);
+
return $result;
}
@@ -145,7 +151,13 @@ function local_webhooks_update_record($record) {
$record->events = !empty($record->events) ? local_webhooks_serialization_data($record->events) : null;
$result = $DB->update_record("local_webhooks_service", $record, false);
+
+ /* Clear the plugin cache */
+ local_webhooks_cache_delete_all();
+
+ /* Event notification */
local_webhooks_events::service_updated($record->id);
+
return boolval($result);
}
@@ -157,8 +169,15 @@ function local_webhooks_update_record($record) {
*/
function local_webhooks_delete_record($serviceid) {
global $DB;
+
$result = $DB->delete_records("local_webhooks_service", array("id" => $serviceid));
+
+ /* Clear the plugin cache */
+ local_webhooks_cache_delete_all();
+
+ /* Event notification */
local_webhooks_events::service_deleted($serviceid);
+
return boolval($result);
}
@@ -169,8 +188,15 @@ function local_webhooks_delete_record($serviceid) {
*/
function local_webhooks_delete_all_records() {
global $DB;
+
$result = $DB->delete_records("local_webhooks_service", null);
+
+ /* Clear the plugin cache */
+ local_webhooks_cache_delete_all();
+
+ /* Event notification */
local_webhooks_events::service_deletedall();
+
return boolval($result);
}
@@ -182,7 +208,10 @@ function local_webhooks_delete_all_records() {
function local_webhooks_create_backup() {
$listrecords = local_webhooks_get_list_records();
$result = local_webhooks_serialization_data($listrecords);
+
+ /* Event notification */
local_webhooks_events::backup_performed();
+
return $result;
}
@@ -202,6 +231,7 @@ function local_webhooks_restore_backup($data, $deleterecords = false) {
local_webhooks_create_record($servicerecord);
}
+ /* Event notification */
local_webhooks_events::backup_restored();
}
@@ -222,9 +252,11 @@ function local_webhooks_send_request($event, $callback) {
$curl = new curl();
$curl->setHeader(array("Content-Type: application/" . $callback->type));
$curl->post($callback->url, json_encode($event));
-
$response = $curl->getResponse();
+
+ /* Event notification */
local_webhooks_events::response_answer($callback->id, $response);
+
return $response;
}