aboutsummaryrefslogtreecommitdiff
path: root/lib.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib.php')
-rw-r--r--lib.php25
1 files changed, 15 insertions, 10 deletions
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;
}
/**