Skip to content

Commit

Permalink
Dev: Only write config file when installation is completely done
Browse files Browse the repository at this point in the history
Conflicts:
	application/controllers/InstallerController.php
  • Loading branch information
olleharstedt committed Feb 22, 2018
1 parent 49c565e commit 9ae8fc8
Showing 1 changed file with 31 additions and 33 deletions.
64 changes: 31 additions & 33 deletions application/controllers/InstallerController.php
Expand Up @@ -100,10 +100,8 @@ public function run($action = 'index')
*/
function _checkInstallation()
{
if (file_exists(APPPATH . 'config/config.php') && is_null(Yii::app()->request->getPost('InstallerConfigForm')))
{
if (file_exists(APPPATH.'config/config.php')) {
throw new CHttpException(500, 'Installation has been done already. Installer disabled.');
exit();
}
}

Expand Down Expand Up @@ -629,18 +627,17 @@ private function stepOptionalConfiguration()
$this->loadHelper('surveytranslator');
$aData['model'] = $model = new InstallerConfigForm('optional');
// Backup the default, needed only for $sDefaultAdminPassword
$sDefaultAdminUserName = $model->adminLoginName;
$sDefaultAdminPassword = $model->adminLoginPwd;
$sDefaultAdminRealName = $model->adminName;
$sDefaultSiteName = $model->siteName;
$sDefaultSiteLanguage = $model->surveylang;
$sDefaultAdminEmail = $model->adminEmail;
if(!is_null(Yii::app()->request->getPost('InstallerConfigForm')))
{
//$sDefaultAdminUserName = $model->adminLoginName;
//$sDefaultAdminPassword = $model->adminLoginPwd;
//$sDefaultAdminRealName = $model->adminName;
//$sDefaultSiteName = $model->siteName;
//$sDefaultSiteLanguage = $model->surveylang;
//$sDefaultAdminEmail = $model->adminEmail;
if (!is_null(Yii::app()->request->getPost('InstallerConfigForm'))) {
$model->attributes = Yii::app()->request->getPost('InstallerConfigForm');

//run validation, if it fails, load the view again else proceed to next step.
if($model->validate()) {
if ($model->validate()) {
$sAdminUserName = $model->adminLoginName;
$sAdminPassword = $model->adminLoginPwd;
$sAdminRealName = $model->adminName;
Expand Down Expand Up @@ -673,7 +670,7 @@ private function stepOptionalConfiguration()
$user = User::model()->findByPk(1);
if (empty($user)) {
throw new Exception('There is an admin user, but not with id 1');
}
}
} else {
$user = new User;

Expand Down Expand Up @@ -705,37 +702,38 @@ private function stepOptionalConfiguration()
$user->parent_id = 0;
$user->lang = $sSiteLanguage;
$user->email = $sAdminEmail;
$result = $user->save();
$user->save();

// only continue if we're error free otherwise setup is broken.
Yii::app()->session['deletedirectories'] = true;

$aData['title'] = gT("Success!");
$aData['descp'] = gT("LimeSurvey has been installed successfully.");
$aData['classesForStep'] = array('off', 'off', 'off', 'off', 'off', 'off');
$aData['progressValue'] = 100;
$aData['user'] = $sAdminUserName;
if ($sDefaultAdminPassword == $sAdminPassword) {
$aData['pwd'] = $sAdminPassword;
} else {
$aData['pwd'] = gT("The password you have chosen at the optional settings step.");
}

$this->_writeConfigFile();

$this->render('/installer/success_view', $aData);

return;

} catch (Exception $e) {
throw new Exception(sprintf('Could not add optional settings: %s.', $e));
}

Yii::app()->session['deletedirectories'] = true;

$aData['title'] = gT("Success!");
$aData['descp'] = gT("LimeSurvey has been installed successfully.");
$aData['classesForStep'] = array('off','off','off','off','off','off');
$aData['progressValue'] = 100;
$aData['user'] = $sAdminUserName;
if($sDefaultAdminPassword==$sAdminPassword){
$aData['pwd'] = $sAdminPassword;
}else{
$aData['pwd'] = gT("The password you have chosen at the optional settings step.");
}

$this->render('/installer/success_view', $aData);
return;
}
} else {
// if passwords don't match, redirect to proper link.
Yii::app()->session['optconfig_message'] = sprintf('<b>%s</b>', gT("Passwords don't match."));
$this->redirect(array('installer/optional'));
}
} elseif(empty(Yii::app()->session['configFileWritten'])) {
$this->_writeConfigFile();
}

$this->render('/installer/optconfig_view', $aData);
}

Expand Down

0 comments on commit 9ae8fc8

Please sign in to comment.