From 490b8bb170e800599889d57bc9398a2906d93f28 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Tue, 13 Mar 2018 01:43:23 +0400 Subject: Update function 'local_webhooks_restore_backup' Signed-off-by: Valentin Popov --- lib.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'lib.php') diff --git a/lib.php b/lib.php index f229612..85372f9 100644 --- a/lib.php +++ b/lib.php @@ -147,7 +147,7 @@ function local_webhooks_create_record($record) { local_webhooks_cache_reset(); /* Event notification */ - local_webhooks_events::service_added($result); + local_webhooks_events::service_added($serviceid); return $serviceid; } @@ -247,22 +247,27 @@ function local_webhooks_create_backup() { /** * Restore from a backup. * - * @param string $data - * @param boolean $deleterecords + * @param string $data */ -function local_webhooks_restore_backup($data, $deleterecords = false) { - $listrecords = local_webhooks_deserialization_data($data); +function local_webhooks_restore_backup($backup) { + global $DB; - if (boolval($deleterecords)) { - local_webhooks_delete_all_records(); - } + $serialize = gzuncompress(base64_decode($backup)); + $records = unserialize($serialize); + + $transaction = $DB->start_delegated_transaction(); + local_webhooks_delete_all_records(); - foreach ($listrecords as $servicerecord) { - local_webhooks_create_record($servicerecord); + foreach ($records as $record) { + local_webhooks_create_record($record); } + $transaction->allow_commit(); + /* Event notification */ local_webhooks_events::backup_restored(); + + return true; } /** -- cgit v1.2.3