From 364c7c0858bcbf0094a9940c49f3bc6edbda595c Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 29 Aug 2014 12:25:25 +0200 Subject: [PATCH] Add base form class for configuration forms refs #5525 --- application/forms/ConfigForm.php | 67 +++++++++++++++++++ .../views/scripts/showConfiguration.phtml | 28 ++++++++ 2 files changed, 95 insertions(+) create mode 100644 application/forms/ConfigForm.php create mode 100644 application/views/scripts/showConfiguration.phtml diff --git a/application/forms/ConfigForm.php b/application/forms/ConfigForm.php new file mode 100644 index 000000000..1f3692473 --- /dev/null +++ b/application/forms/ConfigForm.php @@ -0,0 +1,67 @@ +config = $config; + return $this; + } + + /** + * Persist the current configuration to disk + * + * If an error occurs the user is shown a view describing the issue and displaying the raw INI configuration. + * + * @return bool Whether the configuration could be persisted + */ + public function save() + { + $writer = new PreservingIniWriter( + array( + 'config' => $this->config, + 'filename' => $this->config->getConfigFile() + ) + ); + + try { + $writer->write(); + } catch (Exception $e) { + $this->addDecorator('ViewScript', array( + 'viewScript' => 'showConfiguration.phtml', + 'errorMessage' => $e->getMessage(), + 'configString' => $writer->render(), + 'filePath' => $this->config->getConfigFile() + )); + return false; + } + + return true; + } +} diff --git a/application/views/scripts/showConfiguration.phtml b/application/views/scripts/showConfiguration.phtml new file mode 100644 index 000000000..1dde3b16b --- /dev/null +++ b/application/views/scripts/showConfiguration.phtml @@ -0,0 +1,28 @@ +
+

translate('Saving Configuration Failed'); ?>

+
+

+ translate('The file %s couldn\'t be stored. (Error: "%s")'), + $this->escape($filePath), + $this->escape($errorMessage) + ); ?> +
+ translate('This could have one or more of the following reasons:'); ?> +

+ +
+

+ translate('Details can be found in the application log. (If you don\'t have access to this log, call your administrator in this case)'); ?> +
+ translate('In case you can access the file by yourself, you can open it and insert the config manually:'); ?> +

+

+

+    escape($configString); ?>
+  
+

\ No newline at end of file