aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2018-03-13 00:43:23 +0300
committerValentin Popov <info@valentineus.link>2018-03-13 00:43:23 +0300
commit490b8bb170e800599889d57bc9398a2906d93f28 (patch)
treeea6a1e8700289ab46f0f08e628b6c22d90495a21
parent95c54f82627424667af7a4a8af014baeffafa073 (diff)
downloadlocal_webhooks-490b8bb170e800599889d57bc9398a2906d93f28.tar.xz
local_webhooks-490b8bb170e800599889d57bc9398a2906d93f28.zip
Update function 'local_webhooks_restore_backup'
Signed-off-by: Valentin Popov <info@valentineus.link>
-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;
}
/**