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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
<?php
/*
* Spring Signage Ltd - http://www.springsignage.com
* Copyright (C) 2015 Spring Signage Ltd
* (routes-install.php)
*/
$app->map('/(:step)', function($step = 1) use($app) {
\Xibo\Helper\Log::info('Installer Step %s', $step);
$install = new \Xibo\Helper\Install();
$settingsExists = $app->settingsExists;
$template = '';
$data = [];
switch ($step) {
case 1:
if ($settingsExists)
throw new \Xibo\Exception\InstallationError(__('The CMS has already been installed. Please contact your system administrator.'));
// Welcome to the installer (this should only show once)
// Checks environment
$template = 'install-step1';
$data = $install->Step1();
break;
case 2:
if ($settingsExists)
throw new \Xibo\Exception\InstallationError(__('The CMS has already been installed. Please contact your system administrator.'));
// Collect details about the database
$template = 'install-step2';
$data = $install->Step2();
break;
case 3:
if ($settingsExists)
throw new \Xibo\Exception\InstallationError(__('The CMS has already been installed. Please contact your system administrator.'));
// Check and validate DB details
if (defined('MAX_EXECUTION') && MAX_EXECUTION) {
\Xibo\Helper\Log::info('Setting unlimited max execution time.');
set_time_limit(0);
}
try {
$install->Step3();
// Redirect to step 4
$app->redirectTo('install', ['step' => 4]);
}
catch (\Xibo\Exception\InstallationError $e) {
\Xibo\Helper\Log::error('Installation Exception on Step %d: %s', $step, $e->getMessage());
$app->flashNow('error', $e->getMessage());
// Add our object properties to the flash vars, so we render the form with them set
foreach (\Xibo\Helper\ObjectVars::getObjectVars($install) as $key => $value) {
$app->flashNow($key, $value);
}
// Reload step 2
$template = 'install-step2';
$data = $install->Step2();
}
break;
case 4:
// DB installed and we are ready to collect some more details
// We should get the admin username and password
$data = $install->Step4();
$template = 'install-step4';
break;
case 5:
// Create a user account
try {
$install->Step5();
// Redirect to step 6
$app->redirectTo('install', ['step' => 6]);
}
catch (\Xibo\Exception\InstallationError $e) {
\Xibo\Helper\Log::error('Installation Exception on Step %d: %s', $step, $e->getMessage());
$app->flashNow('error', $e->getMessage());
// Reload step 4
$template = 'install-step4';
$data = $install->Step4();
}
break;
case 6:
$template = 'install-step6';
$data = $install->Step6();
break;
case 7:
// Create a user account
try {
$template = 'install-step7';
$install->Step7();
// Redirect to login
// This will always be one folder down
$login = str_replace('/install', '', $app->urlFor('login'));
\Xibo\Helper\Log::info('Installation Complete. Redirecting to %s', $login);
$app->redirect($login);
}
catch (\Xibo\Exception\InstallationError $e) {
\Xibo\Helper\Log::error('Installation Exception on Step %d: %s', $step, $e->getMessage());
$app->flashNow('error', $e->getMessage());
// Reload step 6
$template = 'install-step6';
$data = $install->Step6();
}
break;
}
// Render
$app->render($template . '.twig', $data);
})->via('GET', 'POST')->name('install');
$app->get('/login', function() use ($app) {
// Just a helper to get correct login route url
$app->halt(404, __('This function should not be called from install/.'));
})->name('login');
|