diff --git a/application/controllers/admin/Database.php b/application/controllers/admin/Database.php index 71c55286a85..7f2cf3e889a 100644 --- a/application/controllers/admin/Database.php +++ b/application/controllers/admin/Database.php @@ -16,13 +16,13 @@ use LimeSurvey\Models\Services\Exception\PersistErrorException; /** -* Database -* -* @package LimeSurvey -* @author -* @copyright 2011 -* @access public -*/ + * Database + * + * @package LimeSurvey + * @author + * @copyright 2011 + * @access public + */ class Database extends SurveyCommonAction { /** @@ -97,10 +97,10 @@ public function updateDefaultValues($qid, $sqid, $scale_id, $specialtype, $langu ->find( 'specialtype = :specialtype AND qid = :qid AND sqid = :sqid AND scale_id = :scale_id', array( - ':specialtype' => $specialtype, - ':qid' => $qid, - ':sqid' => $sqid, - ':scale_id' => $scale_id, + ':specialtype' => $specialtype, + ':qid' => $qid, + ':sqid' => $sqid, + ':scale_id' => $scale_id, ) ); $dvid = !empty($arDefaultValue->dvid) ? $arDefaultValue->dvid : null; @@ -108,7 +108,7 @@ public function updateDefaultValues($qid, $sqid, $scale_id, $specialtype, $langu if ($defaultvalue == '') { // Remove the default value if it is empty if ($dvid !== null) { - DefaultValueL10n::model()->deleteAllByAttributes(array('dvid' => $dvid, 'language' => $language )); + DefaultValueL10n::model()->deleteAllByAttributes(array('dvid' => $dvid, 'language' => $language)); $iRowCount = DefaultValueL10n::model()->countByAttributes(array('dvid' => $dvid)); if ($iRowCount == 0) { DefaultValue::model()->deleteByPk($dvid); @@ -199,7 +199,7 @@ private function actionUpdateDefaultValues($iSurveyID) } if (Yii::app()->request->getPost('defaultanswerscale_0_' . $sLanguage) == 'EM') { -// Case EM, write expression to database + // Case EM, write expression to database $this->updateDefaultValues($this->iQuestionID, 0, 0, '', $sLanguage, Yii::app()->request->getPost('defaultanswerscale_0_' . $sLanguage . '_EM')); } else { // Case "other", write list value to database @@ -379,9 +379,16 @@ protected function actionUpdateSurveyLocaleSettingsGeneralSettings($surveyId) Yii::app() ->setFlashMessage(gT('Survey settings were successfully saved.')); } catch (PersistErrorException $e) { - Yii::app()->setFlashMessage( - $e->getMessage(), - 'error' + \Yii::app()->setFlashMessage( + \CHtml::errorSummary( + $e->getErrorModel(), + \CHtml::tag( + "p", + array('class' => 'strong'), + gT("Survey could not be updated, please fix the following error:") + ) + ), + "error" ); } diff --git a/application/models/services/Exception.php b/application/models/services/Exception.php index 555efdde5ec..156d8a1ab49 100644 --- a/application/models/services/Exception.php +++ b/application/models/services/Exception.php @@ -2,6 +2,19 @@ namespace LimeSurvey\Models\Services; +use LSActiveRecord; + class Exception extends \Exception { + private $errorModel = null; + + public function setErrorModel(LSActiveRecord $errorModel) + { + $this->errorModel = $errorModel; + } + + public function getErrorModel() + { + return $this->errorModel; + } } diff --git a/application/models/services/SurveyAggregateService.php b/application/models/services/SurveyAggregateService.php index dba032db05b..d1d370f8544 100644 --- a/application/models/services/SurveyAggregateService.php +++ b/application/models/services/SurveyAggregateService.php @@ -60,6 +60,11 @@ public function setRestMode($restMode) $this->generalSettings->setRestMode($this->restMode); } + public function getRestMode() + { + return $this->restMode; + } + /** * Update * diff --git a/application/models/services/SurveyAggregateService/GeneralSettings.php b/application/models/services/SurveyAggregateService/GeneralSettings.php index 6bd0ecd2a65..971dd1ee570 100644 --- a/application/models/services/SurveyAggregateService/GeneralSettings.php +++ b/application/models/services/SurveyAggregateService/GeneralSettings.php @@ -177,12 +177,14 @@ private function updateGeneralSettings(Survey $survey, array $input) ); if (!$survey->save()) { - throw new PersistErrorException( + $e = new PersistErrorException( sprintf( 'Failed saving general settings for survey #%s', $survey->sid ) ); + $e->setErrorModel($survey); + throw $e; } } diff --git a/application/models/services/SurveyAggregateService/LanguageSettings.php b/application/models/services/SurveyAggregateService/LanguageSettings.php index ec15f67fcce..9fb95056455 100644 --- a/application/models/services/SurveyAggregateService/LanguageSettings.php +++ b/application/models/services/SurveyAggregateService/LanguageSettings.php @@ -142,13 +142,15 @@ protected function updateLanguageSettings(Survey $survey, $input) $surveyLanguageSetting->setAttributes($data); if (!$surveyLanguageSetting->save()) { - throw new PersistErrorException( + $e = new PersistErrorException( sprintf( 'Failed saving language settings for survey #%s and language "%s"', $survey->sid, $languageCode ) ); + $e->setErrorModel($surveyLanguageSetting); + throw $e; } } }