diff --git a/application/controllers/NavigationController.php b/application/controllers/NavigationController.php index de999a9e9..b1bcb3309 100644 --- a/application/controllers/NavigationController.php +++ b/application/controllers/NavigationController.php @@ -211,23 +211,27 @@ class NavigationController extends Controller $form = new Form(array( 'onSuccess' => function ($form) use ($navigationConfigForm) { try { - if ($navigationConfigForm->unshare($form->getValue('name'))) { - Notification::success(sprintf( - t('Navigation item "%s" has been unshared'), - $form->getValue('name') - )); - } else { - Notification::error(sprintf( - t('Failed to unshare navigation item "%s"'), - $form->getValue('name') - )); - } + $navigationConfigForm->unshare($form->getValue('name')); } catch (NotFoundError $e) { throw $e; } catch (Exception $e) { Notification::error($e->getMessage()); } + if ($navigationConfigForm->save()) { + Notification::success(sprintf( + t('Navigation item "%s" has been unshared'), + $form->getValue('name') + )); + } else { + // TODO: It failed obviously to write one of the configs, so we're leaving the user in + // a inconsistent state. Luckily, it's nothing lost but possibly duplicated... + Notification::error(sprintf( + t('Failed to unshare navigation item "%s"'), + $form->getValue('name') + )); + } + $redirect = $form->getValue('redirect'); if (! empty($redirect)) { $form->setRedirectUrl(htmlspecialchars_decode($redirect)); diff --git a/application/forms/ConfigForm.php b/application/forms/ConfigForm.php index 58d550793..3f3ba227f 100644 --- a/application/forms/ConfigForm.php +++ b/application/forms/ConfigForm.php @@ -43,7 +43,7 @@ class ConfigForm extends Form public function save() { try { - $this->config->saveIni(); + $this->writeConfig($this->config); } catch (Exception $e) { $this->addDecorator('ViewScript', array( 'viewModule' => 'default', @@ -58,4 +58,14 @@ class ConfigForm extends Form return true; } + + /** + * Write the configuration to disk + * + * @param Config $config + */ + protected function writeConfig(Config $config) + { + $config->saveIni(); + } } diff --git a/application/forms/Navigation/NavigationConfigForm.php b/application/forms/Navigation/NavigationConfigForm.php index 097ea71b0..495055cab 100644 --- a/application/forms/Navigation/NavigationConfigForm.php +++ b/application/forms/Navigation/NavigationConfigForm.php @@ -27,6 +27,16 @@ class NavigationConfigForm extends ConfigForm 'dashlet' ); + /** + * The secondary configuration to write + * + * This is always the reduced configuration and is only written to + * disk once the main configuration has been successfully written. + * + * @var Config + */ + protected $secondaryConfig; + /** * The navigation item to load when displaying the form for the first time * @@ -319,6 +329,19 @@ class NavigationConfigForm extends ConfigForm return $values; } + /** + * {@inheritdoc} + */ + protected function writeConfig(Config $config) + { + parent::writeConfig($config); + + if ($this->secondaryConfig !== null) { + $this->config = $this->secondaryConfig; // Causes the config being displayed to the user in case of an error + parent::writeConfig($this->secondaryConfig); + } + } + /** * Return a list of available item types *