Commit 2d0d6fc3 authored by Carsten  Rose's avatar Carsten Rose
Browse files

ErrorMessages in exception: generalized

AbstractException.php: If exist, print Form And FormElement names.
HelperFormElement.php, Logger.php, FillStoreForm.php, AbstractBuildForm.php: fomatting form element name.
Support.php: add setIfNotSet()
parent 5bf19ee3
......@@ -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;
......
......@@ -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);
}
......
......@@ -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.
......
......@@ -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];
......
......@@ -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') {
......
......@@ -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);
}
......
......@@ -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
......@@ -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
......@@ -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'] . ' / ' .
......
......@@ -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();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment