Commit fc4d5e5e authored by Carsten  Rose's avatar Carsten Rose
Browse files

KeyValueStringParser: issue fixed with withspaces andnothing else.

Store: qfq.ini renamed to config.ini
AbstractBuildForm, Constants, Database: constants renamed: KVP
parent 88f7e3a6
......@@ -10,7 +10,7 @@
/.phpdocinstall
/js
/qfq.flowchart.dia.autosave
/extension/qfq.ini
/extension/config.ini
/support
/extension/Resources/Public/fonts
/extension/Resources/Public/JavaScript
......
......@@ -15,6 +15,7 @@ if (!defined('TYPO3_MODE')) {
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:qfq/Configuration/PageTSconfig/PageTSconfig.ts">');
// By default, the 'tt_content' Header will be rendered: Avoid this,cause it's much nicer to use the header in the backend as a description title of what the record does.
$addLine = '
tt_content.qfq_qfq = COA
tt_content.qfq_qfq {
......
......@@ -614,7 +614,7 @@ abstract class AbstractBuildForm {
}
}
} elseif (isset($formElement['itemList']) && strlen($formElement['itemList']) > 0) {
$arr = KeyValueStringParser::parse($formElement['itemList'], ':', ',', IF_VALUE_EMPTY_COPY_KEY);
$arr = KeyValueStringParser::parse($formElement['itemList'], ':', ',', KVP_IF_VALUE_EMPTY_COPY_KEY);
$itemValue = array_values($arr);
$itemKey = array_keys($arr);
} elseif ($fieldType === 'enum' || $fieldType === 'set') {
......@@ -652,7 +652,7 @@ abstract class AbstractBuildForm {
$fieldTypeDefinition = $this->store->getVar($column, STORE_TABLE_COLUMN_TYPES);
if ($fieldTypeDefinition === false) {
throw new UserException("Column '$column' unknown in table '" . $this->formSpec['tableName'] . "'", ERROR_UNKNOWN_COLUMN);
throw new UserException("Column '$column' unknown in table '" . $this->formSpec['tableName'] . "'", ERROR_DB_UNKNOWN_COLUMN);
}
$length = strlen($fieldTypeDefinition);
......@@ -939,7 +939,7 @@ abstract class AbstractBuildForm {
}
if (!isset($formElement['sql1'][0]['id'])) {
throw new UserException('Missing column \'id\' in \'sql1\' Query', ERROR_MISSING_COLUMN_ID);
throw new UserException('Missing column \'id\' in \'sql1\' Query', ERROR_DB_MISSING_COLUMN_ID);
}
// construct column attributes
......@@ -992,7 +992,7 @@ abstract class AbstractBuildForm {
$control['width'][$columnName] = SUBRECORD_COLUMN_WIDTH;
// a) 'City@width=40', b) 'Status@icon', c) 'Mailto@width=80@nostrip'
$arr = KeyValueStringParser::parse($columnName, '=', '|', IF_VALUE_EMPTY_COPY_KEY);
$arr = KeyValueStringParser::parse($columnName, '=', '|', KVP_IF_VALUE_EMPTY_COPY_KEY);
foreach ($arr as $attribute => $value) {
switch ($attribute) {
case 'width':
......
......@@ -6,7 +6,7 @@
* Time: 8:35 PM
*/
const QFQ_INI = "qfq.ini"; // QFQ configuration file: db access
const CONFIG_INI = "config.ini"; // QFQ configuration file: db access
const QFQ_LOG = 'qfq.log';
......@@ -57,8 +57,8 @@ const ROW_EXPECT_GE_1 = "expect_ge_1";
const ROW_KEYS = "keys";
// KeyValueParser
const IF_VALUE_EMPTY_COPY_KEY = 'if_value_empty_copy_key';
const VALUE_GIVEN = 'value_given';
const KVP_IF_VALUE_EMPTY_COPY_KEY = 'if_value_empty_copy_key';
const KVP_VALUE_GIVEN = 'value_given';
// BuildForm
const SUBRECORD_COLUMN_WIDTH = 20;
......@@ -68,9 +68,8 @@ const FORM_ELEMENTS_NATIVE_SUBRECORD = 'native_subrecord';
// QFQ Error Codes
const ERROR_UNKNOW_SANATIZE_CLASS = 1001;
const ERROR_OPEN_DATABASE = 1002;
const ERROR_CODE_SHOULD_NOT_HAPPEN = 1003;
const ERROR_VALUE_ALREADY_CODPIED = 1004;
const ERROR_SIP_MALFORMED = 1005;
const ERROR_SIP_INVALID = 1006;
//const ERROR_MISSING_FORM_NAME = 1007;
......@@ -89,23 +88,18 @@ const ERROR_FORM_UNKNOWN_PERMISSION_MODE = 1019;
const ERROR_MULTI_SQL_MISSING = 1020;
const ERROR_MISSING_OPEN_DELIMITER = 1021;
const ERROR_RECURSION_TOO_DEEP = 1022;
const ERROR_UNKNOWN_COLUMN = 1023;
const ERROR_CHECKBOXMODE_UNKNOWN = 1024;
const ERROR_MISSING_SQL1 = 1025;
const ERROR_CHECKBOX_EQUAL = 1026;
const ERROR_MISSING_ITEM_VALUES = 1027;
const ERROR_UNKNOWN_FORM_RENDER = 1028;
const ERROR_NAME_LABEL_EMPTY = 1029;
const ERROR_MISSING_COLUMN_ID = 1030;
const ERROR_DEBUG = 1031;
const ERROR_UNKNOWN_MODE = 1032;
const ERROR_NOT_IMPLEMENTED = 1033;
const ERROR_RESERVED_KEY_NAME = 1034;
const ERROR_VALUE_HAS_NO_KEY = 1035;
const ERROR_UNKNOWN_FORWARD_MODE = 1036;
const ERROR_COLUMN_NOT_FOUND_IN_TABLE = 1037;
const ERROR_MISSING_HIDDEN_FIELD_IN_SIP = 1038;
const ERROR_KEY_EXIST_IN_STORE = 1039;
const ERROR_MISSING_MIN_MAX = 1040;
const ERROR_MIN_MAX_VIOLATION = 1041;
const ERROR_UNKNOWN_CHECKTYPE = 1042;
......@@ -117,20 +111,28 @@ const ERROR_GET_STORE_ZERO = 1047;
const ERROR_SET_STORE_ZERO = 1048;
const ERROR_MISSING_FORMELEMENT = 1049;
const ERROR_DB_EXECUTE = 1050;
const ERROR_DB_PREPARE = 1051;
const ERROR_DB_BIND = 1052;
const ERROR_DB_QUERY = 1053;
// Store
const ERROR_STORE_VALUE_ALREADY_CODPIED = 1100;
const ERROR_STORE_KEY_EXIST = 1101;
const ERROR_CLOSE_MYSQLI_RESULT = 1054;
const ERROR_CLOSE_MYSQLI_STMT = 1055;
// KeyValueParser
const ERROR_KVP_VALUE_HAS_NO_KEY = 1900;
// DB Errors
//const ERROR_DB_QUERY_SIMPLE = 2000;
const ERROR_DB_GENERIC_CHECK = 2001;
const ERROR_DB_TOO_FEW_ROWS = 2002;
const ERROR_DB_TOO_MANY_ROWS = 2003;
const ERROR_DB_COUNT_DO_NOT_MATCH = 2004;
const ERROR_DB_OPEN = 2000;
const ERROR_DB_EXECUTE = 2001;
const ERROR_DB_PREPARE = 2002;
const ERROR_DB_BIND = 2003;
const ERROR_DB_QUERY = 2004;
const ERROR_DB_GENERIC_CHECK = 2005;
const ERROR_DB_TOO_FEW_ROWS = 2006;
const ERROR_DB_TOO_MANY_ROWS = 2007;
const ERROR_DB_COUNT_DO_NOT_MATCH = 2008;
const ERROR_DB_CLOSE_MYSQLI_RESULT = 2009;
const ERROR_DB_CLOSE_MYSQLI_STMT = 2010;
const ERROR_DB_UNKNOWN_COLUMN = 2011;
const ERROR_DB_MISSING_COLUMN_ID = 2012;
const ERROR_DB_COLUMN_NOT_FOUND_IN_TABLE = 2013;
//
// Store Names: Identifier
//
......@@ -145,7 +147,7 @@ const STORE_TYPO3 = "T"; // Typo3 > Page content record > bodytext
const STORE_ZERO = "0"; // value: 0, might helpfull if variable is empty but used in an SQL statement, which might produce a SQL error otherwise if substituted with an empty string
const STORE_SYSTEM = "Y"; // various system values like db connection credentials
const USE_STORE_DEFAULT = "FSRD";
const STORE_USE_DEFAULT = "FSRD";
//
// Store: Definitions / Members
......
......@@ -84,7 +84,7 @@ class Database {
$mysqli = new \mysqli($dbserver, $dbuser, $dbpw, $db);
if ($mysqli->connect_error) {
throw new UserException ("Error open Database 'mysql:host=" . $dbserver . ";dbname=" . $db . ";dbuser=" . $dbuser . "'': " . $mysqli->connect_errno . PHP_EOL . $mysqli->connect_error, ERROR_OPEN_DATABASE);
throw new UserException ("Error open Database 'mysql:host=" . $dbserver . ";dbname=" . $db . ";dbuser=" . $dbuser . "'': " . $mysqli->connect_errno . PHP_EOL . $mysqli->connect_error, ERROR_DB_OPEN);
}
return $mysqli;
......@@ -158,7 +158,7 @@ class Database {
return $row;
}
}
throw new DbException("Column name '$columnName' not found in table '$table'.", ERROR_COLUMN_NOT_FOUND_IN_TABLE);
throw new DbException("Column name '$columnName' not found in table '$table'.", ERROR_DB_COLUMN_NOT_FOUND_IN_TABLE);
}
/**
......@@ -274,7 +274,7 @@ class Database {
if ($this->mysqli_stmt !== null && $this->mysqli_stmt !== false) {
$this->mysqli_stmt->free_result();
if (!$this->mysqli_stmt->close())
throw new DbException('Error closing mysqli_stmt' . ERROR_CLOSE_MYSQLI_STMT);
throw new DbException('Error closing mysqli_stmt' . ERROR_DB_CLOSE_MYSQLI_STMT);
}
$this->mysqli_stmt = null;
$this->mysqli_result = null;
......@@ -411,9 +411,6 @@ class Database {
* All rows and all columns imploded to one string if $mode=IMPLODE_ALL
*
*/
/**
* @return array|bool|mixed|string
*/
private function fetchAll($mode = '', &$keys = array()) {
if ($this->mysqli_result == null || $this->mysqli_result == false) {
return false;
......
......@@ -88,7 +88,7 @@ class KeyValueStringParser {
* @throws UserException Thrown if there is a value but no key.
*/
public static function parse($keyValueString, $keyValueDelimiter = ":", $listDelimiter = ",", $valueMode = VALUE_GIVEN) {
public static function parse($keyValueString, $keyValueDelimiter = ":", $listDelimiter = ",", $valueMode = KVP_VALUE_GIVEN) {
if ($keyValueString === "") {
return array();
}
......@@ -101,7 +101,7 @@ class KeyValueStringParser {
$returnValue = array();
foreach ($keyValuePairs as $keyValuePairString) {
if ($keyValuePairString === "") {
if (trim($keyValuePairString === "")) {
continue;
}
......@@ -116,7 +116,7 @@ class KeyValueStringParser {
if ($key === '') {
// ":", ":1"
throw new UserException("Value has no key: '$keyValuePairString'", ERROR_VALUE_HAS_NO_KEY);
throw new UserException("Value has no key: '$keyValuePairString'", ERROR_KVP_VALUE_HAS_NO_KEY);
}
if (count($keyValueArray) === 2) {
......@@ -124,7 +124,7 @@ class KeyValueStringParser {
$returnValue[$key] = self::removeSourroundingQuotes(trim($keyValueArray[1]));
} else {
// no Value given: "a"
$returnValue[$key] = ($valueMode === VALUE_GIVEN) ? "" : $key;
$returnValue[$key] = ($valueMode === KVP_VALUE_GIVEN) ? "" : $key;
}
}
......
......@@ -156,9 +156,9 @@ class Store {
try {
//TODO: Vernuenftige Fehlermeldung falls nicht auf qfq.ini zugegriffen werden kann.
//TODO: sinnvollen Platz fuer qfq.ini bestimmen. In der Installationsdoku erwaehnen.
$config = parse_ini_file(__DIR__ . '/../../../' . QFQ_INI, false);
$config = parse_ini_file(__DIR__ . '/../../../' . CONFIG_INI, false);
} catch (\Exception $e) {
throw new qfq\UserException ("Error read file " . QFQ_INI . ": " . $e->getMessage(), ERROR_READ_FILE);
throw new qfq\UserException ("Error read file " . CONFIG_INI . ": " . $e->getMessage(), ERROR_READ_FILE);
}
self::setVarArray($config, STORE_SYSTEM, true);
}
......@@ -178,7 +178,7 @@ class Store {
throw new CodeException("setVarArray() for STORE_ZERO is impossible - there are no values.", ERROR_SET_STORE_ZERO);
if ($flagOverwrite && isset(self::$raw[$store]) && count(self::$raw[$store]) > 0) {
throw new CodeException("Raw values already been copied to store '$store'. Do this only one time.", ERROR_VALUE_ALREADY_CODPIED);
throw new CodeException("Raw values already been copied to store '$store'. Do this only one time.", ERROR_STORE_VALUE_ALREADY_CODPIED);
}
self::$raw[$store] = $dataArray;
......@@ -204,10 +204,6 @@ class Store {
self::setVarArray($arr, STORE_TYPO3, true);
}
/*
*
*/
/**
* @throws CodeException
*/
......@@ -249,11 +245,11 @@ class Store {
* @param string $sanatizeClass
* @return string a) if found: value, b) false
*/
public static function getVar($key, $useStores = USE_STORE_DEFAULT, $sanatizeClass = '') {
public static function getVar($key, $useStores = STORE_USE_DEFAULT, $sanatizeClass = '') {
// no store specifed?
if ($useStores === "" || $useStores === null) {
$useStores = USE_STORE_DEFAULT;
$useStores = STORE_USE_DEFAULT;
}
// no sanatizeClass specified: take last/default
......@@ -377,7 +373,7 @@ class Store {
throw new CodeException("setVar() for STORE_ZERO is impossible - there are no values.", ERROR_SET_STORE_ZERO);
if ($overWrite === false && isset(self::$raw[$store][$key])) {
throw new UserException("Value of '$key' already be set in store '$store'.", ERROR_KEY_EXIST_IN_STORE);
throw new UserException("Value of '$key' already be set in store '$store'.", ERROR_STORE_KEY_EXIST);
}
self::$raw[$store][$key] = $value;
......
......@@ -130,7 +130,7 @@ class KeyValueStringParserTest extends \PHPUnit_Framework_TestCase {
}
public function testParseKeyValueSingle() {
$actual = keyValueStringParser::parse('value1,value2', ':', ',', IF_VALUE_EMPTY_COPY_KEY);
$actual = keyValueStringParser::parse('value1,value2', ':', ',', KVP_IF_VALUE_EMPTY_COPY_KEY);
$expected = [
'value1' => 'value1',
'value2' => 'value2',
......@@ -138,7 +138,7 @@ class KeyValueStringParserTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals($expected, $actual);
$this->assertCount(2, $actual);
$actual = keyValueStringParser::parse('key1:value1,key2:value2', ':', ',', IF_VALUE_EMPTY_COPY_KEY);
$actual = keyValueStringParser::parse('key1:value1,key2:value2', ':', ',', KVP_IF_VALUE_EMPTY_COPY_KEY);
$expected = [
'key1' => 'value1',
'key2' => 'value2',
......@@ -146,7 +146,7 @@ class KeyValueStringParserTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals($expected, $actual);
$this->assertCount(2, $actual);
$actual = keyValueStringParser::parse('key1:value1,key2:value2', ':', ',', VALUE_GIVEN);
$actual = keyValueStringParser::parse('key1:value1,key2:value2', ':', ',', KVP_VALUE_GIVEN);
$expected = [
'key1' => 'value1',
'key2' => 'value2',
......@@ -154,7 +154,7 @@ class KeyValueStringParserTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals($expected, $actual);
$this->assertCount(2, $actual);
$actual = keyValueStringParser::parse('value1,value2', ':', ',', VALUE_GIVEN);
$actual = keyValueStringParser::parse('value1,value2', ':', ',', KVP_VALUE_GIVEN);
$expected = [
'value1' => '',
'value2' => '',
......
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