forked from projects/fipamo
FEATURE: full asset restore from backup archive
the current restore process only restored images and not the additional file types that are allowed, so that has been added also tweaked the reset request to include the correct token so the request does not fail API authorization
This commit is contained in:
parent
d51071b2d3
commit
458b076f73
4 changed files with 38 additions and 15 deletions
|
@ -12,10 +12,14 @@ use function _\find;
|
||||||
class InitService
|
class InitService
|
||||||
{
|
{
|
||||||
protected $docs;
|
protected $docs;
|
||||||
|
protected $filePaths = [];
|
||||||
|
|
||||||
public function __construct(DocService $docService)
|
public function __construct(DocService $docService)
|
||||||
{
|
{
|
||||||
$this->docs = $docService;
|
$this->docs = $docService;
|
||||||
|
$this->filePaths = ['../public/assets/images/blog',
|
||||||
|
'../public/assets/images/user', '../public/assets/video/blog',
|
||||||
|
'../public/assets/docs/blog', '../public/assets/sound/blog'];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function validSecret($length)
|
private static function validSecret($length)
|
||||||
|
@ -125,6 +129,7 @@ class InitService
|
||||||
public function restore($request)
|
public function restore($request)
|
||||||
{
|
{
|
||||||
//content required, so check it
|
//content required, so check it
|
||||||
|
|
||||||
$result = [];
|
$result = [];
|
||||||
$contentArchive = $request->file('backup-content-upload');
|
$contentArchive = $request->file('backup-content-upload');
|
||||||
$fileArchive = $request->file('backup-files-upload');
|
$fileArchive = $request->file('backup-files-upload');
|
||||||
|
@ -135,6 +140,10 @@ class InitService
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
$result = $this->restoreContent($contentArchive, $request);
|
$result = $this->restoreContent($contentArchive, $request);
|
||||||
|
|
||||||
|
if ($result['type'] == 'requestLame') {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
//file upload is optional, so if it's present, restore it
|
//file upload is optional, so if it's present, restore it
|
||||||
if ($fileArchive != null || $fileArchive != '') {
|
if ($fileArchive != null || $fileArchive != '') {
|
||||||
$result = $this->restoreFiles($fileArchive);
|
$result = $this->restoreFiles($fileArchive);
|
||||||
|
@ -200,10 +209,11 @@ class InitService
|
||||||
} else {
|
} else {
|
||||||
$result = [
|
$result = [
|
||||||
'type' => 'requestLame',
|
'type' => 'requestLame',
|
||||||
'message' => 'Could not open backup. RATS!',
|
'message' => 'Uh Oh. Check that handle',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function restoreFiles($filesUpload)
|
private function restoreFiles($filesUpload)
|
||||||
|
@ -212,19 +222,23 @@ class InitService
|
||||||
$filesZip = new \ZipArchive();
|
$filesZip = new \ZipArchive();
|
||||||
$tempDir = env('FIPAMO_DIR') . '/_file_temp';
|
$tempDir = env('FIPAMO_DIR') . '/_file_temp';
|
||||||
$result = [];
|
$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) {
|
if ($filesZip->open(env('FIPAMO_DIR') . '/' . $filesUpload->getClientOriginalName()) === true) {
|
||||||
$filesZip->extractTo($tempDir);
|
$filesZip->extractTo($tempDir);
|
||||||
//clear and move dir if present
|
//clear and move dir if present
|
||||||
delete_directory($blogImagePath, false);
|
foreach ($this->filePaths as $path) {
|
||||||
if (is_dir($tempDir . '/public/assets/images/blog')) {
|
delete_directory($path, false);
|
||||||
rename($tempDir . '/public/assets/images/blog', $blogImagePath);
|
//non image directories don't exist, so they need to be created
|
||||||
}
|
$pathing = explode("/", $path);
|
||||||
delete_directory($userImagePath, false);
|
if ($pathing[3] != 'images') {
|
||||||
if (is_dir($tempDir . '/public/assets/images/user')) {
|
if (!is_dir('../public/assets/' . $pathing[3])) {
|
||||||
rename($tempDir . '/public/assets/images/user', $userImagePath);
|
mkdir('../public/assets/' . $pathing[3]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$tempPath = $tempDir . '/' . substr($path, 3);
|
||||||
|
if (is_dir($tempPath)) {
|
||||||
|
rename($tempPath, $path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$result = [
|
$result = [
|
||||||
'type' => 'requestGood',
|
'type' => 'requestGood',
|
||||||
|
|
|
@ -44,6 +44,7 @@ class ResetService
|
||||||
{
|
{
|
||||||
delete_directory('../public/assets/docs', false);
|
delete_directory('../public/assets/docs', false);
|
||||||
delete_directory('../public/assets/video', false);
|
delete_directory('../public/assets/video', false);
|
||||||
|
delete_directory('../public/assets/sound', false);
|
||||||
delete_directory('../public/assets/css/theme', false);
|
delete_directory('../public/assets/css/theme', false);
|
||||||
delete_directory('../public/assets/scripts/theme', false);
|
delete_directory('../public/assets/scripts/theme', false);
|
||||||
delete_directory('../public/assets/images/blog', false);
|
delete_directory('../public/assets/images/blog', false);
|
||||||
|
|
|
@ -281,8 +281,14 @@ class MaintenanceManager {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (requestType == REQUEST_TYPE_PUT || requestType == REQUEST_TYPE_POST) {
|
if (requestType == REQUEST_TYPE_PUT || requestType == REQUEST_TYPE_POST) {
|
||||||
if (eventType === TASK_UPLOAD_FILES || eventType === TASK_BACKUP_CREATE)
|
if (
|
||||||
|
eventType === TASK_UPLOAD_FILES ||
|
||||||
|
eventType === TASK_BACKUP_CREATE ||
|
||||||
|
eventType === TASK_SITE_INIT
|
||||||
|
) {
|
||||||
request.setRequestHeader('fipamo-access-token', self.token);
|
request.setRequestHeader('fipamo-access-token', self.token);
|
||||||
|
}
|
||||||
|
|
||||||
switch (contentType) {
|
switch (contentType) {
|
||||||
case CONTENT_TYPE_JSON:
|
case CONTENT_TYPE_JSON:
|
||||||
request.setRequestHeader(
|
request.setRequestHeader(
|
||||||
|
|
|
@ -22,6 +22,10 @@ use App\Http\Controllers\API\MailAPIController;
|
||||||
//check if session is active
|
//check if session is active
|
||||||
Route::get("/v1/status", [AuthAPIController::class, 'status']);
|
Route::get("/v1/status", [AuthAPIController::class, 'status']);
|
||||||
|
|
||||||
|
//site setup
|
||||||
|
Route::post("/v1/init", [InitAPIController::class, 'setupFresh']);
|
||||||
|
Route::post("/v1/restore", [InitAPIController::class, 'setupRestore']);
|
||||||
|
|
||||||
//handle page editing actions
|
//handle page editing actions
|
||||||
Route::group(['prefix' => '/v1/page', 'middleware' => 'validate.token'], function () {
|
Route::group(['prefix' => '/v1/page', 'middleware' => 'validate.token'], function () {
|
||||||
Route::put("/write", [PageAPIController::class, 'write']);
|
Route::put("/write", [PageAPIController::class, 'write']);
|
||||||
|
@ -45,8 +49,6 @@ Route::group(['prefix' => '/v1/backup', 'middleware' => 'validate.token'], funct
|
||||||
//other
|
//other
|
||||||
Route::group(['prefix' => '/v1', 'middleware' => 'validate.token'], function () {
|
Route::group(['prefix' => '/v1', 'middleware' => 'validate.token'], function () {
|
||||||
Route::post("/files", [FileUploadAPIController::class, 'upload']);
|
Route::post("/files", [FileUploadAPIController::class, 'upload']);
|
||||||
Route::post("/init", [InitAPIController::class, 'setupFresh']);
|
|
||||||
Route::post("/restore", [InitAPIController::class, 'setupRestore']);
|
|
||||||
Route::post("/reset", [InitAPIController::class, 'setupReset']);
|
Route::post("/reset", [InitAPIController::class, 'setupReset']);
|
||||||
Route::post("/mailer", [MailAPIController::class, 'sendNotify']);
|
Route::post("/mailer", [MailAPIController::class, 'sendNotify']);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue