From 193bb2e93459b1c7a11ddc7099cb51762841f67a Mon Sep 17 00:00:00 2001
From: Carsten  Rose <carsten.rose@math.uzh.ch>
Date: Sun, 16 Dec 2018 11:54:57 +0100
Subject: [PATCH] Fixes #7494: Exception 'General Error': disable/enable per
 config.

---
 extension/Documentation/Manual.rst            |  6 ++++++
 extension/Documentation/Release.rst           |  5 +++++
 extension/ext_conf_template.txt               |  7 +++++++
 extension/qfq/qfq/Constants.php               |  3 +++
 extension/qfq/qfq/exceptions/ErrorHandler.php | 20 ++++++++++++++-----
 extension/qfq/qfq/store/Config.php            |  3 +++
 extension/qfq/qfq/store/Store.php             |  4 ++++
 7 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/extension/Documentation/Manual.rst b/extension/Documentation/Manual.rst
index 43ace6634..91669c271 100644
--- a/extension/Documentation/Manual.rst
+++ b/extension/Documentation/Manual.rst
@@ -358,6 +358,8 @@ Extension Manager: QFQ Configuration
 | documentation                 | http://docs.typo3.org...                              | Link to the online documentation of QFQ. Every QFQ installation also       |
 |                               |                                                       | contains a local copy: typo3conf/ext/qfq/Documentation/html/Manual.html    |
 +-------------------------------+-------------------------------------------------------+----------------------------------------------------------------------------+
+| flagProduction                | yes                                                   | yes|no: might be used to differentiate the installation                    |
++-------------------------------+-------------------------------------------------------+----------------------------------------------------------------------------+
 | thumbnailDirSecure            | fileadmin/protected/qfqThumbnail                      | Important: secure directory 'protected' (recursive) against direct access. |
 +-------------------------------+-------------------------------------------------------+----------------------------------------------------------------------------+
 | thumbnailDirPublic            | typo3temp/qfqThumbnail                                | Both thumbnail directories will be created if not existing.                |
@@ -384,6 +386,10 @@ Extension Manager: QFQ Configuration
 +-------------------------------+-------------------------------------------------------+----------------------------------------------------------------------------+
 | Debug                                                                                                                                                              |
 +-------------------------------+-------------------------------------------------------+----------------------------------------------------------------------------+
+| throwExceptionGeneralError    | auto                                                  | | *yes*: 'general errors' in QFQ (PHP) will throw an exception.            |
+|                               |                                                       | | *auto*: becomes 'yes', if 'flagProduction'!='yes', else 'no'.            |
+|                               |                                                       | | *no*: 'general errors' in QFQ (PHP) will be silently ignored.            |
++-------------------------------+-------------------------------------------------------+----------------------------------------------------------------------------+
 | sqlLogMode                    | modify                                                | | *all*: every statement will be logged - this might a lot.                |
 |                               |                                                       | | *modify*: log only statements who change data. *error*: log only         |
 |                               |                                                       |   DB errors.                                                               |
diff --git a/extension/Documentation/Release.rst b/extension/Documentation/Release.rst
index 6f36c390e..4c9f8d490 100644
--- a/extension/Documentation/Release.rst
+++ b/extension/Documentation/Release.rst
@@ -32,6 +32,11 @@ Notes
 
 * Existing installations: update QFQ extension config form-layout.formBsColumns/formBsLabelColumns/formBsInputColumns,formBsNoteColumns.
   old: 12, new: 'col-md-12 col-lg10' resp. smaller values for individual columnns.
+* New config values:
+
+  * Config/flagProduction: yes/now - differentiate between development und production system. Will be used for
+    'throwExceptionGeneralError' too.
+  * Debug/throwExceptionGeneralError - shows/hide exception of general errors.
 
 Features
 ^^^^^^^^
diff --git a/extension/ext_conf_template.txt b/extension/ext_conf_template.txt
index e24ae39c4..633f060af 100644
--- a/extension/ext_conf_template.txt
+++ b/extension/ext_conf_template.txt
@@ -1,6 +1,9 @@
 # cat=config/config; type=string; label=URL QFQ Documentation:Default is 'https://docs.typo3.org/typo3cms/drafts/github/T3DocumentationStarter/Public-Info-053/Manual.html'. Might be changed to a local repo. Every QFQ installation contains a local copy: <site path>/typo3conf/ext/qfq/Documentation/html/Manual.html (corresponds always to the QFQ version).
 documentation = https://docs.typo3.org/typo3cms/drafts/github/T3DocumentationStarter/Public-Info-053/Manual.html
 
+# cat=config/config; type=string; label=Marks a production installation:Possible values: 'yes', 'no'. Default is 'yes'. Used to differentiate between development & production systems.
+flagProduction = yes
+
 # cat=config/config; type=string; label=Thumbnail directory 'secure':Default is 'fileadmin/protected/qfqThumbnail'. Important: secure the directory (recursive) against direct access. Will be used by a special columnname '_thumbnail'.
 thumbnailDirSecure = fileadmin/protected/qfqThumbnail
 
@@ -45,6 +48,10 @@ fillStoreSystemBySql3 =
 fillStoreSystemBySqlErrorMsg3 =
 
 
+
+# cat=debug/debug; type=string; label=Throw exception General Error:Possible values: 'yes', 'no', 'auto'. Default is 'auto'. If a) 'yes' or b) 'auto' and 'flagProduction!=yes', throw an exception in case of a 'General Error'.
+throwExceptionGeneralError = auto
+
 # cat=debug/mail; type=string; label=Redirect all mail to ...:Default is empty. If set, redirect all QFQ generated mails (Form, Report) to the specified email address.
 redirectAllMailTo =
 
diff --git a/extension/qfq/qfq/Constants.php b/extension/qfq/qfq/Constants.php
index 88bf4f58c..f198921bd 100644
--- a/extension/qfq/qfq/Constants.php
+++ b/extension/qfq/qfq/Constants.php
@@ -454,6 +454,9 @@ const SYSTEM_REDIRECT_ALL_MAIL_TO = 'redirectAllMailTo';
 const SYSTEM_MAIL_LOG = 'mailLog';
 const SYSTEM_MAIL_LOG_FILE = 'fileadmin/protected/log/mail.log';
 
+const SYSTEM_THROW_GENERAL_ERROR = 'throwExceptionGeneralError';
+const SYSTEM_FLAG_PRODUCTION = 'flagProduction';
+
 const SYSTEM_SHOW_DEBUG_INFO = 'showDebugInfo';
 const SYSTEM_SHOW_DEBUG_INFO_YES = 'yes';
 const SYSTEM_SHOW_DEBUG_INFO_NO = 'no';
diff --git a/extension/qfq/qfq/exceptions/ErrorHandler.php b/extension/qfq/qfq/exceptions/ErrorHandler.php
index 65c371cd1..e213a9bf3 100644
--- a/extension/qfq/qfq/exceptions/ErrorHandler.php
+++ b/extension/qfq/qfq/exceptions/ErrorHandler.php
@@ -8,6 +8,7 @@
 
 namespace qfq;
 
+require_once(__DIR__ . '/../store/Store.php');
 
 /**
  * Class ErrorHandler
@@ -23,6 +24,8 @@ class ErrorHandler {
      * @param $line
      * @return bool|string
      * @throws CodeException
+     * @throws UserFormException
+     * @throws UserReportException
      */
     public static function exception_error_handler($severity, $message, $file, $line) {
 
@@ -31,11 +34,18 @@ class ErrorHandler {
             return false;
         }
 
-        // Do not show too much to the user. E.g. 'ldap_bind()' might have problems, but the user should not see the
-        // file and line number. Often the filename is part of the message >> don't show the message to the user.
-        throw new CodeException(json_encode(
-            [ERROR_MESSAGE_TO_USER => 'General error - please report.',
-                ERROR_MESSAGE_SUPPORT => "File: $file / Line: $line / $message"]), $severity, null);
+        $store = Store::getInstance();
+        if($store->getVar(SYSTEM_THROW_GENERAL_ERROR, STORE_SYSTEM) == 'yes'){
+
+            // Do not show too much to the user. E.g. 'ldap_bind()' might have problems, but the user should not see the
+            // file and line number. Often the filename is part of the message >> don't show the message to the user.
+            throw new CodeException(json_encode(
+                [ERROR_MESSAGE_TO_USER => 'General error - please report.',
+                    ERROR_MESSAGE_SUPPORT => "File: $file / Line: $line / $message"]), $severity, null);
+
+        }
+
+        return true;
     }
 
 }
\ No newline at end of file
diff --git a/extension/qfq/qfq/store/Config.php b/extension/qfq/qfq/store/Config.php
index e3cb801c7..1c63ce319 100644
--- a/extension/qfq/qfq/store/Config.php
+++ b/extension/qfq/qfq/store/Config.php
@@ -351,6 +351,9 @@ class Config {
             F_FE_DATA_REQUIRED_ERROR => F_FE_DATA_REQUIRED_ERROR_DEFAULT,
             F_FE_DATA_MATCH_ERROR => F_FE_DATA_MATCH_ERROR_DEFAULT,
             F_FE_DATA_ERROR => 'error',
+
+            SYSTEM_FLAG_PRODUCTION => 'yes',
+            SYSTEM_THROW_GENERAL_ERROR => 'auto',
         ];
 
         // To let run legacy code
diff --git a/extension/qfq/qfq/store/Store.php b/extension/qfq/qfq/store/Store.php
index e40f70c6c..4e287d54f 100644
--- a/extension/qfq/qfq/store/Store.php
+++ b/extension/qfq/qfq/store/Store.php
@@ -300,6 +300,10 @@ class Store {
             $config[SYSTEM_DB_1_NAME] = $config[SYSTEM_DB_NAME];
         }
 
+        if ($config[SYSTEM_THROW_GENERAL_ERROR] == 'auto') {
+            $config[SYSTEM_THROW_GENERAL_ERROR] = $config[SYSTEM_FLAG_PRODUCTION] == 'yes' ? 'no' : 'yes';
+        }
+
         return $config;
     }
 
-- 
GitLab