diff options
author | Valentin Popov <info@valentineus.link> | 2018-03-13 00:43:23 +0300 |
---|---|---|
committer | Valentin Popov <info@valentineus.link> | 2018-03-13 00:43:23 +0300 |
commit | 490b8bb170e800599889d57bc9398a2906d93f28 (patch) | |
tree | ea6a1e8700289ab46f0f08e628b6c22d90495a21 | |
parent | 95c54f82627424667af7a4a8af014baeffafa073 (diff) | |
download | local_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.php | 25 |
1 files changed, 15 insertions, 10 deletions
@@ -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; } /** |