summaryrefslogtreecommitdiff
path: root/app/Http
diff options
context:
space:
mode:
Diffstat (limited to 'app/Http')
-rw-r--r--app/Http/Controllers/Admin/AbstractAdminController.php31
-rw-r--r--app/Http/RequestHandlers/FixLevel0MediaAction.php84
-rw-r--r--app/Http/RequestHandlers/FixLevel0MediaData.php (renamed from app/Http/Controllers/Admin/FixLevel0MediaController.php)63
-rw-r--r--app/Http/RequestHandlers/FixLevel0MediaPage.php51
-rw-r--r--app/Http/RequestHandlers/ImportThumbnailsAction.php129
-rw-r--r--app/Http/RequestHandlers/ImportThumbnailsData.php (renamed from app/Http/Controllers/Admin/ImportThumbnailsController.php)121
-rw-r--r--app/Http/RequestHandlers/ImportThumbnailsPage.php50
-rw-r--r--app/Http/RequestHandlers/LoginAction.php2
-rw-r--r--app/Http/RequestHandlers/UpgradeWizardConfirm.php (renamed from app/Http/Controllers/AbstractBaseController.php)23
-rw-r--r--app/Http/RequestHandlers/UpgradeWizardPage.php130
-rw-r--r--app/Http/RequestHandlers/UpgradeWizardStep.php (renamed from app/Http/Controllers/Admin/UpgradeController.php)83
-rw-r--r--app/Http/Routes/WebRoutes.php27
12 files changed, 503 insertions, 291 deletions
diff --git a/app/Http/Controllers/Admin/AbstractAdminController.php b/app/Http/Controllers/Admin/AbstractAdminController.php
deleted file mode 100644
index fc6d8329e5..0000000000
--- a/app/Http/Controllers/Admin/AbstractAdminController.php
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-
-/**
- * webtrees: online genealogy
- * Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
- */
-
-declare(strict_types=1);
-
-namespace Fisharebest\Webtrees\Http\Controllers\Admin;
-
-use Fisharebest\Webtrees\Http\Controllers\AbstractBaseController;
-
-/**
- * Common functions for admin controllers.
- */
-abstract class AbstractAdminController extends AbstractBaseController
-{
- /** @var string */
- protected $layout = 'layouts/administration';
-}
diff --git a/app/Http/RequestHandlers/FixLevel0MediaAction.php b/app/Http/RequestHandlers/FixLevel0MediaAction.php
new file mode 100644
index 0000000000..6421e14733
--- /dev/null
+++ b/app/Http/RequestHandlers/FixLevel0MediaAction.php
@@ -0,0 +1,84 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Http\RequestHandlers;
+
+use Fisharebest\Webtrees\Registry;
+use Fisharebest\Webtrees\Services\TreeService;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+
+use function response;
+
+/**
+ * Move media links from records to facts.
+ */
+class FixLevel0MediaAction implements RequestHandlerInterface
+{
+ /** @var TreeService */
+ private $tree_service;
+
+ /**
+ * FixLevel0MediaController constructor.
+ *
+ * @param TreeService $tree_service
+ */
+ public function __construct(TreeService $tree_service)
+ {
+ $this->tree_service = $tree_service;
+ }
+
+ /**
+ * Move a link to a media object from a level 0 record to a level 1 record.
+ *
+ * @param ServerRequestInterface $request
+ *
+ * @return ResponseInterface
+ */
+ public function handle(ServerRequestInterface $request): ResponseInterface
+ {
+ $params = (array) $request->getParsedBody();
+
+ $fact_id = $params['fact_id'];
+ $indi_xref = $params['indi_xref'];
+ $obje_xref = $params['obje_xref'];
+ $tree_id = (int) $params['tree_id'];
+
+ $tree = $this->tree_service->find($tree_id);
+ $individual = Registry::individualFactory()->make($indi_xref, $tree);
+ $media = Registry::mediaFactory()->make($obje_xref, $tree);
+
+ if ($individual !== null && $media !== null) {
+ foreach ($individual->facts() as $fact1) {
+ if ($fact1->id() === $fact_id) {
+ $individual->updateFact($fact_id, $fact1->gedcom() . "\n2 OBJE @" . $obje_xref . '@', false);
+ foreach ($individual->facts(['OBJE']) as $fact2) {
+ if ($fact2->target() === $media) {
+ $individual->deleteFact($fact2->id(), false);
+ }
+ }
+ break;
+ }
+ }
+ }
+
+ return response();
+ }
+}
diff --git a/app/Http/Controllers/Admin/FixLevel0MediaController.php b/app/Http/RequestHandlers/FixLevel0MediaData.php
index f7ef91421a..8a74dea656 100644
--- a/app/Http/Controllers/Admin/FixLevel0MediaController.php
+++ b/app/Http/RequestHandlers/FixLevel0MediaData.php
@@ -17,11 +17,10 @@
declare(strict_types=1);
-namespace Fisharebest\Webtrees\Http\Controllers\Admin;
+namespace Fisharebest\Webtrees\Http\RequestHandlers;
use Fisharebest\Webtrees\Fact;
use Fisharebest\Webtrees\Gedcom;
-use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\Services\DatatablesService;
use Fisharebest\Webtrees\Services\TreeService;
@@ -31,19 +30,19 @@ use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Collection;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\RequestHandlerInterface;
use stdClass;
use function addcslashes;
use function e;
use function in_array;
use function preg_match;
-use function response;
use function view;
/**
- * Controller for fixing media links.
+ * Move media links from records to facts.
*/
-class FixLevel0MediaController extends AbstractAdminController
+class FixLevel0MediaData implements RequestHandlerInterface
{
/** @var DatatablesService */
private $datatables_service;
@@ -71,59 +70,7 @@ class FixLevel0MediaController extends AbstractAdminController
*
* @return ResponseInterface
*/
- public function fixLevel0Media(ServerRequestInterface $request): ResponseInterface
- {
- return $this->viewResponse('admin/fix-level-0-media', [
- 'title' => I18N::translate('Link media objects to facts and events'),
- ]);
- }
-
- /**
- * Move a link to a media object from a level 0 record to a level 1 record.
- *
- * @param ServerRequestInterface $request
- *
- * @return ResponseInterface
- */
- public function fixLevel0MediaAction(ServerRequestInterface $request): ResponseInterface
- {
- $params = (array) $request->getParsedBody();
-
- $fact_id = $params['fact_id'];
- $indi_xref = $params['indi_xref'];
- $obje_xref = $params['obje_xref'];
- $tree_id = (int) $params['tree_id'];
-
- $tree = $this->tree_service->find($tree_id);
- $individual = Registry::individualFactory()->make($indi_xref, $tree);
- $media = Registry::mediaFactory()->make($obje_xref, $tree);
-
- if ($individual !== null && $media !== null) {
- foreach ($individual->facts() as $fact1) {
- if ($fact1->id() === $fact_id) {
- $individual->updateFact($fact_id, $fact1->gedcom() . "\n2 OBJE @" . $obje_xref . '@', false);
- foreach ($individual->facts(['OBJE']) as $fact2) {
- if ($fact2->target() === $media) {
- $individual->deleteFact($fact2->id(), false);
- }
- }
- break;
- }
- }
- }
-
- return response();
- }
-
- /**
- * If media objects are wronly linked to top-level records, reattach them
- * to facts/events.
- *
- * @param ServerRequestInterface $request
- *
- * @return ResponseInterface
- */
- public function fixLevel0MediaData(ServerRequestInterface $request): ResponseInterface
+ public function handle(ServerRequestInterface $request): ResponseInterface
{
$ignore_facts = [
'NAME',
diff --git a/app/Http/RequestHandlers/FixLevel0MediaPage.php b/app/Http/RequestHandlers/FixLevel0MediaPage.php
new file mode 100644
index 0000000000..48dbab1e78
--- /dev/null
+++ b/app/Http/RequestHandlers/FixLevel0MediaPage.php
@@ -0,0 +1,51 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Http\RequestHandlers;
+
+use Fisharebest\Webtrees\Http\ViewResponseTrait;
+use Fisharebest\Webtrees\I18N;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+
+/**
+ * Move media links from records to facts.
+ */
+class FixLevel0MediaPage implements RequestHandlerInterface
+{
+ use ViewResponseTrait;
+
+ /**
+ * If media objects are wronly linked to top-level records, reattach them
+ * to facts/events.
+ *
+ * @param ServerRequestInterface $request
+ *
+ * @return ResponseInterface
+ */
+ public function handle(ServerRequestInterface $request): ResponseInterface
+ {
+ $this->layout = 'layouts/administration';
+
+ return $this->viewResponse('admin/fix-level-0-media', [
+ 'title' => I18N::translate('Link media objects to facts and events'),
+ ]);
+ }
+}
diff --git a/app/Http/RequestHandlers/ImportThumbnailsAction.php b/app/Http/RequestHandlers/ImportThumbnailsAction.php
new file mode 100644
index 0000000000..f83ddb7b9c
--- /dev/null
+++ b/app/Http/RequestHandlers/ImportThumbnailsAction.php
@@ -0,0 +1,129 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Http\RequestHandlers;
+
+use Fisharebest\Webtrees\Mime;
+use Fisharebest\Webtrees\Registry;
+use Fisharebest\Webtrees\Services\PendingChangesService;
+use Fisharebest\Webtrees\Services\SearchService;
+use Fisharebest\Webtrees\Services\TreeService;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+
+use function dirname;
+use function explode;
+use function response;
+use function strlen;
+use function substr;
+
+/**
+ * Import custom thumbnails from webtrees 1.x.
+ */
+class ImportThumbnailsAction implements RequestHandlerInterface
+{
+ /** @var PendingChangesService */
+ private $pending_changes_service;
+
+ /** @var TreeService */
+ private $tree_service;
+
+ /**
+ * ImportThumbnailsController constructor.
+ *
+ * @param PendingChangesService $pending_changes_service
+ * @param TreeService $tree_service
+ */
+ public function __construct(
+ PendingChangesService $pending_changes_service,
+ TreeService $tree_service
+ ) {
+ $this->pending_changes_service = $pending_changes_service;
+ $this->tree_service = $tree_service;
+ }
+
+ /**
+ * Import custom thumbnails from webtrees 1.x.
+ *
+ * @param ServerRequestInterface $request
+ *
+ * @return ResponseInterface
+ */
+ public function handle(ServerRequestInterface $request): ResponseInterface
+ {
+ $data_filesystem = Registry::filesystem()->data();
+
+ $params = (array) $request->getParsedBody();
+
+ $thumbnail = $params['thumbnail'];
+ $action = $params['action'];
+ $xrefs = $params['xref'];
+ $geds = $params['ged'];
+
+ if (!$data_filesystem->has($thumbnail)) {
+ return response([]);
+ }
+
+ $media_objects = [];
+
+ foreach ($xrefs as $key => $xref) {
+ $tree = $this->tree_service->all()->get($geds[$key]);
+ $media_objects[] = Registry::mediaFactory()->make($xref, $tree);
+ }
+
+ switch ($action) {
+ case 'delete':
+ $data_filesystem->delete($thumbnail);
+ break;
+
+ case 'add':
+ $mime_type = $data_filesystem->getMimetype($thumbnail) ?: Mime::DEFAULT_TYPE;
+ $directory = dirname($thumbnail, 2);
+ $sha1 = sha1($data_filesystem->read($thumbnail));
+ $extension = explode('/', $mime_type)[1];
+ $move_to = $directory . '/' . $sha1 . '.' . $extension;
+
+ $data_filesystem->rename($thumbnail, $move_to);
+
+ foreach ($media_objects as $media_object) {
+ $prefix = $media_object->tree()->getPreference('MEDIA_DIRECTORY');
+ $gedcom = '1 FILE ' . substr($move_to, strlen($prefix)) . "\n2 FORM " . $extension;
+
+ if ($media_object->firstImageFile() === null) {
+ // The media object doesn't have an image. Add this as a secondary file.
+ $media_object->createFact($gedcom, true);
+ } else {
+ // The media object already has an image. Show this custom one in preference.
+ $gedcom = '0 @' . $media_object->xref() . "@ OBJE\n" . $gedcom;
+ foreach ($media_object->facts() as $fact) {
+ $gedcom .= "\n" . $fact->gedcom();
+ }
+ $media_object->updateRecord($gedcom, true);
+ }
+
+ // Accept the changes, to keep the filesystem in sync with the GEDCOM data.
+ $this->pending_changes_service->acceptRecord($media_object);
+ }
+ break;
+ }
+
+ return response([]);
+ }
+}
diff --git a/app/Http/Controllers/Admin/ImportThumbnailsController.php b/app/Http/RequestHandlers/ImportThumbnailsData.php
index d7838cdf7e..f1dad92f17 100644
--- a/app/Http/Controllers/Admin/ImportThumbnailsController.php
+++ b/app/Http/RequestHandlers/ImportThumbnailsData.php
@@ -17,25 +17,22 @@
declare(strict_types=1);
-namespace Fisharebest\Webtrees\Http\Controllers\Admin;
+namespace Fisharebest\Webtrees\Http\RequestHandlers;
-use Fisharebest\Webtrees\Http\RequestHandlers\AdminMediaFileThumbnail;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Media;
use Fisharebest\Webtrees\Mime;
use Fisharebest\Webtrees\Registry;
-use Fisharebest\Webtrees\Services\PendingChangesService;
use Fisharebest\Webtrees\Services\SearchService;
-use Fisharebest\Webtrees\Services\TreeService;
use Illuminate\Support\Collection;
use Intervention\Image\ImageManager;
use League\Flysystem\FilesystemInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\RequestHandlerInterface;
use function abs;
use function array_map;
-use function dirname;
use function e;
use function explode;
use function glob;
@@ -48,7 +45,6 @@ use function route;
use function str_contains;
use function str_replace;
use function stripos;
-use function strlen;
use function substr;
use function substr_compare;
use function view;
@@ -56,128 +52,33 @@ use function view;
use const GLOB_NOSORT;
/**
- * Controller for importing custom thumbnails from webtrees 1.x.
+ * Import custom thumbnails from webtrees 1.x.
*/
-class ImportThumbnailsController extends AbstractAdminController
+class ImportThumbnailsData implements RequestHandlerInterface
{
private const FINGERPRINT_PIXELS = 10;
- /** @var PendingChangesService */
- private $pending_changes_service;
-
/** @var SearchService */
private $search_service;
- /** @var TreeService */
- private $tree_service;
-
- /**
- * ImportThumbnailsController constructor.
- *
- * @param PendingChangesService $pending_changes_service
- * @param SearchService $search_service
- * @param TreeService $tree_service
- */
- public function __construct(
- PendingChangesService $pending_changes_service,
- SearchService $search_service,
- TreeService $tree_service
- ) {
- $this->pending_changes_service = $pending_changes_service;
- $this->search_service = $search_service;
- $this->tree_service = $tree_service;
- }
-
/**
- * Import custom thumbnails from webtres 1.x.
+ * ImportThumbnailsData constructor.
*
- * @param ServerRequestInterface $request
- *
- * @return ResponseInterface
+ * @param SearchService $search_service
*/
- public function webtrees1Thumbnails(ServerRequestInterface $request): ResponseInterface
+ public function __construct(SearchService $search_service)
{
- return $this->viewResponse('admin/webtrees1-thumbnails', [
- 'title' => I18N::translate('Import custom thumbnails from webtrees version 1'),
- ]);
- }
-
- /**
- * Import custom thumbnails from webtres 1.x.
- *
- * @param ServerRequestInterface $request
- *
- * @return ResponseInterface
- */
- public function webtrees1ThumbnailsAction(ServerRequestInterface $request): ResponseInterface
- {
- $data_filesystem = Registry::filesystem()->data();
-
- $params = (array) $request->getParsedBody();
-
- $thumbnail = $params['thumbnail'];
- $action = $params['action'];
- $xrefs = $params['xref'];
- $geds = $params['ged'];
-
- if (!$data_filesystem->has($thumbnail)) {
- return response([]);
- }
-
- $media_objects = [];
-
- foreach ($xrefs as $key => $xref) {
- $tree = $this->tree_service->all()->get($geds[$key]);
- $media_objects[] = Registry::mediaFactory()->make($xref, $tree);
- }
-
- switch ($action) {
- case 'delete':
- $data_filesystem->delete($thumbnail);
- break;
-
- case 'add':
- $mime_type = $data_filesystem->getMimetype($thumbnail) ?: Mime::DEFAULT_TYPE;
- $directory = dirname($thumbnail, 2);
- $sha1 = sha1($data_filesystem->read($thumbnail));
- $extension = explode('/', $mime_type)[1];
- $move_to = $directory . '/' . $sha1 . '.' . $extension;
-
- $data_filesystem->rename($thumbnail, $move_to);
-
- foreach ($media_objects as $media_object) {
- $prefix = $media_object->tree()->getPreference('MEDIA_DIRECTORY');
- $gedcom = '1 FILE ' . substr($move_to, strlen($prefix)) . "\n2 FORM " . $extension;
-
- if ($media_object->firstImageFile() === null) {
- // The media object doesn't have an image. Add this as a secondary file.
- $media_object->createFact($gedcom, true);
- } else {
- // The media object already has an image. Show this custom one in preference.
- $gedcom = '0 @' . $media_object->xref() . "@ OBJE\n" . $gedcom;
- foreach ($media_object->facts() as $fact) {
- $gedcom .= "\n" . $fact->gedcom();
- }
- $media_object->updateRecord($gedcom, true);
- }
-
- // Accept the changes, to keep the filesystem in sync with the GEDCOM data.
- $this->pending_changes_service->acceptRecord($media_object);
- }
- break;
- }
-
- return response([]);
+ $this->search_service = $search_service;
}
/**
- * Import custom thumbnails from webtres 1.x.
+ * Import custom thumbnails from webtrees 1.x.
*
* @param ServerRequestInterface $request
*
* @return ResponseInterface
*/
- public function webtrees1ThumbnailsData(ServerRequestInterface $request): ResponseInterface
+ public function handle(ServerRequestInterface $request): ResponseInterface
{
$data_filesystem = Registry::filesystem()->data();
@@ -233,7 +134,7 @@ class ImportThumbnailsController extends AbstractAdminController
'<img src="' . e($thumbnail_url) . '" title="' . e($thumbnail) . '">',
'<img src="' . e($original_url) . '" title="' . e($original) . '">',
$media_links,
- I18N::percentage($difference / 100.0, 0),
+ I18N::percentage($difference / 100.0),
$action,
];
});
diff --git a/app/Http/RequestHandlers/ImportThumbnailsPage.php b/app/Http/RequestHandlers/ImportThumbnailsPage.php
new file mode 100644
index 0000000000..d8203967e7
--- /dev/null
+++ b/app/Http/RequestHandlers/ImportThumbnailsPage.php
@@ -0,0 +1,50 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Http\RequestHandlers;
+
+use Fisharebest\Webtrees\Http\ViewResponseTrait;
+use Fisharebest\Webtrees\I18N;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+
+/**
+ * Import custom thumbnails from webtrees 1.x.
+ */
+class ImportThumbnailsPage implements RequestHandlerInterface
+{
+ use ViewResponseTrait;
+
+ /**
+ * Import custom thumbnails from webtrees 1.x.
+ *
+ * @param ServerRequestInterface $request
+ *
+ * @return ResponseInterface
+ */
+ public function handle(ServerRequestInterface $request): ResponseInterface
+ {
+ $this->layout = 'layouts/administration';
+
+ return $this->viewResponse('admin/webtrees1-thumbnails', [
+ 'title' => I18N::translate('Import custom thumbnails from webtrees version 1'),
+ ]);
+ }
+}
diff --git a/app/Http/RequestHandlers/LoginAction.php b/app/Http/RequestHandlers/LoginAction.php
index db9e24966c..7ab0b47dba 100644
--- a/app/Http/RequestHandlers/LoginAction.php
+++ b/app/Http/RequestHandlers/LoginAction.php
@@ -80,7 +80,7 @@ class LoginAction implements RequestHandlerInterface
$this->doLogin($username, $password);
if (Auth::isAdmin() && $this->upgrade_service->isUpgradeAvailable()) {
- FlashMessages::addMessage(I18N::translate('A new version of webtrees is available.') . ' <a class="alert-link" href="' . e(route('upgrade')) . '">' . I18N::translate('Upgrade to webtrees %s.', '<span dir="ltr">' . $this->upgrade_service->latestVersion() . '</span>') . '</a>');
+ FlashMessages::addMessage(I18N::translate('A new version of webtrees is available.') . ' <a class="alert-link" href="' . e(route(UpgradeWizardPage::class)) . '">' . I18N::translate('Upgrade to webtrees %s.', '<span dir="ltr">' . $this->upgrade_service->latestVersion() . '</span>') . '</a>');
}
// Redirect to the target URL
diff --git a/app/Http/Controllers/AbstractBaseController.php b/app/Http/RequestHandlers/UpgradeWizardConfirm.php
index 3eab67ea54..1eb718258f 100644
--- a/app/Http/Controllers/AbstractBaseController.php
+++ b/app/Http/RequestHandlers/UpgradeWizardConfirm.php
@@ -17,14 +17,27 @@
declare(strict_types=1);
-namespace Fisharebest\Webtrees\Http\Controllers;
+namespace Fisharebest\Webtrees\Http\RequestHandlers;
-use Fisharebest\Webtrees\Http\ViewResponseTrait;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+
+use function redirect;
+use function route;
/**
- * Common functions for all controllers
+ * Upgrade to a new version of webtrees.
*/
-abstract class AbstractBaseController
+class UpgradeWizardConfirm implements RequestHandlerInterface
{
- use ViewResponseTrait;
+ /**
+ * @param ServerRequestInterface $request
+ *
+ * @return ResponseInterface
+ */
+ public function handle(ServerRequestInterface $request): ResponseInterface
+ {
+ return redirect(route(UpgradeWizardPage::class, ['continue' => 1]));
+ }
}
diff --git a/app/Http/RequestHandlers/UpgradeWizardPage.php b/app/Http/RequestHandlers/UpgradeWizardPage.php
new file mode 100644
index 0000000000..179731ffc3
--- /dev/null
+++ b/app/Http/RequestHandlers/UpgradeWizardPage.php
@@ -0,0 +1,130 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2021 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 <https://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 Fisharebest\Webtrees\Services\UpgradeService;
+use Fisharebest\Webtrees\Webtrees;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+
+use function basename;
+use function e;
+use function route;
+use function version_compare;
+
+/**
+ * Upgrade to a new version of webtrees.
+ */
+class UpgradeWizardPage implements RequestHandlerInterface
+{
+ use ViewResponseTrait;
+
+ // We make the upgrade in a number of small steps to keep within server time limits.
+ private const STEP_CHECK = 'Check';
+ private const STEP_PREPARE = 'Prepare';
+ private const STEP_PENDING = 'Pending';
+ private const STEP_EXPORT = 'Export';
+ private const STEP_DOWNLOAD = 'Download';
+ private const STEP_UNZIP = 'Unzip';
+ private const STEP_COPY = 'Copy';
+
+ /** @var UpgradeService */
+ private $upgrade_service;
+
+ /** @var TreeService */
+ private $tree_service;
+
+ /**
+ * UpgradeController constructor.
+ *
+ * @param TreeService $tree_service
+ * @param UpgradeService $upgrade_service
+ */
+ public function __construct(TreeService $tree_service, UpgradeService $upgrade_service)
+ {
+ $this->tree_service = $tree_service;
+ $this->upgrade_service = $upgrade_service;
+ }
+
+ /**
+ * @param ServerRequestInterface $request
+ *
+ * @return ResponseInterface
+ */
+ public function handle(ServerRequestInterface $request): ResponseInterface
+ {
+ $this->layout = 'layouts/administration';
+
+ $continue = $request->getQueryParams()['continue'] ?? '';
+
+ $title = I18N::translate('Upgrade wizard');
+
+ $latest_version = $this->upgrade_service->latestVersion();
+
+ $upgrade_available = version_compare($latest_version, Webtrees::VERSION) > 0;
+
+ if ($upgrade_available && $continue === '1') {
+ return $this->viewResponse('admin/upgrade/steps', [
+ 'steps' => $this->wizardSteps(),
+ 'title' => $title,
+ ]);
+ }
+
+ return $this->viewResponse('admin/upgrade/wizard', [
+ 'current_version' => Webtrees::VERSION,
+ 'latest_version' => $latest_version,
+ 'title' => $title,
+ ]);
+ }
+
+
+ /**
+ * @return string[]
+ */
+ private function wizardSteps(): array
+ {
+ $download_url = $this->upgrade_service->downloadUrl();
+
+ $export_steps = [];
+
+ foreach ($this->tree_service->all() as $tree) {
+ $route = route(UpgradeWizardStep::class, [
+ 'step' => self::STEP_EXPORT,
+ 'tree' => $tree->name(),
+ ]);
+
+ $export_steps[$route] = I18N::translate('Export all the family trees to GEDCOM files…') . ' ' . e($tree->title());
+ }
+
+ return [
+ route(UpgradeWizardStep::class, ['step' => self::STEP_CHECK]) => I18N::translate('Upgrade wizard'),
+ route(UpgradeWizardStep::class, ['step' => self::STEP_PREPARE]) => I18N::translate('Create a temporary folder…'),
+ route(UpgradeWizardStep::class, ['step' => self::STEP_PENDING]) => I18N::translate('Check for pending changes…'),
+ ] + $export_steps + [
+ route(UpgradeWizardStep::class, ['step' => self::STEP_DOWNLOAD]) => I18N::translate('Download %s…', e($download_url)),
+ route(UpgradeWizardStep::class, ['step' => self::STEP_UNZIP]) => I18N::translate('Unzip %s to a temporary folder…', e(basename($download_url))),
+ route(UpgradeWizardStep::class, ['step' => self::STEP_COPY]) => I18N::translate('Copy files…'),
+ ];
+ }
+}
diff --git a/app/Http/Controllers/Admin/UpgradeController.php b/app/Http/RequestHandlers/UpgradeWizardStep.php
index 0aea821d2d..5ef9b82f11 100644
--- a/app/Http/Controllers/Admin/UpgradeController.php
+++ b/app/Http/RequestHandlers/UpgradeWizardStep.php
@@ -17,12 +17,11 @@
declare(strict_types=1);
-namespace Fisharebest\Webtrees\Http\Controllers\Admin;
+namespace Fisharebest\Webtrees\Http\RequestHandlers;
use Fig\Http\Message\StatusCodeInterface;
use Fisharebest\Flysystem\Adapter\ChrootAdapter;
use Fisharebest\Webtrees\Exceptions\HttpServerErrorException;
-use Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\Services\GedcomExportService;
@@ -36,11 +35,11 @@ use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\RequestHandlerInterface;
use RuntimeException;
use Throwable;
use function assert;
-use function basename;
use function date;
use function e;
use function fclose;
@@ -48,16 +47,15 @@ use function fopen;
use function fseek;
use function intdiv;
use function microtime;
-use function redirect;
use function response;
use function route;
use function version_compare;
use function view;
/**
- * Controller for upgrading to a new version of webtrees.
+ * Upgrade to a new version of webtrees.
*/
-class UpgradeController extends AbstractAdminController
+class UpgradeWizardStep implements RequestHandlerInterface
{
// We make the upgrade in a number of small steps to keep within server time limits.
private const STEP_CHECK = 'Check';
@@ -111,55 +109,15 @@ class UpgradeController extends AbstractAdminController
}
/**
- * @param ServerRequestInterface $request
- *
- * @return ResponseInterface
- */
- public function wizard(ServerRequestInterface $request): ResponseInterface
- {
- $continue = $request->getQueryParams()['continue'] ?? '';
-
- $title = I18N::translate('Upgrade wizard');
-
- $latest_version = $this->upgrade_service->latestVersion();
-
- $upgrade_available = version_compare($latest_version, Webtrees::VERSION) > 0;
-
- if ($upgrade_available && $continue === '1') {
- return $this->viewResponse('admin/upgrade/steps', [
- 'steps' => $this->wizardSteps(),
- 'title' => $title,
- ]);
- }
-
- return $this->viewResponse('admin/upgrade/wizard', [
- 'current_version' => Webtrees::VERSION,
- 'latest_version' => $latest_version,
- 'title' => $title,
- ]);
- }
-
- /**
- * @param ServerRequestInterface $request
- *
- * @return ResponseInterface
- */
- public function confirm(ServerRequestInterface $request): ResponseInterface
- {
- return redirect(route('upgrade', ['continue' => 1]));
- }
-
- /**
* Perform one step of the wizard
*
* @param ServerRequestInterface $request
*
* @return ResponseInterface
*/
- public function step(ServerRequestInterface $request): ResponseInterface
+ public function handle(ServerRequestInterface $request): ResponseInterface
{
$root_filesystem = Registry::filesystem()->root();
-
$data_filesystem = Registry::filesystem()->data();
// Somewhere to unpack a .ZIP file
@@ -203,35 +161,6 @@ class UpgradeController extends AbstractAdminController
}
/**
- * @return string[]
- */
- private function wizardSteps(): array
- {
- $download_url = $this->upgrade_service->downloadUrl();
-
- $export_steps = [];
-
- foreach ($this->tree_service->all() as $tree) {
- $route = route('upgrade', [
- 'step' => self::STEP_EXPORT,
- 'tree' => $tree->name(),
- ]);
-
- $export_steps[$route] = I18N::translate('Export all the family trees to GEDCOM files…') . ' ' . e($tree->title());
- }
-
- return [
- route('upgrade', ['step' => self::STEP_CHECK]) => I18N::translate('Upgrade wizard'),
- route('upgrade', ['step' => self::STEP_PREPARE]) => I18N::translate('Create a temporary folder…'),
- route('upgrade', ['step' => self::STEP_PENDING]) => I18N::translate('Check for pending changes…'),
- ] + $export_steps + [
- route('upgrade', ['step' => self::STEP_DOWNLOAD]) => I18N::translate('Download %s…', e($download_url)),
- route('upgrade', ['step' => self::STEP_UNZIP]) => I18N::translate('Unzip %s to a temporary folder…', e(basename($download_url))),
- route('upgrade', ['step' => self::STEP_COPY]) => I18N::translate('Copy files…'),
- ];
- }
-
- /**
* @return ResponseInterface
*/
private function wizardStepCheck(): ResponseInterface
@@ -390,7 +319,7 @@ class UpgradeController extends AbstractAdminController
$this->upgrade_service->cleanFiles($root_filesystem, $folders_to_clean, $files_to_keep);
$url = route(ControlPanel::class);
- $alert = I18N::translate('The upgrade is complete.');
+ $alert = I18N::translate('The upgrade is complete.');
$button = '<a href="' . e($url) . '" class="btn btn-primary">' . I18N::translate('continue') . '</a>';
return response(view('components/alert-success', [
diff --git a/app/Http/Routes/WebRoutes.php b/app/Http/Routes/WebRoutes.php
index 6c21204f8a..df98e76bcf 100644
--- a/app/Http/Routes/WebRoutes.php
+++ b/app/Http/Routes/WebRoutes.php
@@ -109,6 +109,9 @@ use Fisharebest\Webtrees\Http\RequestHandlers\ExportGedcomServer;
use Fisharebest\Webtrees\Http\RequestHandlers\FamilyPage;
use Fisharebest\Webtrees\Http\RequestHandlers\FaviconIco;
use Fisharebest\Webtrees\Http\RequestHandlers\FindDuplicateRecords;
+use Fisharebest\Webtrees\Http\RequestHandlers\FixLevel0MediaAction;
+use Fisharebest\Webtrees\Http\RequestHandlers\FixLevel0MediaData;
+use Fisharebest\Webtrees\Http\RequestHandlers\FixLevel0MediaPage;
use Fisharebest\Webtrees\Http\RequestHandlers\GedcomLoad;
use Fisharebest\Webtrees\Http\RequestHandlers\GedcomRecordPage;
use Fisharebest\Webtrees\Http\RequestHandlers\HeaderPage;
@@ -116,6 +119,9 @@ use Fisharebest\Webtrees\Http\RequestHandlers\HelpText;
use Fisharebest\Webtrees\Http\RequestHandlers\HomePage;
use Fisharebest\Webtrees\Http\RequestHandlers\ImportGedcomAction;
use Fisharebest\Webtrees\Http\RequestHandlers\ImportGedcomPage;
+use Fisharebest\Webtrees\Http\RequestHandlers\ImportThumbnailsAction;
+use Fisharebest\Webtrees\Http\RequestHandlers\ImportThumbnailsData;
+use Fisharebest\Webtrees\Http\RequestHandlers\ImportThumbnailsPage;
use Fisharebest\Webtrees\Http\RequestHandlers\IndividualPage;
use Fisharebest\Webtrees\Http\RequestHandlers\LinkChildToFamilyAction;
use Fisharebest\Webtrees\Http\RequestHandlers\LinkChildToFamilyPage;
@@ -273,6 +279,9 @@ use Fisharebest\Webtrees\Http\RequestHandlers\TreePrivacyAction;
use Fisharebest\Webtrees\Http\RequestHandlers\TreePrivacyPage;
use Fisharebest\Webtrees\Http\RequestHandlers\UnconnectedAction;
use Fisharebest\Webtrees\Http\RequestHandlers\UnconnectedPage;
+use Fisharebest\Webtrees\Http\RequestHandlers\UpgradeWizardConfirm;
+use Fisharebest\Webtrees\Http\RequestHandlers\UpgradeWizardPage;
+use Fisharebest\Webtrees\Http\RequestHandlers\UpgradeWizardStep;
use Fisharebest\Webtrees\Http\RequestHandlers\UploadMediaAction;
use Fisharebest\Webtrees\Http\RequestHandlers\UploadMediaPage;
use Fisharebest\Webtrees\Http\RequestHandlers\UserAddAction;
@@ -316,6 +325,9 @@ class WebRoutes
$router->post(DeletePath::class, '/delete-path');
$router->get(EmailPreferencesPage::class, '/email');
$router->post(EmailPreferencesAction::class, '/email');
+ $router->get(FixLevel0MediaPage::class, '/fix-level-0-media');
+ $router->post(FixLevel0MediaAction::class, '/fix-level-0-media');
+ $router->get(FixLevel0MediaData::class, '/fix-level-0-media-data');
$router->get(PhpInformation::class, '/information');
$router->get(SiteLogsPage::class, '/logs');
$router->post(SiteLogsAction::class, '/logs');
@@ -334,12 +346,9 @@ class WebRoutes
$router->post(CreateTreeAction::class, '/trees/create');
$router->post(SelectDefaultTree::class, '/trees/default/{tree}');
$router->post(DeleteTreeAction::class, '/trees/delete/{tree}');
- $router->get('admin-fix-level-0-media', '/fix-level-0-media', 'Admin\FixLevel0MediaController::fixLevel0Media');
- $router->post('admin-fix-level-0-media-action', '/fix-level-0-media', 'Admin\FixLevel0MediaController::fixLevel0MediaAction');
- $router->get('admin-fix-level-0-media-data', '/fix-level-0-media-data', 'Admin\FixLevel0MediaController::fixLevel0MediaData');
- $router->get('admin-webtrees1-thumbs', '/webtrees1-thumbs', 'Admin\ImportThumbnailsController::webtrees1Thumbnails');
- $router->post('admin-webtrees1-thumbs-action', '/webtrees1-thumbs', 'Admin\ImportThumbnailsController::webtrees1ThumbnailsAction');
- $router->get('admin-webtrees1-thumbs-data', '/webtrees1-thumbs-data', 'Admin\ImportThumbnailsController::webtrees1ThumbnailsData');
+ $router->get(ImportThumbnailsPage::class, '/webtrees1-thumbs');
+ $router->post(ImportThumbnailsAction::class, '/webtrees1-thumbs');
+ $router->get(ImportThumbnailsData::class, '/webtrees1-thumbs-data');
$router->get(UsersCleanupPage::class, '/users-cleanup');
$router->post(UsersCleanupAction::class, '/users-cleanup');
$router->get(MapDataAdd::class, '/map-data-add{/parent_id}');
@@ -382,9 +391,9 @@ class WebRoutes
$router->post(ModulesTabsAction::class, '/tabs');
$router->get(ModulesThemesPage::class, '/themes');
$router->post(ModulesThemesAction::class, '/themes');
- $router->get('upgrade', '/upgrade', 'Admin\UpgradeController::wizard');
- $router->post('upgrade-confirm', '/upgrade-confirm', 'Admin\UpgradeController::confirm');
- $router->post('upgrade-action', '/upgrade', 'Admin\UpgradeController::step');
+ $router->get(UpgradeWizardPage::class, '/upgrade');
+ $router->post(UpgradeWizardConfirm::class, '/upgrade-confirm');
+ $router->post(UpgradeWizardStep::class, '/upgrade-action');
$router->get(UserListPage::class, '/admin-users');
$router->get(UserListData::class, '/admin-users-data');
$router->get(UserAddPage::class, '/admin-users-create');