aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2018-03-12 22:48:00 +0300
committerValentin Popov <info@valentineus.link>2018-03-12 22:48:00 +0300
commit57a870f56f3505dbb323cb6461286b03b522bacc (patch)
tree1f2a8d43051206267bf2fdbd559bb0c1938dcd55
parent639276c33d42ee72fe71278cc7209231c31a060a (diff)
downloadlocal_webhooks-57a870f56f3505dbb323cb6461286b03b522bacc.tar.xz
local_webhooks-57a870f56f3505dbb323cb6461286b03b522bacc.zip
Update function 'local_webhooks_create_record'
Signed-off-by: Valentin Popov <info@valentineus.link>
-rw-r--r--lib.php18
1 files changed, 6 insertions, 12 deletions
diff --git a/lib.php b/lib.php
index af8fba5..8a248e9 100644
--- a/lib.php
+++ b/lib.php
@@ -144,20 +144,14 @@ function local_webhooks_get_total_count() {
function local_webhooks_create_record($record) {
global $DB;
- $transaction = $DB->start_delegated_transaction();
- $serviceid = $DB->insert_record(LOCAL_WEBHOOKS_TABLE_SERVICES, $record, true, false);
-
- if (!empty($record->events)) {
- foreach ($record->events as $eventname => $eventstatus) {
- $event = new stdClass();
- $event->name = $eventname;
- $event->serviceid = $serviceid;
- $event->status = $record->status;
-
- $DB->insert_record(LOCAL_WEBHOOKS_TABLE_EVENTS, $event, false, false);
- }
+ if (empty($record->events)) {
+ $record->events = array();
}
+ /* Adding entries */
+ $transaction = $DB->start_delegated_transaction();
+ $serviceid = $DB->insert_record(LOCAL_WEBHOOKS_TABLE_SERVICES, $record, true, false);
+ local_webhooks_insert_events($serviceid, $record->events);
$transaction->allow_commit();
/* Clear the plugin cache */