1*4b3ef6caSGreg Roach<?php 2*4b3ef6caSGreg Roach 3*4b3ef6caSGreg Roach/** 4*4b3ef6caSGreg Roach * webtrees: online genealogy 5*4b3ef6caSGreg Roach * Copyright (C) 2021 webtrees development team 6*4b3ef6caSGreg Roach * This program is free software: you can redistribute it and/or modify 7*4b3ef6caSGreg Roach * it under the terms of the GNU General Public License as published by 8*4b3ef6caSGreg Roach * the Free Software Foundation, either version 3 of the License, or 9*4b3ef6caSGreg Roach * (at your option) any later version. 10*4b3ef6caSGreg Roach * This program is distributed in the hope that it will be useful, 11*4b3ef6caSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12*4b3ef6caSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*4b3ef6caSGreg Roach * GNU General Public License for more details. 14*4b3ef6caSGreg Roach * You should have received a copy of the GNU General Public License 15*4b3ef6caSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 16*4b3ef6caSGreg Roach */ 17*4b3ef6caSGreg Roach 18*4b3ef6caSGreg Roachdeclare(strict_types=1); 19*4b3ef6caSGreg Roach 20*4b3ef6caSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 21*4b3ef6caSGreg Roach 22*4b3ef6caSGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 23*4b3ef6caSGreg Roachuse Fisharebest\Webtrees\I18N; 24*4b3ef6caSGreg Roachuse Fisharebest\Webtrees\Services\TreeService; 25*4b3ef6caSGreg Roachuse Fisharebest\Webtrees\Services\UpgradeService; 26*4b3ef6caSGreg Roachuse Fisharebest\Webtrees\Webtrees; 27*4b3ef6caSGreg Roachuse Psr\Http\Message\ResponseInterface; 28*4b3ef6caSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 29*4b3ef6caSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 30*4b3ef6caSGreg Roach 31*4b3ef6caSGreg Roachuse function basename; 32*4b3ef6caSGreg Roachuse function e; 33*4b3ef6caSGreg Roachuse function route; 34*4b3ef6caSGreg Roachuse function version_compare; 35*4b3ef6caSGreg Roach 36*4b3ef6caSGreg Roach/** 37*4b3ef6caSGreg Roach * Upgrade to a new version of webtrees. 38*4b3ef6caSGreg Roach */ 39*4b3ef6caSGreg Roachclass UpgradeWizardPage implements RequestHandlerInterface 40*4b3ef6caSGreg Roach{ 41*4b3ef6caSGreg Roach use ViewResponseTrait; 42*4b3ef6caSGreg Roach 43*4b3ef6caSGreg Roach // We make the upgrade in a number of small steps to keep within server time limits. 44*4b3ef6caSGreg Roach private const STEP_CHECK = 'Check'; 45*4b3ef6caSGreg Roach private const STEP_PREPARE = 'Prepare'; 46*4b3ef6caSGreg Roach private const STEP_PENDING = 'Pending'; 47*4b3ef6caSGreg Roach private const STEP_EXPORT = 'Export'; 48*4b3ef6caSGreg Roach private const STEP_DOWNLOAD = 'Download'; 49*4b3ef6caSGreg Roach private const STEP_UNZIP = 'Unzip'; 50*4b3ef6caSGreg Roach private const STEP_COPY = 'Copy'; 51*4b3ef6caSGreg Roach 52*4b3ef6caSGreg Roach /** @var UpgradeService */ 53*4b3ef6caSGreg Roach private $upgrade_service; 54*4b3ef6caSGreg Roach 55*4b3ef6caSGreg Roach /** @var TreeService */ 56*4b3ef6caSGreg Roach private $tree_service; 57*4b3ef6caSGreg Roach 58*4b3ef6caSGreg Roach /** 59*4b3ef6caSGreg Roach * UpgradeController constructor. 60*4b3ef6caSGreg Roach * 61*4b3ef6caSGreg Roach * @param TreeService $tree_service 62*4b3ef6caSGreg Roach * @param UpgradeService $upgrade_service 63*4b3ef6caSGreg Roach */ 64*4b3ef6caSGreg Roach public function __construct(TreeService $tree_service, UpgradeService $upgrade_service) 65*4b3ef6caSGreg Roach { 66*4b3ef6caSGreg Roach $this->tree_service = $tree_service; 67*4b3ef6caSGreg Roach $this->upgrade_service = $upgrade_service; 68*4b3ef6caSGreg Roach } 69*4b3ef6caSGreg Roach 70*4b3ef6caSGreg Roach /** 71*4b3ef6caSGreg Roach * @param ServerRequestInterface $request 72*4b3ef6caSGreg Roach * 73*4b3ef6caSGreg Roach * @return ResponseInterface 74*4b3ef6caSGreg Roach */ 75*4b3ef6caSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 76*4b3ef6caSGreg Roach { 77*4b3ef6caSGreg Roach $this->layout = 'layouts/administration'; 78*4b3ef6caSGreg Roach 79*4b3ef6caSGreg Roach $continue = $request->getQueryParams()['continue'] ?? ''; 80*4b3ef6caSGreg Roach 81*4b3ef6caSGreg Roach $title = I18N::translate('Upgrade wizard'); 82*4b3ef6caSGreg Roach 83*4b3ef6caSGreg Roach $latest_version = $this->upgrade_service->latestVersion(); 84*4b3ef6caSGreg Roach 85*4b3ef6caSGreg Roach $upgrade_available = version_compare($latest_version, Webtrees::VERSION) > 0; 86*4b3ef6caSGreg Roach 87*4b3ef6caSGreg Roach if ($upgrade_available && $continue === '1') { 88*4b3ef6caSGreg Roach return $this->viewResponse('admin/upgrade/steps', [ 89*4b3ef6caSGreg Roach 'steps' => $this->wizardSteps(), 90*4b3ef6caSGreg Roach 'title' => $title, 91*4b3ef6caSGreg Roach ]); 92*4b3ef6caSGreg Roach } 93*4b3ef6caSGreg Roach 94*4b3ef6caSGreg Roach return $this->viewResponse('admin/upgrade/wizard', [ 95*4b3ef6caSGreg Roach 'current_version' => Webtrees::VERSION, 96*4b3ef6caSGreg Roach 'latest_version' => $latest_version, 97*4b3ef6caSGreg Roach 'title' => $title, 98*4b3ef6caSGreg Roach ]); 99*4b3ef6caSGreg Roach } 100*4b3ef6caSGreg Roach 101*4b3ef6caSGreg Roach 102*4b3ef6caSGreg Roach /** 103*4b3ef6caSGreg Roach * @return string[] 104*4b3ef6caSGreg Roach */ 105*4b3ef6caSGreg Roach private function wizardSteps(): array 106*4b3ef6caSGreg Roach { 107*4b3ef6caSGreg Roach $download_url = $this->upgrade_service->downloadUrl(); 108*4b3ef6caSGreg Roach 109*4b3ef6caSGreg Roach $export_steps = []; 110*4b3ef6caSGreg Roach 111*4b3ef6caSGreg Roach foreach ($this->tree_service->all() as $tree) { 112*4b3ef6caSGreg Roach $route = route(UpgradeWizardStep::class, [ 113*4b3ef6caSGreg Roach 'step' => self::STEP_EXPORT, 114*4b3ef6caSGreg Roach 'tree' => $tree->name(), 115*4b3ef6caSGreg Roach ]); 116*4b3ef6caSGreg Roach 117*4b3ef6caSGreg Roach $export_steps[$route] = I18N::translate('Export all the family trees to GEDCOM files…') . ' ' . e($tree->title()); 118*4b3ef6caSGreg Roach } 119*4b3ef6caSGreg Roach 120*4b3ef6caSGreg Roach return [ 121*4b3ef6caSGreg Roach route(UpgradeWizardStep::class, ['step' => self::STEP_CHECK]) => I18N::translate('Upgrade wizard'), 122*4b3ef6caSGreg Roach route(UpgradeWizardStep::class, ['step' => self::STEP_PREPARE]) => I18N::translate('Create a temporary folder…'), 123*4b3ef6caSGreg Roach route(UpgradeWizardStep::class, ['step' => self::STEP_PENDING]) => I18N::translate('Check for pending changes…'), 124*4b3ef6caSGreg Roach ] + $export_steps + [ 125*4b3ef6caSGreg Roach route(UpgradeWizardStep::class, ['step' => self::STEP_DOWNLOAD]) => I18N::translate('Download %s…', e($download_url)), 126*4b3ef6caSGreg Roach route(UpgradeWizardStep::class, ['step' => self::STEP_UNZIP]) => I18N::translate('Unzip %s to a temporary folder…', e(basename($download_url))), 127*4b3ef6caSGreg Roach route(UpgradeWizardStep::class, ['step' => self::STEP_COPY]) => I18N::translate('Copy files…'), 128*4b3ef6caSGreg Roach ]; 129*4b3ef6caSGreg Roach } 130*4b3ef6caSGreg Roach} 131