2024-07-03 01:09:27 +02:00
|
|
|
<?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);
|
2024-07-10 00:26:01 +02:00
|
|
|
delete_directory('../public/assets/sound', false);
|
2024-07-03 01:09:27 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|