-
-
Notifications
You must be signed in to change notification settings - Fork 137
/
PrepareInstallAction.php
99 lines (87 loc) · 3.55 KB
/
PrepareInstallAction.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
declare(strict_types=1);
namespace Helhum\Typo3Console\Install\Action;
/*
* This file is part of the TYPO3 Console project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read
* LICENSE file that was distributed with this source code.
*
*/
use Helhum\Typo3Console\Mvc\Cli\CommandDispatcher;
use Helhum\Typo3Console\Mvc\Cli\ConsoleOutput;
use Helhum\Typo3Console\Typo3CompatibilityBridge;
use TYPO3\CMS\Core\Core\Environment;
class PrepareInstallAction implements InstallActionInterface
{
/**
* @var ConsoleOutput
*/
private $output;
public function setOutput(ConsoleOutput $output)
{
$this->output = $output;
}
public function setCommandDispatcher(CommandDispatcher $commandDispatcher)
{
// Not needed here
}
public function shouldExecute(array $actionDefinition, array $options = []): bool
{
return true;
}
public function execute(array $actionDefinition, array $options = []): bool
{
$this->ensureInstallationIsPossible($options);
// We don't use Environment API here, because this code is called from Composer plugins
// TYPO3_PATH_ROOT is ensured to be set correctly in CompatibilityClassLoader for non Composer installs
$typo3RootPath = getenv('TYPO3_PATH_ROOT');
$firstInstallPath = $typo3RootPath . '/FIRST_INSTALL';
touch($firstInstallPath);
return true;
}
/**
* Handles the case when system configuration file already exists
*
* @param array $options
* @throws InstallationFailedException
*/
private function ensureInstallationIsPossible(array $options)
{
$integrityCheck = $options['integrityCheck'] ?? false;
if (!$integrityCheck) {
return;
}
$isInteractive = $options['interactive'] ?? $this->output->getSymfonyConsoleInput()->isInteractive();
$forceInstall = $options['forceInstall'] ?? false;
$localConfFile = Typo3CompatibilityBridge::getSystemConfigurationFileLocation();
if (!$forceInstall && file_exists($localConfFile)) {
$this->output->outputLine();
$this->output->outputLine('<error>TYPO3 seems to be already set up!</error>');
$proceed = $isInteractive;
if ($isInteractive) {
$this->output->outputLine();
$this->output->outputLine('<info>If you continue, your system configuration file</info>');
$this->output->outputLine('<warning>will be deleted!</warning>');
$this->output->outputLine();
$proceed = $this->output->askConfirmation('<info>Do you really want to proceed?</info> (<comment>no</comment>) ', false);
}
if (!$proceed) {
$this->output->outputLine('<error>Installation aborted!</error>');
throw new InstallationFailedException('Installation aborted by user', 1529926774);
}
}
@unlink($localConfFile);
clearstatcache();
if (file_exists($localConfFile)) {
$this->output->outputLine();
$this->output->outputLine('<error>Unable to delete configuration file!</error>');
$this->output->outputLine('<error>Installation aborted!</error>');
throw new InstallationFailedException('Installation aborted because of insufficient permissions', 1529926810);
}
}
}