diff options
| -rw-r--r-- | app/Http/Middleware/Housekeeping.php | 23 | ||||
| -rw-r--r-- | app/Http/Middleware/UseLocale.php | 17 | ||||
| -rw-r--r-- | app/Http/Middleware/UseTheme.php | 13 |
3 files changed, 18 insertions, 35 deletions
diff --git a/app/Http/Middleware/Housekeeping.php b/app/Http/Middleware/Housekeeping.php index 4fdb8bb203..4886a5cda3 100644 --- a/app/Http/Middleware/Housekeeping.php +++ b/app/Http/Middleware/Housekeeping.php @@ -38,7 +38,7 @@ class Housekeeping implements MiddlewareInterface private const MAX_THUMBNAIL_AGE = 60 * 60 * 24 * 90; // Delete files in /data/tmp after 1 hour. - private const TMP_DIR = 'data/tmp'; + private const TMP_DIR = 'data/tmp'; private const MAX_TMP_FILE_AGE = 60 * 60; // Delete error logs after 90 days. @@ -50,21 +50,16 @@ class Housekeeping implements MiddlewareInterface // Run the cleanup every 100 requests. private const PROBABILITY = 100; - /** @var Filesystem */ - private $filesystem; - /** @var HousekeepingService */ private $housekeeping_service; /** * Housekeeping constructor. * - * @param FilesystemInterface $filesystem * @param HousekeepingService $housekeeping_service */ - public function __construct(FilesystemInterface $filesystem, HousekeepingService $housekeeping_service) + public function __construct(HousekeepingService $housekeeping_service) { - $this->filesystem = $filesystem; $this->housekeeping_service = $housekeeping_service; } @@ -94,14 +89,16 @@ class Housekeeping implements MiddlewareInterface */ private function runHousekeeping() { - // Clear files in the (user-specified) data folder - which might not be local - $this->housekeeping_service->deleteOldFiles($this->filesystem, 'cache', self::MAX_CACHE_AGE); + $data_filesystem = app()->make(FilesystemInterface::class); + $root_filesystem = new Filesystem(new Local(WT_ROOT)); + + // Clear files in the (user-specified) data folder - which might not be local files + $this->housekeeping_service->deleteOldFiles($data_filesystem, 'cache', self::MAX_CACHE_AGE); - $this->housekeeping_service->deleteOldFiles($this->filesystem, 'thumbnail-cache', self::MAX_THUMBNAIL_AGE); + $this->housekeeping_service->deleteOldFiles($data_filesystem, 'thumbnail-cache', self::MAX_THUMBNAIL_AGE); - // Clear files in /data (for things that need to be local files) - $filesystem = new Filesystem(new Local(WT_ROOT)); - $this->housekeeping_service->deleteOldFiles($filesystem, self::TMP_DIR, self::MAX_TMP_FILE_AGE); + // Clear files in /data - which need to be local files + $this->housekeeping_service->deleteOldFiles($root_filesystem, self::TMP_DIR, self::MAX_TMP_FILE_AGE); // Clear entries in database tables $this->housekeeping_service->deleteOldLogs(self::MAX_LOG_AGE); diff --git a/app/Http/Middleware/UseLocale.php b/app/Http/Middleware/UseLocale.php index c836f6097a..a5e1acd75c 100644 --- a/app/Http/Middleware/UseLocale.php +++ b/app/Http/Middleware/UseLocale.php @@ -32,19 +32,6 @@ use Throwable; */ class UseLocale implements MiddlewareInterface { - /** @var Tree|null */ - private $tree; - - /** - * UseTheme constructor. - * - * @param Tree|null $tree - */ - public function __construct(?Tree $tree) - { - $this->tree = $tree; - } - /** * @param Request $request * @param Closure $next @@ -54,8 +41,10 @@ class UseLocale implements MiddlewareInterface */ public function handle(Request $request, Closure $next): Response { + $tree = app()->make(Tree::class); + // Select a locale - define('WT_LOCALE', I18N::init('', $this->tree)); + define('WT_LOCALE', I18N::init('', $tree)); Session::put('locale', WT_LOCALE); app()->instance(LocaleInterface::class, WebtreesLocale::create(WT_LOCALE)); diff --git a/app/Http/Middleware/UseTheme.php b/app/Http/Middleware/UseTheme.php index 5552c8bbdf..94bfe98ee1 100644 --- a/app/Http/Middleware/UseTheme.php +++ b/app/Http/Middleware/UseTheme.php @@ -37,19 +37,14 @@ class UseTheme implements MiddlewareInterface /** @var ModuleService */ private $module_service; - /** @var Tree|null */ - private $tree; - /** * UseTheme constructor. * * @param ModuleService $module_service - * @param Tree|null $tree */ - public function __construct(ModuleService $module_service, ?Tree $tree) + public function __construct(ModuleService $module_service) { $this->module_service = $module_service; - $this->tree = $tree; } /** @@ -89,8 +84,10 @@ class UseTheme implements MiddlewareInterface yield $themes->get(Session::get('theme_id', '')); // Default for tree - if ($this->tree instanceof Tree) { - yield $themes->get($this->tree->getPreference('THEME_DIR')); + $tree = app()->make(Tree::class); + + if ($tree instanceof Tree) { + yield $themes->get($tree->getPreference('THEME_DIR')); } // Default for site |
