diff --git a/extension/qfq/qfq/AbstractBuildForm.php b/extension/qfq/qfq/AbstractBuildForm.php index 6af125ba23a3fa4d671e9290810e3eab312f70d8..b6e012d95f3ea6be5c68060403abe3eadc781923 100644 --- a/extension/qfq/qfq/AbstractBuildForm.php +++ b/extension/qfq/qfq/AbstractBuildForm.php @@ -323,8 +323,8 @@ abstract class AbstractBuildForm { $debugStack = array(); - // Log / Debug - $this->store->setVar(SYSTEM_FORM_ELEMENT, $fe['name'] . ' / ' . $fe['id'], STORE_SYSTEM); + // Preparation for Log, Debug + $this->store->setVar(SYSTEM_FORM_ELEMENT, Logger::formatFormElementName($fe), STORE_SYSTEM); // evaluate current FormElement $evaluate = new Evaluate($this->store, $this->db); @@ -670,7 +670,8 @@ abstract class AbstractBuildForm { $attribute .= Support::doAttribute('disabled', 'disabled'); break; default: - $this->store->setVar(SYSTEM_FORM_ELEMENT, $formElement['name'] . ' / ' . $formElement['id'], STORE_SYSTEM); + // Preparation for Log, Debug + $this->store->setVar(SYSTEM_FORM_ELEMENT, Logger::formatFormElementName($formElement), STORE_SYSTEM); $this->store->setVar(SYSTEM_FORM_ELEMENT_COLUMN, 'mode', STORE_SYSTEM); throw new UserFormException("Unknown mode '" . $formElement['mode'] . "'", ERROR_UNKNOWN_MODE); break; diff --git a/extension/qfq/qfq/BuildFormBootstrap.php b/extension/qfq/qfq/BuildFormBootstrap.php index 14cb2ebea5139e778d7b15ef161be29750dab9c2..215512d9d7515fa12e8842b152bbb5df73955cc1 100644 --- a/extension/qfq/qfq/BuildFormBootstrap.php +++ b/extension/qfq/qfq/BuildFormBootstrap.php @@ -231,7 +231,7 @@ class BuildFormBootstrap extends AbstractBuildForm { $ii++; if ($formElement['name'] === '' || $formElement['label'] === '') { - $this->store->setVar(SYSTEM_FORM_ELEMENT, $formElement['name'] . ' / ' . $formElement['id'], STORE_SYSTEM); + $this->store->setVar(SYSTEM_FORM_ELEMENT, Logger::formatFormElementName($formElement), STORE_SYSTEM); $this->store->setVar(SYSTEM_FORM_ELEMENT_COLUMN, 'name, label', STORE_SYSTEM); throw new UserFormException("Field 'name' and/or 'label' are empty", ERROR_NAME_LABEL_EMPTY); } diff --git a/extension/qfq/qfq/QuickFormQuery.php b/extension/qfq/qfq/QuickFormQuery.php index 9e5b70ffbd4c78070ae2c5834cb10943cf395491..378d5f47d050b7ca358c9584ac15a63543a66baf 100644 --- a/extension/qfq/qfq/QuickFormQuery.php +++ b/extension/qfq/qfq/QuickFormQuery.php @@ -273,6 +273,8 @@ class QuickFormQuery { if (false === ($formName = $this->getFormName($mode, $foundInStore))) { return false; } + + // Preparation for Log, Debug $this->store->setVar(SYSTEM_FORM, $formName, STORE_SYSTEM); // Check if there is a recordId specified in Bodytext - as variable or query. diff --git a/extension/qfq/qfq/Save.php b/extension/qfq/qfq/Save.php index e4cc4c38b794959b81ecba923bf7435786177f5b..6256308056c478929d1ad89e317dd01af2d42a78 100644 --- a/extension/qfq/qfq/Save.php +++ b/extension/qfq/qfq/Save.php @@ -94,7 +94,7 @@ class Save { continue; // Preparation for Log, Debug - $this->store->setVar(SYSTEM_FORM_ELEMENT, $formElement['name'] . ' / ' . $formElement['id'], STORE_SYSTEM); + $this->store->setVar(SYSTEM_FORM_ELEMENT, Logger::formatFormElementName($formElement), STORE_SYSTEM); if (isset($formValues[$column])) { $newValues[$column] = $formValues[$column]; diff --git a/extension/qfq/qfq/exceptions/AbstractException.php b/extension/qfq/qfq/exceptions/AbstractException.php index 27ae847219dfae38c993669ba40fed8eb9ee1f26..c5c2d17203497fd6e43c25913d17044eb524c8d2 100644 --- a/extension/qfq/qfq/exceptions/AbstractException.php +++ b/extension/qfq/qfq/exceptions/AbstractException.php @@ -26,6 +26,7 @@ class AbstractException extends \Exception { public function formatException() { $debug = ''; $store = Store::getInstance(); + $html = ''; $this->messageArray['File'] = $this->getFile(); $this->messageArray['Line'] = $this->getLine(); @@ -35,10 +36,19 @@ class AbstractException extends \Exception { $this->messageArray['Page Id'] = $store->getVar(TYPO3_PAGE_ID, STORE_TYPO3); $this->messageArray['Content Id'] = $store->getVar(TYPO3_TT_CONTENT_UID, STORE_TYPO3); - $html = "<h2>Error</h2>"; - $html .= "<p>Code: " . $this->messageArray['Code'] . "</p>"; - $html .= "<p>Message: <strong>" . $this->messageArray['Message'] . "</strong></p>"; - $html = "<div class='warning'>$html</div>"; + $html .= "Code: " . $this->messageArray['Code'] . "<br>"; + $html .= "Message: " . Support::wrapTag("<strong>", $this->messageArray['Message']) . "</br>"; + + if (isset($this->messageArray['Form'])) { + $html .= "Form: " . Support::wrapTag("<strong>", $this->messageArray['Form']) . "</br>"; + } + + if (isset($this->messageArray['Form Element'])) { + $html .= "Form Element: " . Support::wrapTag("<strong>", $this->messageArray['Form Element']) . "</br>"; + } + + $html = "<h2>Error</h2>" . Support::wrapTag('<p>', $html); + $html = Support::wrapTag("<div class='warning'>", $html); if ($store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) === 'yes') { diff --git a/extension/qfq/qfq/helper/HelperFormElement.php b/extension/qfq/qfq/helper/HelperFormElement.php index 0d2bf4fc944b04c6a827c8d28469e77f8c1ab011..958c4fcfad24d12fd94f60ad570c7fe9e20b824c 100644 --- a/extension/qfq/qfq/helper/HelperFormElement.php +++ b/extension/qfq/qfq/helper/HelperFormElement.php @@ -51,7 +51,7 @@ class HelperFormElement foreach ($checkKeys AS $checkKey) { if (isset($element[$checkKey])) { $store = Store::getInstance(); - $store->setVar(SYSTEM_FORM_ELEMENT, $element['name'] . ' / ' . $element['id'], STORE_SYSTEM); + $store->setVar(SYSTEM_FORM_ELEMENT, Logger::formatFormElementName($element), STORE_SYSTEM); $store->setVar(SYSTEM_FORM_ELEMENT_COLUMN, 'parameter', STORE_SYSTEM); throw new UserFormException("Found reserved keyname '$checkKey'", ERROR_RESERVED_KEY_NAME); } diff --git a/extension/qfq/qfq/helper/Logger.php b/extension/qfq/qfq/helper/Logger.php index 4ea913a7a3450ca6fe15aef2e8480afa4cdc37ca..81570166fbec94699e5730f5d072331419d3f3ae 100644 --- a/extension/qfq/qfq/helper/Logger.php +++ b/extension/qfq/qfq/helper/Logger.php @@ -34,4 +34,14 @@ class Logger { fclose($handle); } // logMessage() + /** + * @param array $fe + */ + public static function formatFormElementName(array $fe) { + Support::setIfNotSet($fe, 'id'); + Support::setIfNotSet($fe, 'name'); + Support::setIfNotSet($fe, 'label'); + + return $fe['id'] . ' / ' . $fe['name'] . ' / ' . $fe['label']; + } } \ No newline at end of file diff --git a/extension/qfq/qfq/helper/Support.php b/extension/qfq/qfq/helper/Support.php index ea8ec1d447d896b122d4aa6de454dae8668d5674..61c2fa61ea0c3c8c06eb5ffb4eb5647b29c51e85 100644 --- a/extension/qfq/qfq/helper/Support.php +++ b/extension/qfq/qfq/helper/Support.php @@ -270,4 +270,15 @@ class Support { $token = (strpos($url, '?') === false) ? '?' : '&'; return $url . $token . $param; } + + /** + * @param $arr + * @param $index + * @param string $value + */ + public static function setIfNotSet(&$arr, $index, $value = '') { + + if (!isset($arr[$index])) + $arr[$index] = $value; + } } \ No newline at end of file diff --git a/extension/qfq/qfq/store/FillStoreForm.php b/extension/qfq/qfq/store/FillStoreForm.php index 50d0e3c0df00a763740b414f6b4e4d684317a2d3..4f29ef5a2c603a86a6ce608c17df2d813d94adf4 100644 --- a/extension/qfq/qfq/store/FillStoreForm.php +++ b/extension/qfq/qfq/store/FillStoreForm.php @@ -48,9 +48,12 @@ class FillStoreForm { * @throws UserFormException */ private function loadFormElementsBasedOnSIP() { - $form = $this->store->getVar(SIP_FORM, STORE_SIP); + $formName = $this->store->getVar(SIP_FORM, STORE_SIP); - $feSpecNative = $this->db->sql(SQL_FORM_ELEMENT_SIMPLE_ALL_CONTAINER, ROW_REGULAR, [$form]); + // Preparation for Log, Debug + $this->store->setVar(SYSTEM_FORM, $formName, STORE_SYSTEM); + + $feSpecNative = $this->db->sql(SQL_FORM_ELEMENT_SIMPLE_ALL_CONTAINER, ROW_REGULAR, [$formName]); if (count($feSpecNative) === 0) { throw new UserFormException('Form not found or multiple forms with the same name.', ERROR_FORM_NOT_FOUND); @@ -82,6 +85,9 @@ class FillStoreForm { if ($formElement['name'] === 'id') continue; + // Preparation for Log, Debug + $this->store->setVar(SYSTEM_FORM_ELEMENT, Logger::formatFormElementName($formElement), STORE_SYSTEM); + // Get related formElement. // construct the field name used in the form $clientFieldName = HelperFormElement::buildFormElementId($formElement['name'], $sipValues[SIP_RECORD_ID]); @@ -115,14 +121,13 @@ class FillStoreForm { $clientValues[$clientFieldName] = implode(',', $clientValues[$clientFieldName]); } - try { -// $newValues[$formElement['name']] = $this->validateValue($formElement, $clientValues[$clientFieldName]); +// try { $newValues[$formElement['name']] = Sanitize::sanitize($clientValues[$clientFieldName], $formElement['checkType'], $formElement['checkPattern'], SANATIZE_EXCEPTION); - } catch (UserFormException $e) { - throw new UserFormException("Form element '" . $formElement['name'] . ' / ' . - $formElement['label'] . "': " . $e->formatMessage(), SANATIZE_EXCEPTION); - } +// } catch (UserFormException $e) { +// $msg = "Form element '" . $formElement['name'] . ' / ' . $formElement['label'] . "': " . $e->formatMessage(); +// throw new UserFormException($msg, ERROR_SANATIZE_INVALID_VALUE); +// } } else { if ($formElement['mode'] === FE_MODE_REQUIRED) { throw new UserFormException("Missing required value for '" . $formElement['name'] . ' / ' . diff --git a/extension/qfq/tests/phpunit/SupportTest.php b/extension/qfq/tests/phpunit/SupportTest.php index 82a80bd9b3f54df12a01871619cb598d97333cc0..412fc8703a0171dd4df90af7f07a20ed4f4fd9ea 100644 --- a/extension/qfq/tests/phpunit/SupportTest.php +++ b/extension/qfq/tests/phpunit/SupportTest.php @@ -333,6 +333,22 @@ class SupportTest extends \PHPUnit_Framework_TestCase { $this->assertEquals('http://example.com?id=34&a=100&b=201', $url); } + public function testSetIfNotSet() { + $new = array(); + + Support::setIfNotSet($new, 'id'); + $this->assertEquals(['id' => ''], $new); + + $new = array(); + $new['id'] = 1; + Support::setIfNotSet($new, 'id'); + $this->assertEquals(['id' => 1], $new); + + $new = array(); + Support::setIfNotSet($new, 'id', 2); + $this->assertEquals(['id' => 2], $new); + + } protected function setUp() { parent::setUp();