fipamo/app/Services/Upkeep/ResetService.php
ro bc7b1fe7ec
FEATURE: Restore to default
plugged in a new feature that will allow the site to be reset to its
default state, clearing out all content and configurations to start
fresh
2024-07-02 17:09:27 -06:00

71 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/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);
}
}
}
}
}