aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--index.php2
-rw-r--r--lib.php26
-rw-r--r--restorebackup.php10
3 files changed, 29 insertions, 9 deletions
diff --git a/index.php b/index.php
index 8fb92f2..318520a 100644
--- a/index.php
+++ b/index.php
@@ -54,7 +54,7 @@ $callbacks = local_webhooks_get_list_records();
/* Upload settings as a file */
if (boolval($backupservices)) {
- $filecontent = local_webhooks_archiving_data($callbacks);
+ $filecontent = local_webhooks_create_backup();
$filename = "webhooks_" . date("U") . ".backup";
send_file($filecontent, $filename, 0, 0, true, true);
}
diff --git a/lib.php b/lib.php
index ab20526..c423e9b 100644
--- a/lib.php
+++ b/lib.php
@@ -109,6 +109,32 @@ function local_webhooks_update_record($data, $insert = true) {
}
/**
+ * Make a backup copy of all the services.
+ *
+ * @return string
+ */
+function local_webhooks_create_backup() {
+ $listservices = local_webhooks_get_list_records();
+ $listservices = local_webhooks_archiving_data($listservices);
+ return $listservices;
+}
+
+/**
+ * Restore the data from the backup.
+ *
+ * @param string $data
+ */
+function local_webhooks_restore_backup($listservices = "") {
+ $listservices = local_webhooks_unarchive_data($listservices);
+
+ local_webhooks_remove_list_records();
+
+ foreach ($listservices as $servicerecord) {
+ local_webhooks_update_record($servicerecord, true);
+ }
+}
+
+/**
* Compress an array into a string.
*
* @param array $data
diff --git a/restorebackup.php b/restorebackup.php
index b4cfce0..011de03 100644
--- a/restorebackup.php
+++ b/restorebackup.php
@@ -46,14 +46,8 @@ if ($mform->is_cancelled()) {
/* Processing the received file */
if ($data = $mform->get_data()) {
- $content = $mform->get_file_content("backupfile");
- $callbacks = local_webhooks_unarchive_data($content);
-
- local_webhooks_remove_list_records();
- foreach ($callbacks as $callback) {
- local_webhooks_update_record($callback, true);
- }
-
+ $content = $mform->get_file_content("backupfile");
+ local_webhooks_restore_backup($content);
redirect($managerservice, new lang_string("restorefinished", "moodle"));
}