mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-29 15:22:15 +09:00
Fix #2136 allow admin to add exception to cleanup list
This commit is contained in:
parent
b01c36b792
commit
e98ba87f8e
6 changed files with 60 additions and 1 deletions
|
|
@ -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, '/')))
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue