-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
131 lines (105 loc) · 4.56 KB
/
index.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
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
<?php
/**
* The index file for the installer.
*
* @author Benjamin Mestdagh
* @copyright 2013 by 0KFN Belgium
*/
use Symfony\Component\HttpFoundation\Request;
$loader = require_once __DIR__.'/vendor/autoload.php';
$loader->add('tdt\\installer\\', __DIR__.'/src');
$app = new Silex\Application();
//$app['debug'] = true;
$app->register(new Silex\Provider\SessionServiceProvider());
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__.'/frontend',
));
$app->before(function (Request $request) {
$request->getSession()->start();
});
/**
* The array containing all steps of the installer. These are the names of the PHP classes,
* and (in lowercase) also the names of the twig files to be shown (in frontend/).
*/
$wizardSteps = array('Requirements', 'InitialDownload', 'Packages', 'PackageDownload',
'General', 'Host', 'Logging', 'Cache', 'Database', 'DatabaseAdvanced', 'DatabaseUser',
'DatabaseDb', 'Finish');
/**
* The main start point of the installer. Normal installer page requests are processed
* here. The installer page number is set in the query string
*/
$app->match('/', function (Request $request) use ($app, $wizardSteps) {
// Get the current page number
$getParams = $request->query->all();
if(array_key_exists('page', $getParams)) $step = (int) $getParams['page'];
else $step = 0;
// Check if the user is allowed to visit this page
if(!$app['session']->get('requirementsOk')) {
// You cannot start the installer if you don't meet the requirements!
$step = 0;
} elseif($step > count($wizardSteps) - 1 || $step < 0) {
// You cannot go to a non-existing page of the installer!
$step = $app['session']->get('lastVisitedStep');
} elseif($step > $app['session']->get('lastVisitedStep') + 1) {
// You cannot skip steps in the installer, unless you have
// chosen the default database installation
if($app['session']->get('dbinstalldefault') !== true) {
$step = $app['session']->get('lastVisitedStep');
}
} elseif($step < 4) {
// You cannot revisit the package download pages
if($app['session']->get('lastVisitedStep') > $step) {
$step = $app['session']->get('lastVisitedStep');
}
}
$app['session']->set('lastVisitedStep', $step);
// The twig page to be shown
$page = strtolower($wizardSteps[$step].'.html');
// The PHP class to be called
$className = 'tdt\\installer\\installersteps\\' . $wizardSteps[$step];
$class = new $className();
// The array containing the variables to be sent to the twig page
$pagevariables = array();
$pagevariables['validationError'] = false;
if($request->getMethod() == 'POST') {
$class->writeData($request, $app['session']);
$validationOutput = $class->validate($request);
if($validationOutput !== true) {
$pagevariables = array_merge($pagevariables, $validationOutput);
$pagevariables['validationError'] = true;
} else {
// Go to finish if the user chose a default database installation
$redirectPage = $app['session']->get('dbinstalldefault') === true ? count($wizardSteps) - 1 : ($step + 1);
return $app->redirect('?page='.$redirectPage);
}
}
try {
$pagevariables['currentpage'] = $step;
$pagevariables['hasnextpage'] = $step < count($wizardSteps);
$pagevariables = array_merge($pagevariables, $class->getPageContent($app['session']));
// We set the requirements check to false when we reach the final page.
// Normally, the session should be invalidated, but that triggers PHP warnings.
if($step == (count($wizardSteps) - 1)) {
$app['session']->set('requirementsOk', false);
}
return $app['twig']->render($page, $pagevariables);
} catch (Exception $e) {
// An error occured, show the error page, and the log
return $app['twig']->render('error.html', array('logs' => file_get_contents('settings/installer.log')));
}
});
/**
* Processes the request for a Git clone of the tdt/start package.
*/
$app->get('/gitclone', function () use ($app) {
$gitcloner = new tdt\installer\GitCloner();
return $app->json($gitcloner->start());
});
/**
* Processes the request for the Composer update
*/
$app->get('/packagedownload', function () use ($app) {
$packageDownloader = new tdt\installer\PackageDownloader();
return $packageDownloader->start($app['session']);
});
$app->run();