fipamo/app/Services/Upkeep/ResetService.php
ro 458b076f73
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
2024-07-09 16:26:01 -06:00

72 lines
1.9 KiB
PHP

<?php
namespace App\Services\Upkeep;
class ResetService
{
private $protectedItems = ['assets', '.htaccess', 'index.php', 'robots.txt'];
public function __construct()
{
}
public function site()
{
$response = [];
try {
$this->clearPublicAssets();
$this->clearPublicRoot();
$this->clearContent();
session()->flush();
$response = [
'message' => "PUBLIC CLEARED",
'type' => "COOL",
];
} catch (\Throwable $e) {
$response = [
'message' => "RESET NOT COMPLETED",
'error' => $e,
'type' => "ERROR",
];
}
return $response;
}
private function clearContent()
{
$contentDir = env('FIPAMO_DIR');
delete_directory($contentDir . '/pages', false);
delete_directory($contentDir . '/config', false);
}
private function clearPublicAssets()
{
delete_directory('../public/assets/docs', false);
delete_directory('../public/assets/video', false);
delete_directory('../public/assets/sound', false);
delete_directory('../public/assets/css/theme', false);
delete_directory('../public/assets/scripts/theme', false);
delete_directory('../public/assets/images/blog', false);
delete_directory('../public/assets/images/user', false);
}
private function clearPublicRoot()
{
$publicItems = glob('../public/*');
$response = [];
foreach ($publicItems as $path) {
$item = explode('/', $path);
if (in_array($item[2], $this->protectedItems)) {
//protected item do nothing
} else {
if (is_file($path)) {
unlink($path);
} else {
delete_directory($path);
}
}
}
}
}