14b3ef6caSGreg Roach<?php 24b3ef6caSGreg Roach 34b3ef6caSGreg Roach/** 44b3ef6caSGreg Roach * webtrees: online genealogy 5*5bfc6897SGreg Roach * Copyright (C) 2022 webtrees development team 64b3ef6caSGreg Roach * This program is free software: you can redistribute it and/or modify 74b3ef6caSGreg Roach * it under the terms of the GNU General Public License as published by 84b3ef6caSGreg Roach * the Free Software Foundation, either version 3 of the License, or 94b3ef6caSGreg Roach * (at your option) any later version. 104b3ef6caSGreg Roach * This program is distributed in the hope that it will be useful, 114b3ef6caSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 124b3ef6caSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 134b3ef6caSGreg Roach * GNU General Public License for more details. 144b3ef6caSGreg Roach * You should have received a copy of the GNU General Public License 154b3ef6caSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 164b3ef6caSGreg Roach */ 174b3ef6caSGreg Roach 184b3ef6caSGreg Roachdeclare(strict_types=1); 194b3ef6caSGreg Roach 204b3ef6caSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 214b3ef6caSGreg Roach 224b3ef6caSGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 234b3ef6caSGreg Roachuse Fisharebest\Webtrees\I18N; 244b3ef6caSGreg Roachuse Fisharebest\Webtrees\Services\TreeService; 254b3ef6caSGreg Roachuse Fisharebest\Webtrees\Services\UpgradeService; 264b3ef6caSGreg Roachuse Fisharebest\Webtrees\Webtrees; 274b3ef6caSGreg Roachuse Psr\Http\Message\ResponseInterface; 284b3ef6caSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 294b3ef6caSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 304b3ef6caSGreg Roach 314b3ef6caSGreg Roachuse function basename; 324b3ef6caSGreg Roachuse function e; 334b3ef6caSGreg Roachuse function route; 344b3ef6caSGreg Roachuse function version_compare; 354b3ef6caSGreg Roach 364b3ef6caSGreg Roach/** 374b3ef6caSGreg Roach * Upgrade to a new version of webtrees. 384b3ef6caSGreg Roach */ 394b3ef6caSGreg Roachclass UpgradeWizardPage implements RequestHandlerInterface 404b3ef6caSGreg Roach{ 414b3ef6caSGreg Roach use ViewResponseTrait; 424b3ef6caSGreg Roach 434b3ef6caSGreg Roach // We make the upgrade in a number of small steps to keep within server time limits. 444b3ef6caSGreg Roach private const STEP_CHECK = 'Check'; 454b3ef6caSGreg Roach private const STEP_PREPARE = 'Prepare'; 464b3ef6caSGreg Roach private const STEP_PENDING = 'Pending'; 474b3ef6caSGreg Roach private const STEP_EXPORT = 'Export'; 484b3ef6caSGreg Roach private const STEP_DOWNLOAD = 'Download'; 494b3ef6caSGreg Roach private const STEP_UNZIP = 'Unzip'; 504b3ef6caSGreg Roach private const STEP_COPY = 'Copy'; 514b3ef6caSGreg Roach 52c4943cffSGreg Roach private TreeService $tree_service; 534b3ef6caSGreg Roach 54c4943cffSGreg Roach private UpgradeService $upgrade_service; 554b3ef6caSGreg Roach 564b3ef6caSGreg Roach /** 574b3ef6caSGreg Roach * UpgradeController constructor. 584b3ef6caSGreg Roach * 594b3ef6caSGreg Roach * @param TreeService $tree_service 604b3ef6caSGreg Roach * @param UpgradeService $upgrade_service 614b3ef6caSGreg Roach */ 624b3ef6caSGreg Roach public function __construct(TreeService $tree_service, UpgradeService $upgrade_service) 634b3ef6caSGreg Roach { 644b3ef6caSGreg Roach $this->tree_service = $tree_service; 654b3ef6caSGreg Roach $this->upgrade_service = $upgrade_service; 664b3ef6caSGreg Roach } 674b3ef6caSGreg Roach 684b3ef6caSGreg Roach /** 694b3ef6caSGreg Roach * @param ServerRequestInterface $request 704b3ef6caSGreg Roach * 714b3ef6caSGreg Roach * @return ResponseInterface 724b3ef6caSGreg Roach */ 734b3ef6caSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 744b3ef6caSGreg Roach { 754b3ef6caSGreg Roach $this->layout = 'layouts/administration'; 764b3ef6caSGreg Roach 774b3ef6caSGreg Roach $continue = $request->getQueryParams()['continue'] ?? ''; 784b3ef6caSGreg Roach 794b3ef6caSGreg Roach $title = I18N::translate('Upgrade wizard'); 804b3ef6caSGreg Roach 814b3ef6caSGreg Roach $latest_version = $this->upgrade_service->latestVersion(); 824b3ef6caSGreg Roach 834b3ef6caSGreg Roach $upgrade_available = version_compare($latest_version, Webtrees::VERSION) > 0; 844b3ef6caSGreg Roach 854b3ef6caSGreg Roach if ($upgrade_available && $continue === '1') { 864b3ef6caSGreg Roach return $this->viewResponse('admin/upgrade/steps', [ 874b3ef6caSGreg Roach 'steps' => $this->wizardSteps(), 884b3ef6caSGreg Roach 'title' => $title, 894b3ef6caSGreg Roach ]); 904b3ef6caSGreg Roach } 914b3ef6caSGreg Roach 924b3ef6caSGreg Roach return $this->viewResponse('admin/upgrade/wizard', [ 934b3ef6caSGreg Roach 'current_version' => Webtrees::VERSION, 944b3ef6caSGreg Roach 'latest_version' => $latest_version, 954b3ef6caSGreg Roach 'title' => $title, 964b3ef6caSGreg Roach ]); 974b3ef6caSGreg Roach } 984b3ef6caSGreg Roach 994b3ef6caSGreg Roach 1004b3ef6caSGreg Roach /** 10124f2a3afSGreg Roach * @return array<string> 1024b3ef6caSGreg Roach */ 1034b3ef6caSGreg Roach private function wizardSteps(): array 1044b3ef6caSGreg Roach { 1054b3ef6caSGreg Roach $download_url = $this->upgrade_service->downloadUrl(); 1064b3ef6caSGreg Roach 1074b3ef6caSGreg Roach $export_steps = []; 1084b3ef6caSGreg Roach 1094b3ef6caSGreg Roach foreach ($this->tree_service->all() as $tree) { 1104b3ef6caSGreg Roach $route = route(UpgradeWizardStep::class, [ 1114b3ef6caSGreg Roach 'step' => self::STEP_EXPORT, 1124b3ef6caSGreg Roach 'tree' => $tree->name(), 1134b3ef6caSGreg Roach ]); 1144b3ef6caSGreg Roach 1154b3ef6caSGreg Roach $export_steps[$route] = I18N::translate('Export all the family trees to GEDCOM files…') . ' ' . e($tree->title()); 1164b3ef6caSGreg Roach } 1174b3ef6caSGreg Roach 1184b3ef6caSGreg Roach return [ 1194b3ef6caSGreg Roach route(UpgradeWizardStep::class, ['step' => self::STEP_CHECK]) => I18N::translate('Upgrade wizard'), 1204b3ef6caSGreg Roach route(UpgradeWizardStep::class, ['step' => self::STEP_PREPARE]) => I18N::translate('Create a temporary folder…'), 1214b3ef6caSGreg Roach route(UpgradeWizardStep::class, ['step' => self::STEP_PENDING]) => I18N::translate('Check for pending changes…'), 1224b3ef6caSGreg Roach ] + $export_steps + [ 1234b3ef6caSGreg Roach route(UpgradeWizardStep::class, ['step' => self::STEP_DOWNLOAD]) => I18N::translate('Download %s…', e($download_url)), 1244b3ef6caSGreg Roach route(UpgradeWizardStep::class, ['step' => self::STEP_UNZIP]) => I18N::translate('Unzip %s to a temporary folder…', e(basename($download_url))), 1254b3ef6caSGreg Roach route(UpgradeWizardStep::class, ['step' => self::STEP_COPY]) => I18N::translate('Copy files…'), 1264b3ef6caSGreg Roach ]; 1274b3ef6caSGreg Roach } 1284b3ef6caSGreg Roach} 129