diff --git a/app/Http/Controllers/FrontController.php b/app/Http/Controllers/FrontController.php index f94c79a..0e4835e 100644 --- a/app/Http/Controllers/FrontController.php +++ b/app/Http/Controllers/FrontController.php @@ -59,7 +59,11 @@ class FrontController extends Controller } return view($template, $pageData); } else { - return response()->file('../public/index.html'); + if (is_file('../public/index.html')) { + return response()->file('../public/index.html'); + } else { + return redirect()->intended('dashboard/start'); + } } } else { return view('back.init', ["status" => false, "title" => "Set Up"]); diff --git a/app/Services/Upkeep/InitService.php b/app/Services/Upkeep/InitService.php index 5c58b8e..30a2e89 100644 --- a/app/Services/Upkeep/InitService.php +++ b/app/Services/Upkeep/InitService.php @@ -124,19 +124,38 @@ class InitService public function restore($request) { - $file = $request->file('backup-upload'); - $file->move(env('FIPAMO_DIR') . '/', $file->getClientOriginalName()); - $zip = new \ZipArchive(); - $result = []; - $tempDir = env('FIPAMO_DIR') . '/_temp'; - if ($zip->open(env('FIPAMO_DIR') . '/' . $file->getClientOriginalName()) === true) { - $folks = json_decode($zip->getFromName('config/folks.json'), true); + //content required, so check it + $result = []; + $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 = []; + $tempDir = env('FIPAMO_DIR') . '/_temp'; + if ($contentZip->open(env('FIPAMO_DIR') . '/' . $contentUpload->getClientOriginalName()) === true) { + $folks = json_decode($contentZip->getFromName('config/folks.json'), true); $found = find($folks, ['handle' => $request->restore_member_handle]); if ($found) { if (password_verify($request->restore_member_pass, $found['password'])) { //restore assets from previous site 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 = []; if (!isset($found['secret'])) { @@ -145,7 +164,7 @@ class InitService array_push($newFolks, $found); //make temp folder and dump file in there mkdir($tempDir, 0755, true); - $zip->extractTo($tempDir); + $contentZip->extractTo($tempDir); //load up old config file $newConfig = json_decode( file_get_contents($tempDir . '/config/settings.json'), @@ -166,11 +185,11 @@ class InitService rename($tempDir . '/content/pages/', env('PAGES_PATH')); //clean up temp dir and zip file $this->docs::deleteFolder($tempDir); - $zip->close(); - unlink(env('FIPAMO_DIR') . '/' . $file->getClientOriginalName()); + $contentZip->close(); + unlink(env('FIPAMO_DIR') . '/' . $contentUpload->getClientOriginalName()); $result = [ 'type' => 'requestGood', - 'message' => 'Site Restored! Redirecting', + 'message' => 'Content Restored! Redirecting', ]; } else { $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; } diff --git a/content/init/settings-template.json b/content/init/settings-template.json index c89da9c..da34a7d 100644 --- a/content/init/settings-template.json +++ b/content/init/settings-template.json @@ -9,7 +9,7 @@ "theme": "fipamo-default-v2", "display_limit": 5, "last_content_backup": null, - "last_file_backup": null, + "last_files_backup": null, "externalAPI": "false", "dynamicRender": "false" }, diff --git a/resources/views/forms/init-restore.blade.php b/resources/views/forms/init-restore.blade.php index 43d3bac..5b30408 100644 --- a/resources/views/forms/init-restore.blade.php +++ b/resources/views/forms/init-restore.blade.php @@ -4,12 +4,16 @@
- +
- - + + +
+
+ +