aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 */