forked from projects/fipamo
FEATURE: Full site restore
content restore was already enabled, so the last step was completing file restorartion if there was a file archive uploaded now that this has been added, full site restore from backup archives now works.
This commit is contained in:
parent
4e880092c1
commit
d24df50d96
4 changed files with 74 additions and 17 deletions
|
@ -59,7 +59,11 @@ class FrontController extends Controller
|
||||||
}
|
}
|
||||||
return view($template, $pageData);
|
return view($template, $pageData);
|
||||||
} else {
|
} else {
|
||||||
|
if (is_file('../public/index.html')) {
|
||||||
return response()->file('../public/index.html');
|
return response()->file('../public/index.html');
|
||||||
|
} else {
|
||||||
|
return redirect()->intended('dashboard/start');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return view('back.init', ["status" => false, "title" => "Set Up"]);
|
return view('back.init', ["status" => false, "title" => "Set Up"]);
|
||||||
|
|
|
@ -124,19 +124,38 @@ class InitService
|
||||||
|
|
||||||
public function restore($request)
|
public function restore($request)
|
||||||
{
|
{
|
||||||
$file = $request->file('backup-upload');
|
//content required, so check it
|
||||||
$file->move(env('FIPAMO_DIR') . '/', $file->getClientOriginalName());
|
$result = [];
|
||||||
$zip = new \ZipArchive();
|
$contentArchive = $request->file('backup-content-upload');
|
||||||
|
$fileArchive = $request->file('backup-files-upload');
|
||||||
|
if ($contentArchive == null || $contentArchive == '') {
|
||||||
|
return $result = [
|
||||||
|
'type' => 'requestLame',
|
||||||
|
'message' => 'Content Archive EMPTY',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$result = $this->restoreContent($contentArchive, $request);
|
||||||
|
//file upload is optional, so if it's present, restore it
|
||||||
|
if ($fileArchive != null || $fileArchive != '') {
|
||||||
|
$result = $this->restoreFiles($fileArchive);
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function restoreContent($contentUpload, $request)
|
||||||
|
{
|
||||||
|
$contentUpload->move(env('FIPAMO_DIR') . '/', $contentUpload->getClientOriginalName());
|
||||||
|
$contentZip = new \ZipArchive();
|
||||||
$result = [];
|
$result = [];
|
||||||
$tempDir = env('FIPAMO_DIR') . '/_temp';
|
$tempDir = env('FIPAMO_DIR') . '/_temp';
|
||||||
if ($zip->open(env('FIPAMO_DIR') . '/' . $file->getClientOriginalName()) === true) {
|
if ($contentZip->open(env('FIPAMO_DIR') . '/' . $contentUpload->getClientOriginalName()) === true) {
|
||||||
$folks = json_decode($zip->getFromName('config/folks.json'), true);
|
$folks = json_decode($contentZip->getFromName('config/folks.json'), true);
|
||||||
$found = find($folks, ['handle' => $request->restore_member_handle]);
|
$found = find($folks, ['handle' => $request->restore_member_handle]);
|
||||||
if ($found) {
|
if ($found) {
|
||||||
if (password_verify($request->restore_member_pass, $found['password'])) {
|
if (password_verify($request->restore_member_pass, $found['password'])) {
|
||||||
//restore assets from previous site
|
//restore assets from previous site
|
||||||
if ($request->restore_former_url != '' || $request->restore_former_url != null) {
|
if ($request->restore_former_url != '' || $request->restore_former_url != null) {
|
||||||
$this->moveAssets($zip, $request->restore_former_url);
|
$this->moveAssets($contentZip, $request->restore_former_url);
|
||||||
}
|
}
|
||||||
$newFolks = [];
|
$newFolks = [];
|
||||||
if (!isset($found['secret'])) {
|
if (!isset($found['secret'])) {
|
||||||
|
@ -145,7 +164,7 @@ class InitService
|
||||||
array_push($newFolks, $found);
|
array_push($newFolks, $found);
|
||||||
//make temp folder and dump file in there
|
//make temp folder and dump file in there
|
||||||
mkdir($tempDir, 0755, true);
|
mkdir($tempDir, 0755, true);
|
||||||
$zip->extractTo($tempDir);
|
$contentZip->extractTo($tempDir);
|
||||||
//load up old config file
|
//load up old config file
|
||||||
$newConfig = json_decode(
|
$newConfig = json_decode(
|
||||||
file_get_contents($tempDir . '/config/settings.json'),
|
file_get_contents($tempDir . '/config/settings.json'),
|
||||||
|
@ -166,11 +185,11 @@ class InitService
|
||||||
rename($tempDir . '/content/pages/', env('PAGES_PATH'));
|
rename($tempDir . '/content/pages/', env('PAGES_PATH'));
|
||||||
//clean up temp dir and zip file
|
//clean up temp dir and zip file
|
||||||
$this->docs::deleteFolder($tempDir);
|
$this->docs::deleteFolder($tempDir);
|
||||||
$zip->close();
|
$contentZip->close();
|
||||||
unlink(env('FIPAMO_DIR') . '/' . $file->getClientOriginalName());
|
unlink(env('FIPAMO_DIR') . '/' . $contentUpload->getClientOriginalName());
|
||||||
$result = [
|
$result = [
|
||||||
'type' => 'requestGood',
|
'type' => 'requestGood',
|
||||||
'message' => 'Site Restored! Redirecting',
|
'message' => 'Content Restored! Redirecting',
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
$result = [
|
$result = [
|
||||||
|
@ -185,6 +204,36 @@ class InitService
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private function restoreFiles($filesUpload)
|
||||||
|
{
|
||||||
|
$filesUpload->move(env('FIPAMO_DIR') . '/', $filesUpload->getClientOriginalName());
|
||||||
|
$filesZip = new \ZipArchive();
|
||||||
|
$tempDir = env('FIPAMO_DIR') . '/_file_temp';
|
||||||
|
$result = [];
|
||||||
|
//images path for blog and user
|
||||||
|
$blogImagePath = '../public/assets/images/blog';
|
||||||
|
$userImagePath = '../public/assets/images/user';
|
||||||
|
if ($filesZip->open(env('FIPAMO_DIR') . '/' . $filesUpload->getClientOriginalName()) === true) {
|
||||||
|
$filesZip->extractTo($tempDir);
|
||||||
|
//clear and move dir if present
|
||||||
|
delete_directory($blogImagePath, false);
|
||||||
|
if (is_dir($tempDir . '/public/assets/images/blog')) {
|
||||||
|
rename($tempDir . '/public/assets/images/blog', $blogImagePath);
|
||||||
|
}
|
||||||
|
delete_directory($userImagePath, false);
|
||||||
|
if (is_dir($tempDir . '/public/assets/images/user')) {
|
||||||
|
rename($tempDir . '/public/assets/images/user', $userImagePath);
|
||||||
|
}
|
||||||
|
$result = [
|
||||||
|
'type' => 'requestGood',
|
||||||
|
'message' => 'Files & Content Restored! Redirecting',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
delete_directory($tempDir);
|
||||||
|
$filesZip->close();
|
||||||
|
unlink(env('FIPAMO_DIR') . '/' . $filesUpload->getClientOriginalName());
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
"theme": "fipamo-default-v2",
|
"theme": "fipamo-default-v2",
|
||||||
"display_limit": 5,
|
"display_limit": 5,
|
||||||
"last_content_backup": null,
|
"last_content_backup": null,
|
||||||
"last_file_backup": null,
|
"last_files_backup": null,
|
||||||
"externalAPI": "false",
|
"externalAPI": "false",
|
||||||
"dynamicRender": "false"
|
"dynamicRender": "false"
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,12 +4,16 @@
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<form id="init-restore" method="POST">
|
<form id="init-restore" method="POST">
|
||||||
<label class="inline">previous</label><input type="text" class="inline" name="restore_former_url" id="restore_former_url" placeholder="previous site url"/>
|
|
||||||
<label class="inline">handle</label><input type="text" class="inline" name="restore_member_handle" id="restore_member_handle" placeholder="handle"/>
|
<label class="inline">handle</label><input type="text" class="inline" name="restore_member_handle" id="restore_member_handle" placeholder="handle"/>
|
||||||
<label class="inline">password</label><input type="password"class="inline" name="restore_member_pass" id="restore_member_pass" placeholder="password"/>
|
<label class="inline">password</label><input type="password"class="inline" name="restore_member_pass" id="restore_member_pass" placeholder="password"/>
|
||||||
|
<label class="inline">previous</label><input type="text" class="inline" name="restore_former_url" id="restore_former_url" placeholder="previous site url"/>
|
||||||
<div>
|
<div>
|
||||||
<label>Grab your backup zip</label>
|
<label>Grab your content backup</label>
|
||||||
<input id="backup-upload" type="file" name="backup-upload" placeholder="Backup Zip"/>
|
<input id="backup-content-upload" type="file" name="backup-content-upload" placeholder="Content Archive"/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label>Grab your file backup</label>
|
||||||
|
<input id="backup-files-upload" type="file" name="backup-files-upload" placeholder="File Archive"/>
|
||||||
</div>
|
</div>
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
<button id="blog-restore" data-action='blog-restore' type='submit'>RESTORE</button>
|
<button id="blog-restore" data-action='blog-restore' type='submit'>RESTORE</button>
|
||||||
|
|
Loading…
Reference in a new issue