Update function 'local_webhooks_create_record'

Signed-off-by: Valentin Popov <info@valentineus.link>
This commit is contained in:
Valentin Popov 2018-03-12 23:48:00 +04:00
parent 639276c33d
commit 57a870f56f
Signed by: Valentin Popov
GPG Key ID: 269A00ACA90A8EA3

18
lib.php
View File

@ -144,20 +144,14 @@ function local_webhooks_get_total_count() {
function local_webhooks_create_record($record) { function local_webhooks_create_record($record) {
global $DB; global $DB;
$transaction = $DB->start_delegated_transaction(); if (empty($record->events)) {
$serviceid = $DB->insert_record(LOCAL_WEBHOOKS_TABLE_SERVICES, $record, true, false); $record->events = array();
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);
}
} }
/* 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(); $transaction->allow_commit();
/* Clear the plugin cache */ /* Clear the plugin cache */