summaryrefslogtreecommitdiff
path: root/app/Http/RequestHandlers/CleanDataFolder.php
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@webtrees.net>2019-10-16 11:45:00 +0100
committerGreg Roach <fisharebest@webtrees.net>2019-10-16 11:45:00 +0100
commitfd6c003f26d8770d21ea893811f0fc20a190c323 (patch)
treee9d99071afe0a821516bc30a2598e0f20feb0a80 /app/Http/RequestHandlers/CleanDataFolder.php
parent1a218474113038005e50986fff24ebcbd58554ff (diff)
downloadwebtrees-fd6c003f26d8770d21ea893811f0fc20a190c323.tar.gz
webtrees-fd6c003f26d8770d21ea893811f0fc20a190c323.tar.bz2
webtrees-fd6c003f26d8770d21ea893811f0fc20a190c323.zip
Convert controller to request handler
Diffstat (limited to 'app/Http/RequestHandlers/CleanDataFolder.php')
-rw-r--r--app/Http/RequestHandlers/CleanDataFolder.php100
1 files changed, 100 insertions, 0 deletions
diff --git a/app/Http/RequestHandlers/CleanDataFolder.php b/app/Http/RequestHandlers/CleanDataFolder.php
new file mode 100644
index 0000000000..d6c9cc0154
--- /dev/null
+++ b/app/Http/RequestHandlers/CleanDataFolder.php
@@ -0,0 +1,100 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2019 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Http\RequestHandlers;
+
+use Fisharebest\Webtrees\Http\ViewResponseTrait;
+use Fisharebest\Webtrees\I18N;
+use Fisharebest\Webtrees\Services\TreeService;
+use League\Flysystem\FilesystemInterface;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+
+use function array_map;
+use function explode;
+
+/**
+ * Show old files that could be deleted.
+ */
+class CleanDataFolder implements RequestHandlerInterface
+{
+ use ViewResponseTrait;
+
+ /** @var FilesystemInterface */
+ private $filesystem;
+
+ /** @var TreeService */
+ private $tree_service;
+
+ /**
+ * CleanDataFolder constructor.
+ *
+ * @param FilesystemInterface $filesystem
+ * @param TreeService $tree_service
+ */
+ public function __construct(FilesystemInterface $filesystem, TreeService $tree_service)
+ {
+ $this->filesystem = $filesystem;
+ $this->tree_service = $tree_service;
+ }
+
+ /**
+ * @param ServerRequestInterface $request
+ *
+ * @return ResponseInterface
+ */
+ public function handle(ServerRequestInterface $request): ResponseInterface
+ {
+ $this->layout = 'layouts/administration';
+
+ $protected = [
+ '.htaccess',
+ '.gitignore',
+ 'index.php',
+ 'config.ini.php',
+ ];
+
+ if ($request->getAttribute('dbtype') === 'sqlite') {
+ $protected[] = $request->getAttribute('dbname') . '.sqlite';
+ }
+
+ // Protect the media folders
+ foreach ($this->tree_service->all() as $tree) {
+ $media_directory = $tree->getPreference('MEDIA_DIRECTORY');
+ [$folder] = explode('/', $media_directory);
+
+ $protected[] = $folder . '/';
+ }
+
+ // List the top-level contents of the data folder
+ $entries = array_map(static function (array $content) {
+ if ($content['type'] === 'dir') {
+ return $content['path'] . '/';
+ }
+
+ return $content['path'];
+ }, $this->filesystem->listContents());
+
+ return $this->viewResponse('admin/clean-data', [
+ 'title' => I18N::translate('Clean up data folder'),
+ 'entries' => $entries,
+ 'protected' => $protected,
+ ]);
+ }
+}