Issues (2502)

app/Http/RequestHandlers/UpgradeWizardPage.php (1 issue)

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