From 57a870f56f3505dbb323cb6461286b03b522bacc Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Mon, 12 Mar 2018 23:48:00 +0400 Subject: Update function 'local_webhooks_create_record' Signed-off-by: Valentin Popov --- lib.php | 18 ++++++------------ 1 file 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 */ -- cgit v1.2.3