|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SymphonyCms\Installer\Lib; |
|
4
|
|
|
|
|
5
|
|
|
use Configuration; |
|
6
|
|
|
use DateTimeObj; |
|
7
|
|
|
use Exception; |
|
8
|
|
|
use Lang; |
|
9
|
|
|
use Psr\Log\LoggerInterface; |
|
10
|
|
|
use Symphony; |
|
11
|
|
|
use SymphonyCms\Installer\Steps; |
|
12
|
|
|
|
|
13
|
|
|
class ConsoleInstaller |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var LoggerInterface |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $logger; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var Configuration |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $configuration; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var bool |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $overwrite = false; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param LoggerInterface $logger |
|
32
|
|
|
* @param Configuration $configuration |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct(LoggerInterface $logger, Configuration $configuration) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->logger = $logger; |
|
37
|
|
|
$this->configuration = $configuration; |
|
38
|
|
|
|
|
39
|
|
|
// Symphony expects a couple of constants to always exist, so lets do a basic bootstrap. |
|
40
|
|
|
$this->bootstrap(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Allow the Installer and it's steps to attempt to install Symphony at all costs, |
|
45
|
|
|
* including removing and deleting existing data. Use with caution. |
|
46
|
|
|
* |
|
47
|
|
|
* @param bool $overwrite |
|
48
|
|
|
* @return $this |
|
49
|
|
|
*/ |
|
50
|
|
|
public function setOverride($overwrite = false) |
|
51
|
|
|
{ |
|
52
|
|
|
$this->overwrite = $overwrite; |
|
53
|
|
|
|
|
54
|
|
|
return $this; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Installs Symphony using the configuration information available. |
|
59
|
|
|
* |
|
60
|
|
|
* @param array $data |
|
61
|
|
|
* @return bool |
|
62
|
|
|
*/ |
|
63
|
|
|
public function install(array $data) |
|
64
|
|
|
{ |
|
65
|
|
|
$steps = [ |
|
66
|
|
|
// Create database |
|
67
|
|
|
Steps\CreateDatabase::class, |
|
68
|
|
|
// Create manifest folder structure |
|
69
|
|
|
Steps\CreateManifest::class, |
|
70
|
|
|
// Write .htaccess |
|
71
|
|
|
Steps\CreateHtaccess::class, |
|
72
|
|
|
// Create or import the workspace |
|
73
|
|
|
Steps\Workspace::class, |
|
74
|
|
|
// Enable extensions |
|
75
|
|
|
Steps\EnableExtensions::class |
|
76
|
|
|
]; |
|
77
|
|
|
|
|
78
|
|
|
try { |
|
79
|
|
|
foreach ($steps as $step) { |
|
80
|
|
|
$installStep = new $step($this->logger); |
|
81
|
|
|
$installStep->setOverride($this->overwrite); |
|
82
|
|
|
|
|
83
|
|
View Code Duplication |
if (false === $installStep->handle($this->configuration, $data)) { |
|
84
|
|
|
throw new Exception(sprintf('Aborting installation, %s step failed.', $step)); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
} catch (Exception $ex) { |
|
88
|
|
|
$this->logger->error($ex->getMessage()); |
|
89
|
|
|
return false; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
if (false === Symphony::Configuration()->write(CONFIG, $this->configuration->get('write_mode', 'file'))) { |
|
|
|
|
|
|
93
|
|
|
$this->logger->error('Could not create config file ‘' . CONFIG . '’. Check permission on /manifest.'); |
|
94
|
|
|
return false; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
$this->logger->info('Symphony has been installed.'); |
|
98
|
|
|
return true; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Bootstrap the environment to the bare minimum for Symphony to 'run'. |
|
103
|
|
|
*/ |
|
104
|
|
|
private function bootstrap() |
|
105
|
|
|
{ |
|
106
|
|
|
// Initialize date/time |
|
107
|
|
|
define_safe('__SYM_DATE_FORMAT__', $this->configuration->get('date_format', 'region')); |
|
|
|
|
|
|
108
|
|
|
define_safe('__SYM_TIME_FORMAT__', $this->configuration->get('time_format', 'region')); |
|
|
|
|
|
|
109
|
|
|
define_safe( |
|
110
|
|
|
'__SYM_DATETIME_FORMAT__', |
|
111
|
|
|
__SYM_DATE_FORMAT__ . $this->configuration->get('datetime_separator', 'region') . __SYM_TIME_FORMAT__ |
|
112
|
|
|
); |
|
113
|
|
|
DateTimeObj::setSettings($this->configuration->get('region')); |
|
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
Lang::initialize(); |
|
116
|
|
|
Symphony::setDatabase(); |
|
117
|
|
|
Symphony::initialiseExtensionManager(); |
|
118
|
|
|
Symphony::initialiseConfiguration($this->configuration->get()); |
|
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
define('INSTALL', DOCROOT . '/install'); |
|
121
|
|
|
define('INSTALL_LOGS', MANIFEST . '/logs'); |
|
122
|
|
|
define('INSTALL_URL', URL . '/install'); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: