External backup function
This commit is contained in:
@ -54,7 +54,7 @@ $callbacks = local_webhooks_get_list_records();
|
|||||||
|
|
||||||
/* Upload settings as a file */
|
/* Upload settings as a file */
|
||||||
if (boolval($backupservices)) {
|
if (boolval($backupservices)) {
|
||||||
$filecontent = local_webhooks_archiving_data($callbacks);
|
$filecontent = local_webhooks_create_backup();
|
||||||
$filename = "webhooks_" . date("U") . ".backup";
|
$filename = "webhooks_" . date("U") . ".backup";
|
||||||
send_file($filecontent, $filename, 0, 0, true, true);
|
send_file($filecontent, $filename, 0, 0, true, true);
|
||||||
}
|
}
|
||||||
|
26
lib.php
26
lib.php
@ -108,6 +108,32 @@ function local_webhooks_update_record($data, $insert = true) {
|
|||||||
return boolval($result);
|
return boolval($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Compress an array into a string.
|
||||||
*
|
*
|
||||||
|
@ -47,13 +47,7 @@ if ($mform->is_cancelled()) {
|
|||||||
/* Processing the received file */
|
/* Processing the received file */
|
||||||
if ($data = $mform->get_data()) {
|
if ($data = $mform->get_data()) {
|
||||||
$content = $mform->get_file_content("backupfile");
|
$content = $mform->get_file_content("backupfile");
|
||||||
$callbacks = local_webhooks_unarchive_data($content);
|
local_webhooks_restore_backup($content);
|
||||||
|
|
||||||
local_webhooks_remove_list_records();
|
|
||||||
foreach ($callbacks as $callback) {
|
|
||||||
local_webhooks_update_record($callback, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
redirect($managerservice, new lang_string("restorefinished", "moodle"));
|
redirect($managerservice, new lang_string("restorefinished", "moodle"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user