forked from projects/fipamo
moved site restore to utility class, updated set up script, fixed minor error in front end api restore request
This commit is contained in:
parent
b8cf4e403a
commit
06787aac30
6 changed files with 111 additions and 75 deletions
|
@ -17,6 +17,7 @@ include "../brain/utility/FileUploader.inc.php";
|
||||||
include "../brain/utility/DocTools.inc.php";
|
include "../brain/utility/DocTools.inc.php";
|
||||||
include "../brain/utility/Sorting.inc.php";
|
include "../brain/utility/Sorting.inc.php";
|
||||||
include "../brain/utility/Setup.inc.php";
|
include "../brain/utility/Setup.inc.php";
|
||||||
|
include "../brain/utility/Maintenance.inc.php";
|
||||||
|
|
||||||
class App
|
class App
|
||||||
{
|
{
|
||||||
|
|
|
@ -57,7 +57,7 @@ class SettingsAPI
|
||||||
|
|
||||||
public static function createBackup()
|
public static function createBackup()
|
||||||
{
|
{
|
||||||
$result = Settings::makeBackup();
|
$result = Maintenance::makeBackup();
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,77 +168,6 @@ class Settings
|
||||||
DocTools::writeSettings("../config/settings.json", $settings);
|
DocTools::writeSettings("../config/settings.json", $settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function makeBackup()
|
|
||||||
{
|
|
||||||
//make sure back directory is there
|
|
||||||
if (!is_dir("../config/backups")) {
|
|
||||||
mkdir("../config/backups", 0755, true);
|
|
||||||
}
|
|
||||||
//creat backup zip
|
|
||||||
$zip = new ZipArchive();
|
|
||||||
$zip->open(
|
|
||||||
"../config/backups/latest_back.zip",
|
|
||||||
ZipArchive::CREATE | ZipArchive::OVERWRITE
|
|
||||||
);
|
|
||||||
//gather data and path info for md pages
|
|
||||||
$pagePath = "../content/pages";
|
|
||||||
$yearPaths = glob($pagePath . "/*", GLOB_ONLYDIR);
|
|
||||||
foreach ($yearPaths as $years) {
|
|
||||||
$year = explode("/", $years);
|
|
||||||
//grap the index and save it
|
|
||||||
if (trim($year[3]) == "start") {
|
|
||||||
$options = [
|
|
||||||
"add_path" => "content/pages/" . $year[3] . "/",
|
|
||||||
"remove_all_path" => true,
|
|
||||||
];
|
|
||||||
$zip->addGlob($years . "/*.md", GLOB_BRACE, $options);
|
|
||||||
}
|
|
||||||
$monthsPath = glob($pagePath . "/" . $year[3] . "/*", GLOB_ONLYDIR);
|
|
||||||
foreach ($monthsPath as $months) {
|
|
||||||
$month = explode("/", $months);
|
|
||||||
//once info is collected, add md pages to zip
|
|
||||||
$options = [
|
|
||||||
"add_path" => "content/pages/" . $year[3] . "/" . $month[4] . "/",
|
|
||||||
"remove_all_path" => true,
|
|
||||||
];
|
|
||||||
$zip->addGlob($months . "/*.md", GLOB_BRACE, $options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//tather data and path info for blog images
|
|
||||||
$blogImagesPath = "../public/assets/images/blog";
|
|
||||||
$yearPaths = glob($blogImagesPath . "/*", GLOB_ONLYDIR);
|
|
||||||
foreach ($yearPaths as $years) {
|
|
||||||
$year = explode("/", $years);
|
|
||||||
$monthsPath = glob($blogImagesPath . "/" . $year[5] . "/*", GLOB_ONLYDIR);
|
|
||||||
foreach ($monthsPath as $months) {
|
|
||||||
$month = explode("/", $months);
|
|
||||||
//once info is collected, add images pages to zip
|
|
||||||
$options = [
|
|
||||||
"add_path" =>
|
|
||||||
"public/assets/images/blog/" . $year[5] . "/" . $month[6] . "/",
|
|
||||||
"remove_all_path" => true,
|
|
||||||
];
|
|
||||||
$zip->addGlob($months . "/*.*", GLOB_BRACE, $options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//add directory for settings and save them
|
|
||||||
$zip->addEmptyDir("settings");
|
|
||||||
$zip->addFile("../config/settings.json", "settings/settings.json");
|
|
||||||
$zip->addFile("../config/folks.json", "settings/folks.json");
|
|
||||||
$zip->addFile("../config/tags.json", "settings/tags.json");
|
|
||||||
//save zip file
|
|
||||||
$zip->close();
|
|
||||||
|
|
||||||
//update settings file with latest back up date
|
|
||||||
$updated = new \Moment\Moment();
|
|
||||||
self::updateGlobalData("last_backup", $updated->format("Y-m-d\TH:i:sP"));
|
|
||||||
|
|
||||||
$result = ["message" => "Backup created. THIS IS A SAFE SPACE!"];
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function updateTags()
|
public static function updateTags()
|
||||||
{
|
{
|
||||||
$tags = Sorting::tags();
|
$tags = Sorting::tags();
|
||||||
|
|
99
brain/utility/Maintenance.inc.php
Normal file
99
brain/utility/Maintenance.inc.php
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
<?php
|
||||||
|
class Maintenance
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function makeBackup()
|
||||||
|
{
|
||||||
|
//make sure back directory is there
|
||||||
|
if (!is_dir("../config/backups")) {
|
||||||
|
mkdir("../config/backups", 0755, true);
|
||||||
|
}
|
||||||
|
//creat backup zip
|
||||||
|
$zip = new ZipArchive();
|
||||||
|
$zip->open(
|
||||||
|
"../config/backups/latest_back.zip",
|
||||||
|
ZipArchive::CREATE | ZipArchive::OVERWRITE
|
||||||
|
);
|
||||||
|
//gather data and path info for md pages
|
||||||
|
$pagePath = "../content/pages";
|
||||||
|
$yearPaths = glob($pagePath . "/*", GLOB_ONLYDIR);
|
||||||
|
foreach ($yearPaths as $years) {
|
||||||
|
$year = explode("/", $years);
|
||||||
|
//grap the index and save it
|
||||||
|
if (trim($year[3]) == "start") {
|
||||||
|
$options = [
|
||||||
|
"add_path" => "content/pages/" . $year[3] . "/",
|
||||||
|
"remove_all_path" => true,
|
||||||
|
];
|
||||||
|
$zip->addGlob($years . "/*.md", GLOB_BRACE, $options);
|
||||||
|
}
|
||||||
|
$monthsPath = glob($pagePath . "/" . $year[3] . "/*", GLOB_ONLYDIR);
|
||||||
|
foreach ($monthsPath as $months) {
|
||||||
|
$month = explode("/", $months);
|
||||||
|
//once info is collected, add md pages to zip
|
||||||
|
$options = [
|
||||||
|
"add_path" => "content/pages/" . $year[3] . "/" . $month[4] . "/",
|
||||||
|
"remove_all_path" => true,
|
||||||
|
];
|
||||||
|
$zip->addGlob($months . "/*.md", GLOB_BRACE, $options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//gather data and path info for blog images
|
||||||
|
$blogImagesPath = "../public/assets/images/blog";
|
||||||
|
$yearPaths = glob($blogImagesPath . "/*", GLOB_ONLYDIR);
|
||||||
|
foreach ($yearPaths as $years) {
|
||||||
|
$year = explode("/", $years);
|
||||||
|
$monthsPath = glob($blogImagesPath . "/" . $year[5] . "/*", GLOB_ONLYDIR);
|
||||||
|
foreach ($monthsPath as $months) {
|
||||||
|
$month = explode("/", $months);
|
||||||
|
//once info is collected, add images pages to zip
|
||||||
|
$options = [
|
||||||
|
"add_path" =>
|
||||||
|
"public/assets/images/blog/" . $year[5] . "/" . $month[6] . "/",
|
||||||
|
"remove_all_path" => true,
|
||||||
|
];
|
||||||
|
$zip->addGlob($months . "/*.*", GLOB_BRACE, $options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//gather data and path info for user images
|
||||||
|
$userImagesPath = "../public/assets/images/user";
|
||||||
|
$yearPaths = glob($userImagesPath . "/*", GLOB_ONLYDIR);
|
||||||
|
foreach ($yearPaths as $years) {
|
||||||
|
$year = explode("/", $years);
|
||||||
|
$monthsPath = glob($userImagesPath . "/" . $year[5] . "/*", GLOB_ONLYDIR);
|
||||||
|
foreach ($monthsPath as $months) {
|
||||||
|
$month = explode("/", $months);
|
||||||
|
//once info is collected, add images pages to zip
|
||||||
|
$options = [
|
||||||
|
"add_path" =>
|
||||||
|
"public/assets/images/user/" . $year[5] . "/" . $month[6] . "/",
|
||||||
|
"remove_all_path" => true,
|
||||||
|
];
|
||||||
|
$zip->addGlob($months . "/*.*", GLOB_BRACE, $options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//add directory for settings and save them
|
||||||
|
$zip->addEmptyDir("settings");
|
||||||
|
$zip->addFile("../config/settings.json", "settings/settings.json");
|
||||||
|
$zip->addFile("../config/folks.json", "settings/folks.json");
|
||||||
|
$zip->addFile("../config/tags.json", "settings/tags.json");
|
||||||
|
//save zip file
|
||||||
|
$zip->close();
|
||||||
|
|
||||||
|
//update settings file with latest back up date
|
||||||
|
$updated = new \Moment\Moment();
|
||||||
|
Settings::updateGlobalData(
|
||||||
|
"last_backup",
|
||||||
|
$updated->format("Y-m-d\TH:i:sP")
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = ["message" => "Backup created. THIS IS A SAFE SPACE!"];
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -142,6 +142,11 @@ class SetUp
|
||||||
"../public/assets/images/blog"
|
"../public/assets/images/blog"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
rename(
|
||||||
|
"../content/public/assets/images/user",
|
||||||
|
"../public/assets/images/user"
|
||||||
|
);
|
||||||
|
|
||||||
rename("../content/content/pages/", "../content/pages");
|
rename("../content/content/pages/", "../content/pages");
|
||||||
|
|
||||||
//legacy check for old file structure
|
//legacy check for old file structure
|
||||||
|
@ -164,8 +169,10 @@ class SetUp
|
||||||
DocTools::deleteFolder("../content/settings");
|
DocTools::deleteFolder("../content/settings");
|
||||||
DocTools::deleteFolder("../content/public");
|
DocTools::deleteFolder("../content/public");
|
||||||
DocTools::deleteFolder("../content/content");
|
DocTools::deleteFolder("../content/content");
|
||||||
|
$result = [
|
||||||
echo "AUTH VERIFIED";
|
"type" => "requestGood",
|
||||||
|
"message" => "Site Restored! Redirecting",
|
||||||
|
];
|
||||||
} else {
|
} else {
|
||||||
$result = [
|
$result = [
|
||||||
"type" => "requestLame",
|
"type" => "requestLame",
|
||||||
|
|
|
@ -97,7 +97,7 @@ export default class Base {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
let api = new FipamoApi();
|
let api = new FipamoApi();
|
||||||
var form = document.getElementById("init-restore");
|
var form = document.getElementById("init-restore");
|
||||||
admin
|
api
|
||||||
.handleInitRestore(form)
|
.handleInitRestore(form)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (response.type === DataEvent.REQUEST_LAME) {
|
if (response.type === DataEvent.REQUEST_LAME) {
|
||||||
|
|
Loading…
Reference in a new issue