Fix #2136 allow admin to add exception to cleanup list

This commit is contained in:
Kijin Sung 2023-07-04 22:37:17 +09:00
parent b01c36b792
commit e98ba87f8e
6 changed files with 60 additions and 1 deletions

View file

@ -3,6 +3,8 @@
namespace Rhymix\Modules\Admin\Controllers\Maintenance;
use Context;
use ModuleController;
use ModuleModel;
use Rhymix\Framework\Exceptions\InvalidRequest;
use Rhymix\Framework\Exceptions\TargetNotFound;
use Rhymix\Framework\Security;
@ -28,6 +30,30 @@ class Cleanup extends Base
$this->setTemplateFile('cleanup');
}
/**
* Add a file or directory to the cleanup exception list.
*/
public function procAdminAddCleanupException()
{
// Check the path.
$path = Context::get('path');
if (!$path || !array_key_exists($path, self::CLEANUP_LIST))
{
throw new InvalidRequest;
}
// Get current configuration.
$config = ModuleModel::getModuleConfig('admin') ?: new \stdClass;
if (!isset($config->cleanup_exceptions))
{
$config->cleanup_exceptions = [];
}
// Add the path to the exception list.
$config->cleanup_exceptions[$path] = date('Ymd');
ModuleController::getInstance()->insertModuleConfig('admin', $config);
}
/**
* Cleanup action.
*/
@ -59,9 +85,22 @@ class Cleanup extends Base
*/
public function checkFiles(): array
{
// Get current configuration.
$config = ModuleModel::getModuleConfig('admin') ?: new \stdClass;
if (!isset($config->cleanup_exceptions))
{
$config->cleanup_exceptions = [];
}
$result = [];
foreach (self::CLEANUP_LIST as $name => $reason)
{
// Skip if registered as an exception.
if (isset($config->cleanup_exceptions[$name]))
{
continue;
}
// Skip if file/directory distinction doesn't match.
if (str_ends_with($name, '/') && !Storage::isDirectory(\RX_BASEDIR . rtrim($name, '/')))
{