1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
require_once CORE . "/class.administration.php"; |
4
|
|
|
|
5
|
|
|
class Installer extends Administration |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Override the default Symphony constructor to initialise the Log, Config |
9
|
|
|
* and Database objects for installation/update. This allows us to use the |
10
|
|
|
* normal accessors. |
11
|
|
|
*/ |
12
|
|
|
protected function __construct() |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
self::$Profiler = Profiler::instance(); |
15
|
|
|
self::$Profiler->sample('Engine Initialisation'); |
16
|
|
|
|
17
|
|
|
if (get_magic_quotes_gpc()) { |
18
|
|
|
General::cleanArray($_SERVER); |
19
|
|
|
General::cleanArray($_COOKIE); |
20
|
|
|
General::cleanArray($_GET); |
21
|
|
|
General::cleanArray($_POST); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
// Include the default Config for installation. |
25
|
|
|
include(INSTALL . '/includes/config_default.php'); |
26
|
|
|
static::initialiseConfiguration($settings); |
|
|
|
|
27
|
|
|
|
28
|
|
|
// Initialize date/time |
29
|
|
|
define_safe('__SYM_DATE_FORMAT__', self::Configuration()->get('date_format', 'region')); |
|
|
|
|
30
|
|
|
define_safe('__SYM_TIME_FORMAT__', self::Configuration()->get('time_format', 'region')); |
|
|
|
|
31
|
|
|
define_safe('__SYM_DATETIME_FORMAT__', __SYM_DATE_FORMAT__ . self::Configuration()->get('datetime_separator', 'region') . __SYM_TIME_FORMAT__); |
32
|
|
|
DateTimeObj::setSettings(self::Configuration()->get('region')); |
|
|
|
|
33
|
|
|
|
34
|
|
|
// Initialize Language, Logs and Database |
35
|
|
|
static::initialiseLang(); |
36
|
|
|
static::initialiseLog(INSTALL_LOGS . '/install'); |
37
|
|
|
static::initialiseDatabase(); |
38
|
|
|
|
39
|
|
|
// Initialize error handlers |
40
|
|
|
GenericExceptionHandler::initialise(Symphony::Log()); |
41
|
|
|
GenericErrorHandler::initialise(Symphony::Log()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* This function returns an instance of the Installer |
46
|
|
|
* class. It is the only way to create a new Installer, as |
47
|
|
|
* it implements the Singleton interface |
48
|
|
|
* |
49
|
|
|
* @return Installer |
50
|
|
|
*/ |
51
|
|
|
public static function instance() |
52
|
|
|
{ |
53
|
|
|
if (!(self::$_instance instanceof Installer)) { |
54
|
|
|
self::$_instance = new Installer; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return self::$_instance; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Initialises the language by looking at the `lang` key, |
62
|
|
|
* passed via GET or POST |
63
|
|
|
*/ |
64
|
|
|
public static function initialiseLang() |
65
|
|
|
{ |
66
|
|
|
$lang = !empty($_REQUEST['lang']) ? preg_replace('/[^a-zA-Z\-]/', null, $_REQUEST['lang']) : 'en'; |
67
|
|
|
Lang::initialize(); |
68
|
|
|
Lang::set($lang, false); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Overrides the default `initialiseLog()` method and writes |
73
|
|
|
* logs to manifest/logs/install |
74
|
|
|
*/ |
75
|
|
|
public static function initialiseLog($filename = null) |
76
|
|
|
{ |
77
|
|
View Code Duplication |
if (is_dir(INSTALL_LOGS) || General::realiseDirectory(INSTALL_LOGS, self::Configuration()->get('write_mode', 'directory'))) { |
|
|
|
|
78
|
|
|
parent::initialiseLog($filename); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Overrides the default `initialiseDatabase()` method |
84
|
|
|
* This allows us to still use the normal accessor |
85
|
|
|
*/ |
86
|
|
|
public static function initialiseDatabase() |
87
|
|
|
{ |
88
|
|
|
self::setDatabase(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function run() |
92
|
|
|
{ |
93
|
|
|
// Make sure a log file is available |
94
|
|
|
if (is_null(Symphony::Log())) { |
95
|
|
|
self::__render(new InstallerPage('missing-log')); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
// Check essential server requirements |
99
|
|
|
$errors = self::__checkRequirements(); |
100
|
|
View Code Duplication |
if (!empty($errors)) { |
101
|
|
|
Symphony::Log()->error('Installer - Missing requirements.'); |
|
|
|
|
102
|
|
|
|
103
|
|
|
foreach ($errors as $err) { |
104
|
|
|
Symphony::Log()->error( |
|
|
|
|
105
|
|
|
sprintf('Requirement - %s', $err['msg']) |
106
|
|
|
); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
self::__render(new InstallerPage('requirements', array( |
110
|
|
|
'errors'=> $errors |
111
|
|
|
))); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
// If language is not set and there is language packs available, show language selection pages |
115
|
|
|
if (!isset($_POST['lang']) && count(Lang::getAvailableLanguages(false)) > 1) { |
116
|
|
|
self::__render(new InstallerPage('languages')); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
// Check for configuration errors and, if there are no errors, install Symphony! |
120
|
|
|
if (isset($_POST['fields'])) { |
121
|
|
|
$errors = self::__checkConfiguration(); |
122
|
|
View Code Duplication |
if (!empty($errors)) { |
123
|
|
|
Symphony::Log()->error('Installer - Wrong configuration.'); |
|
|
|
|
124
|
|
|
|
125
|
|
|
foreach ($errors as $err) { |
126
|
|
|
Symphony::Log()->error( |
|
|
|
|
127
|
|
|
sprintf('Configuration - %s', $err['msg']) |
128
|
|
|
); |
129
|
|
|
} |
130
|
|
|
} else { |
131
|
|
|
$disabled_extensions = self::__install(); |
132
|
|
|
|
133
|
|
|
self::__render(new InstallerPage('success', array( |
134
|
|
|
'disabled-extensions' => $disabled_extensions |
135
|
|
|
))); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
// Display the Installation page |
140
|
|
|
self::__render(new InstallerPage('configuration', array( |
141
|
|
|
'errors' => $errors, |
142
|
|
|
'default-config' => Symphony::Configuration()->get() |
143
|
|
|
))); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* This function checks the server can support a Symphony installation. |
148
|
|
|
* It checks that PHP is 5.2+, MySQL, Zlib, LibXML, XSLT modules are enabled |
149
|
|
|
* and a `install.sql` file exists. |
150
|
|
|
* If any of these requirements fail the installation will not proceed. |
151
|
|
|
* |
152
|
|
|
* @return array |
153
|
|
|
* An associative array of errors, with `msg` and `details` keys |
154
|
|
|
*/ |
155
|
|
|
private static function __checkRequirements() |
156
|
|
|
{ |
157
|
|
|
$errors = array(); |
158
|
|
|
|
159
|
|
|
// Check for PHP 5.2+ |
160
|
|
|
if (version_compare(phpversion(), '5.3', '<=')) { |
161
|
|
|
$errors[] = array( |
162
|
|
|
'msg' => __('PHP Version is not correct'), |
163
|
|
|
'details' => __('Symphony requires %1$s or greater to work, however version %2$s was detected.', array('<code><abbr title="PHP: Hypertext Pre-processor">PHP</abbr> 5.3</code>', '<code>' . phpversion() . '</code>')) |
164
|
|
|
); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
// Make sure the install.sql file exists |
168
|
|
|
if (!file_exists(INSTALL . '/includes/install.sql') || !is_readable(INSTALL . '/includes/install.sql')) { |
169
|
|
|
$errors[] = array( |
170
|
|
|
'msg' => __('Missing install.sql file'), |
171
|
|
|
'details' => __('It appears that %s is either missing or not readable. This is required to populate the database and must be uploaded before installation can commence. Ensure that PHP has read permissions.', array('<code>install.sql</code>')) |
172
|
|
|
); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
// Is MySQL available? |
176
|
|
View Code Duplication |
if (!function_exists('mysqli_connect')) { |
177
|
|
|
$errors[] = array( |
178
|
|
|
'msg' => __('MySQLi extension not present'), |
179
|
|
|
'details' => __('Symphony requires PHP to be configured with MySQLi to work.') |
180
|
|
|
); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
// Is ZLib available? |
184
|
|
View Code Duplication |
if (!extension_loaded('zlib')) { |
185
|
|
|
$errors[] = array( |
186
|
|
|
'msg' => __('ZLib extension not present'), |
187
|
|
|
'details' => __('Symphony uses the ZLib compression library for log rotation.') |
188
|
|
|
); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
// Is libxml available? |
192
|
|
View Code Duplication |
if (!extension_loaded('xml') && !extension_loaded('libxml')) { |
193
|
|
|
$errors[] = array( |
194
|
|
|
'msg' => __('XML extension not present'), |
195
|
|
|
'details' => __('Symphony needs the XML extension to pass data to the site frontend.') |
196
|
|
|
); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
// Is libxslt available? |
200
|
|
|
if (!extension_loaded('xsl') && !extension_loaded('xslt') && !function_exists('domxml_xslt_stylesheet')) { |
201
|
|
|
$errors[] = array( |
202
|
|
|
'msg' => __('XSLT extension not present'), |
203
|
|
|
'details' => __('Symphony needs an XSLT processor such as %s or Sablotron to build pages.', array('Lib<abbr title="eXtensible Stylesheet Language Transformation">XSLT</abbr>')) |
204
|
|
|
); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
// Is json_encode available? |
208
|
|
View Code Duplication |
if (!function_exists('json_decode')) { |
209
|
|
|
$errors[] = array( |
210
|
|
|
'msg' => __('JSON functionality is not present'), |
211
|
|
|
'details' => __('Symphony uses JSON functionality throughout the backend for translations and the interface.') |
212
|
|
|
); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
// Cannot write to root folder. |
216
|
|
|
if (!is_writable(DOCROOT)) { |
217
|
|
|
$errors['no-write-permission-root'] = array( |
218
|
|
|
'msg' => 'Root folder not writable: ' . DOCROOT, |
219
|
|
|
'details' => __('Symphony does not have write permission to the root directory. Please modify permission settings on %s. This can be reverted once installation is complete.', array('<code>' . DOCROOT . '</code>')) |
220
|
|
|
); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
// Cannot write to workspace |
224
|
|
|
if (is_dir(DOCROOT . '/workspace') && !is_writable(DOCROOT . '/workspace')) { |
225
|
|
|
$errors['no-write-permission-workspace'] = array( |
226
|
|
|
'msg' => 'Workspace folder not writable: ' . DOCROOT . '/workspace', |
227
|
|
|
'details' => __('Symphony does not have write permission to the existing %1$s directory. Please modify permission settings on this directory and its contents to allow this, such as with a recursive %2$s command.', array('<code>/workspace</code>', '<code>chmod -R</code>')) |
228
|
|
|
); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
return $errors; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* This function checks the current Configuration (which is the values entered |
236
|
|
|
* by the user on the installation form) to ensure that `/symphony` and `/workspace` |
237
|
|
|
* folders exist and are writable and that the Database credentials are correct. |
238
|
|
|
* Once those initial checks pass, the rest of the form values are validated. |
239
|
|
|
* |
240
|
|
|
* @return |
241
|
|
|
* An associative array of errors if something went wrong, otherwise an empty array. |
242
|
|
|
*/ |
243
|
|
|
private static function __checkConfiguration() |
|
|
|
|
244
|
|
|
{ |
245
|
|
|
$errors = array(); |
246
|
|
|
$fields = $_POST['fields']; |
247
|
|
|
|
248
|
|
|
// Testing the database connection |
249
|
|
|
try { |
250
|
|
|
Symphony::Database()->connect( |
251
|
|
|
$fields['database']['host'], |
252
|
|
|
$fields['database']['user'], |
253
|
|
|
$fields['database']['password'], |
254
|
|
|
$fields['database']['port'], |
255
|
|
|
$fields['database']['db'] |
256
|
|
|
); |
257
|
|
|
} catch (DatabaseException $e) { |
258
|
|
|
// Invalid credentials |
259
|
|
|
// @link http://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
260
|
|
|
if ($e->getDatabaseErrorCode() === 1044 || $e->getDatabaseErrorCode() === 1045) { |
261
|
|
|
$errors['database-invalid-credentials'] = array( |
262
|
|
|
'msg' => 'Database credentials were denied', |
263
|
|
|
'details' => __('Symphony was unable to access the database with these credentials.') |
264
|
|
|
); |
265
|
|
|
} |
266
|
|
|
// Connection related |
267
|
|
|
else { |
268
|
|
|
$errors['no-database-connection'] = array( |
269
|
|
|
'msg' => 'Could not establish database connection.', |
270
|
|
|
'details' => __('Symphony was unable to establish a valid database connection. You may need to modify host or port settings.') |
271
|
|
|
); |
272
|
|
|
} |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
try { |
276
|
|
|
// Check the database table prefix is legal. #1815 |
277
|
|
|
if (!preg_match('/^[0-9a-zA-Z\$_]*$/', $fields['database']['tbl_prefix'])) { |
278
|
|
|
$errors['database-table-prefix'] = array( |
279
|
|
|
'msg' => 'Invalid database table prefix: ‘' . $fields['database']['tbl_prefix'] . '’', |
280
|
|
|
'details' => __('The table prefix %s is invalid. The table prefix must only contain numbers, letters or underscore characters.', array('<code>' . $fields['database']['tbl_prefix'] . '</code>')) |
281
|
|
|
); |
282
|
|
|
} |
283
|
|
|
// Check the database credentials |
284
|
|
|
elseif (Symphony::Database()->isConnected()) { |
285
|
|
|
// Incorrect MySQL version |
286
|
|
|
$version = Symphony::Database()->fetchVar('version', 0, "SELECT VERSION() AS `version`;"); |
287
|
|
|
if (version_compare($version, '5.5', '<')) { |
288
|
|
|
$errors['database-incorrect-version'] = array( |
289
|
|
|
'msg' => 'MySQL Version is not correct. '. $version . ' detected.', |
290
|
|
|
'details' => __('Symphony requires %1$s or greater to work, however version %2$s was detected. This requirement must be met before installation can proceed.', array('<code>MySQL 5.5</code>', '<code>' . $version . '</code>')) |
291
|
|
|
); |
292
|
|
|
} |
293
|
|
|
else { |
294
|
|
|
// Existing table prefix |
295
|
|
|
if (Symphony::Database()->tableExists($fields['database']['tbl_prefix'] . '%')) { |
296
|
|
|
$errors['database-table-prefix'] = array( |
297
|
|
|
'msg' => 'Database table prefix clash with ‘' . $fields['database']['db'] . '’', |
298
|
|
|
'details' => __('The table prefix %s is already in use. Please choose a different prefix to use with Symphony.', array( |
299
|
|
|
|
300
|
|
|
'<code>' . $fields['database']['tbl_prefix'] . '</code>' |
301
|
|
|
)) |
302
|
|
|
); |
303
|
|
|
} |
304
|
|
|
} |
305
|
|
|
} |
306
|
|
|
} catch (DatabaseException $e) { |
307
|
|
|
$errors['unknown-database'] = array( |
308
|
|
|
'msg' => 'Database ‘' . $fields['database']['db'] . '’ not found.', |
309
|
|
|
'details' => __('Symphony was unable to connect to the specified database.') |
310
|
|
|
); |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
// Website name not entered |
314
|
|
|
if (trim($fields['general']['sitename']) == '') { |
315
|
|
|
$errors['general-no-sitename'] = array( |
316
|
|
|
'msg' => 'No sitename entered.', |
317
|
|
|
'details' => __('You must enter a Site name. This will be shown at the top of your backend.') |
318
|
|
|
); |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
// Username Not Entered |
322
|
|
|
if (trim($fields['user']['username']) == '') { |
323
|
|
|
$errors['user-no-username'] = array( |
324
|
|
|
'msg' => 'No username entered.', |
325
|
|
|
'details' => __('You must enter a Username. This will be your Symphony login information.') |
326
|
|
|
); |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
// Password Not Entered |
330
|
|
|
if (trim($fields['user']['password']) == '') { |
331
|
|
|
$errors['user-no-password'] = array( |
332
|
|
|
'msg' => 'No password entered.', |
333
|
|
|
'details' => __('You must enter a Password. This will be your Symphony login information.') |
334
|
|
|
); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
// Password mismatch |
338
|
|
|
elseif ($fields['user']['password'] != $fields['user']['confirm-password']) { |
339
|
|
|
$errors['user-password-mismatch'] = array( |
340
|
|
|
'msg' => 'Passwords did not match.', |
341
|
|
|
'details' => __('The password and confirmation did not match. Please retype your password.') |
342
|
|
|
); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
// No Name entered |
346
|
|
|
if (trim($fields['user']['firstname']) == '' || trim($fields['user']['lastname']) == '') { |
347
|
|
|
$errors['user-no-name'] = array( |
348
|
|
|
'msg' => 'Did not enter First and Last names.', |
349
|
|
|
'details' => __('You must enter your name.') |
350
|
|
|
); |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
// Invalid Email |
354
|
|
|
if (!preg_match('/^\w(?:\.?[\w%+-]+)*@\w(?:[\w-]*\.)+?[a-z]{2,}$/i', $fields['user']['email'])) { |
355
|
|
|
$errors['user-invalid-email'] = array( |
356
|
|
|
'msg' => 'Invalid email address supplied.', |
357
|
|
|
'details' => __('This is not a valid email address. You must provide an email address since you will need it if you forget your password.') |
358
|
|
|
); |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
// Admin path not entered |
362
|
|
|
if (trim($fields['symphony']['admin-path']) == '') { |
363
|
|
|
$errors['no-symphony-path'] = array( |
364
|
|
|
'msg' => 'No Symphony path entered.', |
365
|
|
|
'details' => __('You must enter a path for accessing Symphony, or leave the default. This will be used to access Symphony\'s backend.') |
366
|
|
|
); |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
return $errors; |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* If something went wrong, the `__abort` function will write an entry to the Log |
374
|
|
|
* file and display the failure page to the user. |
375
|
|
|
* @todo: Resume installation after an error has been fixed. |
376
|
|
|
*/ |
377
|
|
|
protected static function __abort($message, $start) |
378
|
|
|
{ |
379
|
|
|
Symphony::Log()->error($message); |
|
|
|
|
380
|
|
|
Symphony::Log()->error(sprintf('INSTALLATION ABORTED: Execution Time - %d sec (%s)', |
|
|
|
|
381
|
|
|
max(1, time() - $start), |
382
|
|
|
date('d.m.y H:i:s') |
383
|
|
|
)); |
384
|
|
|
|
385
|
|
|
self::__render(new InstallerPage('failure')); |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
private static function __install() |
|
|
|
|
389
|
|
|
{ |
390
|
|
|
$fields = $_POST['fields']; |
391
|
|
|
$start = time(); |
392
|
|
|
|
393
|
|
|
Symphony::Log()->info('INSTALLATION PROCESS STARTED (' . DateTimeObj::get('c') . ')'); |
|
|
|
|
394
|
|
|
|
395
|
|
|
// MySQL: Establishing connection |
396
|
|
|
Symphony::Log()->info('MYSQL: Establishing Connection'); |
|
|
|
|
397
|
|
|
|
398
|
|
|
try { |
399
|
|
|
Symphony::Database()->connect( |
400
|
|
|
$fields['database']['host'], |
401
|
|
|
$fields['database']['user'], |
402
|
|
|
$fields['database']['password'], |
403
|
|
|
$fields['database']['port'], |
404
|
|
|
$fields['database']['db'] |
405
|
|
|
); |
406
|
|
|
} catch (DatabaseException $e) { |
407
|
|
|
self::__abort( |
408
|
|
|
'There was a problem while trying to establish a connection to the MySQL server. Please check your settings.', |
409
|
|
|
$start); |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
// MySQL: Setting prefix & character encoding |
413
|
|
|
Symphony::Database()->setPrefix($fields['database']['tbl_prefix']); |
414
|
|
|
|
415
|
|
|
// MySQL: Importing schema |
416
|
|
|
Symphony::Log()->info('MYSQL: Importing Table Schema'); |
|
|
|
|
417
|
|
|
|
418
|
|
|
try { |
419
|
|
|
Symphony::Database()->import(file_get_contents(INSTALL . '/includes/install.sql')); |
420
|
|
|
} catch (DatabaseException $e) { |
421
|
|
|
self::__abort( |
422
|
|
|
'There was an error while trying to import data to the database. MySQL returned: ' . $e->getDatabaseErrorCode() . ': ' . $e->getDatabaseErrorMessage(), |
423
|
|
|
$start); |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
// MySQL: Creating default author |
427
|
|
|
Symphony::Log()->info('MYSQL: Creating Default Author'); |
|
|
|
|
428
|
|
|
|
429
|
|
|
try { |
430
|
|
|
Symphony::Database()->insert(array( |
431
|
|
|
'id' => 1, |
432
|
|
|
'username' => Symphony::Database()->cleanValue($fields['user']['username']), |
433
|
|
|
'password' => Cryptography::hash(Symphony::Database()->cleanValue($fields['user']['password'])), |
434
|
|
|
'first_name' => Symphony::Database()->cleanValue($fields['user']['firstname']), |
435
|
|
|
'last_name' => Symphony::Database()->cleanValue($fields['user']['lastname']), |
436
|
|
|
'email' => Symphony::Database()->cleanValue($fields['user']['email']), |
437
|
|
|
'last_seen' => null, |
438
|
|
|
'user_type' => 'developer', |
439
|
|
|
'primary' => 'yes', |
440
|
|
|
'default_area' => null, |
441
|
|
|
'auth_token_active' => 'no' |
442
|
|
|
), 'tbl_authors'); |
443
|
|
|
} catch (DatabaseException $e) { |
444
|
|
|
self::__abort( |
445
|
|
|
'There was an error while trying create the default author. MySQL returned: ' . $e->getDatabaseErrorCode() . ': ' . $e->getDatabaseErrorMessage(), |
446
|
|
|
$start); |
447
|
|
|
} |
448
|
|
|
|
449
|
|
|
// Configuration: Populating array |
450
|
|
|
$conf = Symphony::Configuration()->get(); |
451
|
|
|
|
452
|
|
|
foreach ($conf as $group => $settings) { |
|
|
|
|
453
|
|
|
foreach ($settings as $key => $value) { |
454
|
|
|
if (isset($fields[$group]) && isset($fields[$group][$key])) { |
455
|
|
|
$conf[$group][$key] = $fields[$group][$key]; |
456
|
|
|
} |
457
|
|
|
} |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
// Create manifest folder structure |
461
|
|
|
Symphony::Log()->info('WRITING: Creating ‘manifest’ folder (/manifest)'); |
|
|
|
|
462
|
|
|
if (!General::realiseDirectory(MANIFEST, $conf['directory']['write_mode'])) { |
463
|
|
|
self::__abort( |
464
|
|
|
'Could not create ‘manifest’ directory. Check permission on the root folder.', |
465
|
|
|
$start); |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
Symphony::Log()->info('WRITING: Creating ‘logs’ folder (/manifest/logs)'); |
|
|
|
|
469
|
|
|
if (!General::realiseDirectory(LOGS, $conf['directory']['write_mode'])) { |
470
|
|
|
self::__abort( |
471
|
|
|
'Could not create ‘logs’ directory. Check permission on /manifest.', |
472
|
|
|
$start); |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
Symphony::Log()->info('WRITING: Creating ‘cache’ folder (/manifest/cache)'); |
|
|
|
|
476
|
|
|
if (!General::realiseDirectory(CACHE, $conf['directory']['write_mode'])) { |
477
|
|
|
self::__abort( |
478
|
|
|
'Could not create ‘cache’ directory. Check permission on /manifest.', |
479
|
|
|
$start); |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
Symphony::Log()->info('WRITING: Creating ‘tmp’ folder (/manifest/tmp)'); |
|
|
|
|
483
|
|
|
if (!General::realiseDirectory(MANIFEST . '/tmp', $conf['directory']['write_mode'])) { |
484
|
|
|
self::__abort( |
485
|
|
|
'Could not create ‘tmp’ directory. Check permission on /manifest.', |
486
|
|
|
$start); |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
// Writing configuration file |
490
|
|
|
Symphony::Log()->info('WRITING: Configuration File'); |
|
|
|
|
491
|
|
|
|
492
|
|
|
Symphony::Configuration()->setArray($conf); |
|
|
|
|
493
|
|
|
|
494
|
|
View Code Duplication |
if (!Symphony::Configuration()->write(CONFIG, $conf['file']['write_mode'])) { |
495
|
|
|
self::__abort( |
496
|
|
|
'Could not create config file ‘' . CONFIG . '’. Check permission on /manifest.', |
497
|
|
|
$start); |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
// Writing htaccess file |
501
|
|
|
Symphony::Log()->info('CONFIGURING: Frontend', E_NOTICE); |
|
|
|
|
502
|
|
|
|
503
|
|
|
$rewrite_base = ltrim(preg_replace('/\/install$/i', null, dirname($_SERVER['PHP_SELF'])), '/'); |
504
|
|
|
$htaccess = str_replace( |
505
|
|
|
'<!-- REWRITE_BASE -->', $rewrite_base, |
506
|
|
|
file_get_contents(INSTALL . '/includes/htaccess.txt') |
507
|
|
|
); |
508
|
|
|
|
509
|
|
|
if (!General::writeFile(DOCROOT . "/.htaccess", $htaccess, $conf['file']['write_mode'], 'a')) { |
510
|
|
|
self::__abort( |
511
|
|
|
'Could not write ‘.htaccess’ file. Check permission on ' . DOCROOT, |
512
|
|
|
$start); |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
// Writing /workspace folder |
516
|
|
|
if (!is_dir(DOCROOT . '/workspace')) { |
517
|
|
|
// Create workspace folder structure |
518
|
|
|
Symphony::Log()->info('WRITING: Creating ‘workspace’ folder (/workspace)'); |
|
|
|
|
519
|
|
|
if (!General::realiseDirectory(WORKSPACE, $conf['directory']['write_mode'])) { |
520
|
|
|
self::__abort( |
521
|
|
|
'Could not create ‘workspace’ directory. Check permission on the root folder.', |
522
|
|
|
$start); |
523
|
|
|
} |
524
|
|
|
|
525
|
|
|
Symphony::Log()->info('WRITING: Creating ‘data-sources’ folder (/workspace/data-sources)'); |
|
|
|
|
526
|
|
|
if (!General::realiseDirectory(DATASOURCES, $conf['directory']['write_mode'])) { |
527
|
|
|
self::__abort( |
528
|
|
|
'Could not create ‘workspace/data-sources’ directory. Check permission on the root folder.', |
529
|
|
|
$start); |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
Symphony::Log()->info('WRITING: Creating ‘events’ folder (/workspace/events)'); |
|
|
|
|
533
|
|
|
if (!General::realiseDirectory(EVENTS, $conf['directory']['write_mode'])) { |
534
|
|
|
self::__abort( |
535
|
|
|
'Could not create ‘workspace/events’ directory. Check permission on the root folder.', |
536
|
|
|
$start); |
537
|
|
|
} |
538
|
|
|
|
539
|
|
|
Symphony::Log()->info('WRITING: Creating ‘pages’ folder (/workspace/pages)'); |
|
|
|
|
540
|
|
|
if (!General::realiseDirectory(PAGES, $conf['directory']['write_mode'])) { |
541
|
|
|
self::__abort( |
542
|
|
|
'Could not create ‘workspace/pages’ directory. Check permission on the root folder.', |
543
|
|
|
$start); |
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
Symphony::Log()->info('WRITING: Creating ‘utilities’ folder (/workspace/utilities)'); |
|
|
|
|
547
|
|
|
if (!General::realiseDirectory(UTILITIES, $conf['directory']['write_mode'])) { |
548
|
|
|
self::__abort( |
549
|
|
|
'Could not create ‘workspace/utilities’ directory. Check permission on the root folder.', |
550
|
|
|
$start); |
551
|
|
|
} |
552
|
|
|
} else { |
553
|
|
|
Symphony::Log()->info('An existing ‘workspace’ directory was found at this location. Symphony will use this workspace.'); |
|
|
|
|
554
|
|
|
|
555
|
|
|
// MySQL: Importing workspace data |
556
|
|
|
Symphony::Log()->info('MYSQL: Importing Workspace Data...'); |
|
|
|
|
557
|
|
|
|
558
|
|
|
if (is_file(WORKSPACE . '/install.sql')) { |
559
|
|
|
try { |
560
|
|
|
Symphony::Database()->import(file_get_contents(WORKSPACE . '/install.sql')); |
561
|
|
|
} catch (DatabaseException $e) { |
562
|
|
|
self::__abort( |
563
|
|
|
'There was an error while trying to import data to the database. MySQL returned: ' . $e->getDatabaseErrorCode() . ': ' . $e->getDatabaseErrorMessage(), |
564
|
|
|
$start); |
565
|
|
|
} |
566
|
|
|
} |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
// Write extensions folder |
570
|
|
|
if (!is_dir(EXTENSIONS)) { |
571
|
|
|
// Create extensions folder |
572
|
|
|
Symphony::Log()->info('WRITING: Creating ‘extensions’ folder (/extensions)'); |
|
|
|
|
573
|
|
|
if (!General::realiseDirectory(EXTENSIONS, $conf['directory']['write_mode'])) { |
574
|
|
|
self::__abort( |
575
|
|
|
'Could not create ‘extension’ directory. Check permission on the root folder.', |
576
|
|
|
$start); |
577
|
|
|
} |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
// Install existing extensions |
581
|
|
|
Symphony::Log()->info('CONFIGURING: Installing existing extensions'); |
|
|
|
|
582
|
|
|
$disabled_extensions = array(); |
583
|
|
|
foreach (new DirectoryIterator(EXTENSIONS) as $e) { |
584
|
|
|
if ($e->isDot() || $e->isFile() || !is_file($e->getRealPath() . '/extension.driver.php')) { |
585
|
|
|
continue; |
586
|
|
|
} |
587
|
|
|
|
588
|
|
|
$handle = $e->getBasename(); |
589
|
|
|
try { |
590
|
|
|
if (!ExtensionManager::enable($handle)) { |
591
|
|
|
$disabled_extensions[] = $handle; |
592
|
|
|
Symphony::Log()->warning('Could not enable the extension ‘' . $handle . '’.'); |
|
|
|
|
593
|
|
|
} |
594
|
|
|
} catch (Exception $ex) { |
595
|
|
|
$disabled_extensions[] = $handle; |
596
|
|
|
Symphony::Log()->warning('Could not enable the extension ‘' . $handle . '’. '. $ex->getMessage()); |
|
|
|
|
597
|
|
|
} |
598
|
|
|
} |
599
|
|
|
|
600
|
|
|
// Loading default language |
601
|
|
|
if (isset($_REQUEST['lang']) && $_REQUEST['lang'] != 'en') { |
602
|
|
|
Symphony::Log()->info('CONFIGURING: Default language'); |
|
|
|
|
603
|
|
|
|
604
|
|
|
$language = Lang::Languages(); |
605
|
|
|
$language = $language[$_REQUEST['lang']]; |
606
|
|
|
|
607
|
|
|
// Is the language extension enabled? |
608
|
|
|
if (in_array('lang_' . $language['handle'], ExtensionManager::listInstalledHandles())) { |
609
|
|
|
Symphony::Configuration()->set('lang', $_REQUEST['lang'], 'symphony'); |
610
|
|
View Code Duplication |
if (!Symphony::Configuration()->write(CONFIG, $conf['file']['write_mode'])) { |
611
|
|
|
Symphony::Log()->warning('Could not write default language ‘' . $language['name'] . '’ to config file.'); |
|
|
|
|
612
|
|
|
} |
613
|
|
|
} else { |
614
|
|
|
Symphony::Log()->warning('Could not enable the desired language ‘' . $language['name'] . '’.'); |
|
|
|
|
615
|
|
|
} |
616
|
|
|
} |
617
|
|
|
|
618
|
|
|
// Installation completed. Woo-hoo! |
619
|
|
|
Symphony::Log()->info(sprintf('INSTALLATION COMPLETED: Execution Time - %d sec (%s)', |
|
|
|
|
620
|
|
|
max(1, time() - $start), |
621
|
|
|
date('d.m.y H:i:s') |
622
|
|
|
)); |
623
|
|
|
|
624
|
|
|
return $disabled_extensions; |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
protected static function __render(InstallerPage $page) |
628
|
|
|
{ |
629
|
|
|
$output = $page->generate(); |
630
|
|
|
|
631
|
|
|
header('Content-Type: text/html; charset=utf-8'); |
632
|
|
|
echo $output; |
633
|
|
|
exit; |
|
|
|
|
634
|
|
|
} |
635
|
|
|
} |
636
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: