aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2017-11-23 17:09:56 +0300
committerValentin Popov <info@valentineus.link>2017-11-23 17:09:56 +0300
commit0bc809ba07e16c8d043edb58dde95d5dfaed32d7 (patch)
treec6bed9551ee745ddaf6c6a657674ef9f7454d019
parent03d22ef096c57e462e81fac078ffd463302a256e (diff)
downloadlocal_webhooks-0bc809ba07e16c8d043edb58dde95d5dfaed32d7.tar.xz
local_webhooks-0bc809ba07e16c8d043edb58dde95d5dfaed32d7.zip
Refactoring the backup recovery code
-rw-r--r--restorebackup.php20
1 files changed, 9 insertions, 11 deletions
diff --git a/restorebackup.php b/restorebackup.php
index 453e25c..b4cfce0 100644
--- a/restorebackup.php
+++ b/restorebackup.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
- * Restore settings page.
+ * Restore the settings page.
*
* @package local_webhooks
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
@@ -24,18 +24,20 @@
require_once(__DIR__ . "/../../config.php");
require_once(__DIR__ . "/classes/editform.php");
+require_once(__DIR__ . "/lib.php");
+
require_once($CFG->libdir . "/adminlib.php");
/* Link generation */
-$managerservice = new moodle_url("/local/webhooks/managerservice.php");
$baseurl = new moodle_url("/local/webhooks/restorebackup.php");
+$managerservice = new moodle_url("/local/webhooks/index.php");
/* Configure the context of the page */
admin_externalpage_setup("local_webhooks", "", null, $baseurl, array());
$context = context_system::instance();
/* Create an editing form */
-$mform = new \local_webhooks\service_backup_form($PAGE->url);
+$mform = new service_backup_form($PAGE->url);
/* Cancel processing */
if ($mform->is_cancelled()) {
@@ -43,19 +45,15 @@ if ($mform->is_cancelled()) {
}
/* Processing the received file */
-if ($data = $mform->get_data() && confirm_sesskey()) {
+if ($data = $mform->get_data()) {
$content = $mform->get_file_content("backupfile");
- $callbacks = unserialize(gzuncompress(base64_decode($content)));
+ $callbacks = local_webhooks_unarchive_data($content);
- $DB->delete_records("local_webhooks_service");
+ local_webhooks_remove_list_records();
foreach ($callbacks as $callback) {
- $DB->insert_record("local_webhooks_service", $callback);
+ local_webhooks_update_record($callback, true);
}
- /* Run the event */
- $event = \local_webhooks\event\backup_restored::create(array("context" => $context, "objectid" => 0));
- $event->trigger();
-
redirect($managerservice, new lang_string("restorefinished", "moodle"));
}