Install: Display previous selections when installation failed

This commit is contained in:
Olivier PEREZ 2015-09-07 16:34:24 +02:00
parent fd27c135c8
commit cbc5727ce4
3 changed files with 40 additions and 40 deletions

View File

@ -31,7 +31,8 @@ $error = null;
$installService = new InstallService();
if (!empty($_POST)) {
$result = $installService->install($_POST, $smarty);
$installService->updateFields($_POST);
$result = $installService->install($smarty);
if ($result['status'] === 'OK') {
header(('Location: ' . Utils::get_server_name() . 'admin/migration.php'));

View File

@ -26,34 +26,37 @@ use Smarty;
class InstallService {
private $fields = array(
'General' =>
array(
'appName' => 'Framadate',
'appMail' => '',
'responseMail' => '',
'defaultLanguage' => 'fr',
'cleanUrl' => true
),
'Database configuration' =>
array(
'dbConnectionString' => 'mysql:host=<HOST>;dbname=<SCHEMA>;port=3306',
'dbUser' => 'root',
'dbPassword' => '',
'dbPrefix' => 'fd_',
'migrationTable' => 'framadate_migration'
)
// General
'appName' => 'Framadate',
'appMail' => '',
'responseMail' => '',
'defaultLanguage' => 'fr',
'cleanUrl' => true,
// Database configuration
'dbConnectionString' => 'mysql:host=<HOST>;dbname=<SCHEMA>;port=3306',
'dbUser' => 'root',
'dbPassword' => '',
'dbPrefix' => 'fd_',
'migrationTable' => 'framadate_migration'
);
function __construct() {}
public function install($data, Smarty &$smarty) {
public function updateFields($data) {
foreach ($data as $field => $value) {
$this->fields[$field] = $value;
}
}
public function install(Smarty &$smarty) {
// Check values are present
if (empty($data['appName']) || empty($data['appMail']) || empty($data['defaultLanguage']) || empty($data['dbConnectionString']) || empty($data['dbUser'])) {
if (empty($this->fields['appName']) || empty($this->fields['appMail']) || empty($this->fields['defaultLanguage']) || empty($this->fields['dbConnectionString']) || empty($this->fields['dbUser'])) {
return $this->error('MISSING_VALUES');
}
// Connect to database
$connect = $this->connectTo($data['dbConnectionString'], $data['dbUser'], $data['dbPassword']);
$connect = $this->connectTo($this->fields['dbConnectionString'], $this->fields['dbUser'], $this->fields['dbPassword']);
if (!$connect) {
return $this->error('CANT_CONNECT_TO_DATABASE');
}
@ -62,7 +65,7 @@ class InstallService {
$this->createDatabaseSchema($connect);
// Write configuration to conf.php file
$this->writeConfiguration($data, $smarty);
$this->writeConfiguration($smarty);
return $this->ok();
}
@ -78,11 +81,9 @@ class InstallService {
}
}
function writeConfiguration($data, Smarty &$smarty) {
foreach($this->fields as $groupKey=>$group) {
foreach ($group as $field=>$value) {
$smarty->assign($field, $data[$field]);
}
function writeConfiguration(Smarty &$smarty) {
foreach($this->fields as $field=>$value) {
$smarty->assign($field, $value);
}
$content = $smarty->fetch('admin/config.tpl');

View File

@ -15,21 +15,21 @@
<div class="form-group">
<div class="input-group">
<label for="appName" class="input-group-addon">{__('Generic', 'ASTERISK')} {__('Installation', 'AppName')}</label>
<input type="text" class="form-control" id="appName" name="appName" value="{$fields['General']['appName']}" autofocus required>
<input type="text" class="form-control" id="appName" name="appName" value="{$fields['appName']}" autofocus required>
</div>
</div>
<div class="form-group">
<div class="input-group">
<label for="appMail" class="input-group-addon">{__('Generic', 'ASTERISK')} {__('Installation', 'AppMail')}</label>
<input type="email" class="form-control" id="appMail" name="appMail" value="{$fields['General']['appMail']}" required>
<input type="email" class="form-control" id="appMail" name="appMail" value="{$fields['appMail']}" required>
</div>
</div>
<div class="form-group">
<div class="input-group">
<label for="responseMail" class="input-group-addon">{__('Installation', 'ResponseMail')}</label>
<input type="email" class="form-control" id="responseMail" name="responseMail" value="{$fields['General']['responseMail']}">
<input type="email" class="form-control" id="responseMail" name="responseMail" value="{$fields['responseMail']}">
</div>
</div>
@ -37,11 +37,9 @@
<div class="input-group">
<label for="defaultLanguage" class="input-group-addon">{__('Generic', 'ASTERISK')} {__('Installation', 'DefaultLanguage')}</label>
<select type="email" class="form-control" id="defaultLanguage" name="defaultLanguage" required>
<option value="de">{$langs['de']}</option>
<option value="en">{$langs['es']}</option>
<option value="es">{$langs['es']}</option>
<option value="fr" selected>{$langs['fr']}</option>
<option value="it">{$langs['it']}</option>
{foreach $langs as $lang=>$label}
<option value="{$lang}" {if $lang==$fields['defaultLanguage']}selected{/if}>{$label}</option>
{/foreach}
</select>
</div>
</div>
@ -50,7 +48,7 @@
<label for="cleanUrl" class="input-group-addon">{__('Installation', 'CleanUrl')}</label>
<div class="form-control">
<input type="checkbox" id="cleanUrl" name="cleanUrl" {($fields['General']['cleanUrl']) ? 'checked' : ''}>
<input type="checkbox" id="cleanUrl" name="cleanUrl" {($fields['cleanUrl']) ? 'checked' : ''}>
</div>
</div>
</div>
@ -61,35 +59,35 @@
<div class="form-group">
<div class="input-group">
<label for="dbConnectionString" class="input-group-addon">{__('Generic', 'ASTERISK')} {__('Installation', 'DbConnectionString')}</label>
<input type="text" class="form-control" id="dbConnectionString" name="dbConnectionString" value="{$fields['Database configuration']['dbConnectionString']}" required>
<input type="text" class="form-control" id="dbConnectionString" name="dbConnectionString" value="{$fields['dbConnectionString']}" required>
</div>
</div>
<div class="form-group">
<div class="input-group">
<label for="dbUser" class="input-group-addon">{__('Generic', 'ASTERISK')} {__('Installation', 'DbUser')}</label>
<input type="text" class="form-control" id="dbUser" name="dbUser" value="{$fields['Database configuration']['dbUser']}" required>
<input type="text" class="form-control" id="dbUser" name="dbUser" value="{$fields['dbUser']}" required>
</div>
</div>
<div class="form-group">
<div class="input-group">
<label for="dbPassword" class="input-group-addon">{__('Installation', 'DbPassword')}</label>
<input type="password" class="form-control" id="dbPassword" name="dbPassword" value="{$fields['Database configuration']['dbPassword']}">
<input type="password" class="form-control" id="dbPassword" name="dbPassword" value="{$fields['dbPassword']}">
</div>
</div>
<div class="form-group">
<div class="input-group">
<label for="dbPrefix" class="input-group-addon">{__('Installation', 'DbPrefix')}</label>
<input type="text" class="form-control" id="dbPrefix" name="dbPrefix" value="{$fields['Database configuration']['dbPrefix']}">
<input type="text" class="form-control" id="dbPrefix" name="dbPrefix" value="{$fields['dbPrefix']}">
</div>
</div>
<div class="form-group">
<div class="input-group">
<label for="migrationTable" class="input-group-addon">{__('Generic', 'ASTERISK')} {__('Installation', 'MigrationTable')}</label>
<input type="text" class="form-control" id="migrationTable" name="migrationTable" value="{$fields['Database configuration']['migrationTable']}" required>
<input type="text" class="form-control" id="migrationTable" name="migrationTable" value="{$fields['migrationTable']}" required>
</div>
</div>
</fieldset>