Commit 6827cb93 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Feature #4967 / config.qfq.ini: Rename 'VAR_ADD_BY_SQL' to 'FILL_STORE_SYSTEM_BY_SQL_1'

OnArray.php: new function keyNameRemoveLeadingUnderscore().
Report: Introduce constant TOKEN_COLUMN_CTRL.
Config.php: Implement function 'checkDeprecated().
Store.php: Update StoreSystemUpdate() to handle up to 3 FILL_STORE_SYSTEM_SQL_x. Implement an optional error message together with a full stop.
parent c49eee5b
......@@ -108,7 +108,9 @@ WKHTMLTOPDF = /opt/wkhtmltox/bin/wkhtmltopdf
; Local Documentation (doc fits to installed version): typo3conf/ext/qfq/Documentation/html/Manual.html
;DOCUMENTATION_QFQ = https://docs.typo3.org/typo3cms/drafts/github/T3DocumentationStarter/Public-Info-053/Manual.html
; VAR_ADD_BY_SQL = "SELECT id AS _periodId FROM Period WHERE start<=NOW() ORDER BY start DESC LIMIT 1"
; FILL_STORE_SYSTEM_BY_SQL_1 = "SELECT id AS _periodId FROM Period WHERE start<=NOW() ORDER BY start DESC LIMIT 1"
; Important: only define an error message, if QFQ should stop running in case of an SQL error or not exact 1 record.
; FILL_STORE_SYSTEM_BY_SQL_ERROR_MSG_1 = No current period found
; FORM_LANGUAGE_A_ID = E.g. FORM_LANGUAGE_A_ID = 1
; FORM_LANGUAGE_A_LABEL = E.g. FORM_LANGUAGE_A_ID = English
......
......@@ -109,6 +109,7 @@ const ERROR_SIP_INVALID = 1006;
const ERROR_MISSING_RECORD_ID = 1007;
const ERROR_IN_SQL_STATEMENT = 1008;
const ERROR_MISSING_REQUIRED_PARAMETER = 1009;
const ERROR_BROKEN_PARAMETER = 1011;
const ERROR_FE_USER_UID_CHANGED = 1012;
const ERROR_SIP_NOT_FOUND = 1013;
......@@ -118,8 +119,9 @@ const ERROR_SIP_EXIST_BUT_OTHER_PARAM_GIVEN_BY_CLIENT = 1016;
const ERROR_USER_NOT_LOGGED_IN = 1017;
const ERROR_USER_LOGGED_IN = 1018;
const ERROR_FORM_FORBIDDEN = 1019;
const ERROR_FORM_UNKNOWN_PERMISSION_MODE = 10120;
const ERROR_FORM_UNKNOWN_PERMISSION_MODE = 1020;
const ERROR_MULTI_SQL_MISSING = 1021;
const ERROR_RECURSION_TOO_DEEP = 1023;
const ERROR_CHECKBOXMODE_UNKNOWN = 1024;
const ERROR_MISSING_SQL1 = 1025;
......@@ -127,12 +129,16 @@ const ERROR_CHECKBOX_EQUAL = 1026;
const ERROR_MISSING_ITEM_LIST = 1027;
const ERROR_UNKNOWN_FORM_RENDER = 1028;
const ERROR_NAME_LABEL_EMPTY = 1029;
const ERROR_DEBUG = 1031;
const ERROR_UNKNOWN_MODE = 1032;
const ERROR_NOT_IMPLEMENTED = 1033;
const ERROR_RESERVED_KEY_NAME = 1034;
const ERROR_UNKNOWN_FORWARD_MODE = 1036;
const ERROR_MISSING_HIDDEN_FIELD_IN_SIP = 1038;
const ERROR_MISSING_MIN_MAX = 1040;
const ERROR_MIN_MAX_VIOLATION = 1041;
const ERROR_UNKNOWN_CHECKTYPE = 1042;
......@@ -150,7 +156,7 @@ const ERROR_SANATIZE_INVALID_VALUE = 1054;
const ERROR_REQUIRED_VALUE_EMPTY = 1055;
const ERROR_DATE_UNEXPECTED_FORMAT = 1056;
const ERROR_UNEXPECTED_TYPE = 1057;
const ERROR_NOT_APPLICABLE = 108;
const ERROR_NOT_APPLICABLE = 1058;
const ERROR_FORMELEMENT_TYPE = 1059;
const ERROR_MISSING_OPEN_DELIMITER = 1060;
const ERROR_MISSING_CLOSE_DELIMITER = 1061;
......@@ -453,9 +459,13 @@ const SYSTEM_DB_UPDATE_AUTO = 'auto';
const SYSTEM_RECORD_LOCK_TIMEOUT_SECONDS = 'RECORD_LOCK_TIMEOUT_SECONDS';
const SYSTEM_RECORD_LOCK_TIMEOUT_SECONDS_DEFAULT = 900; // 15 mins
// Deprecated, replaced by SYSTEM_FILL_STORE_SYSTEM_BY_SQ
const SYSTEM_VAR_ADD_BY_SQL = 'VAR_ADD_BY_SQL';
const SYSTEM_VAR_ADD_BY_SQL_DEFAULT = 'SELECT id AS periodId FROM Period WHERE start<=NOW() ORDER BY start DESC LIMIT 1';
const SYSTEM_FILL_STORE_SYSTEM_BY_SQL = 'FILL_STORE_SYSTEM_BY_SQL';
const SYSTEM_FILL_STORE_SYSTEM_ERROR_MSG = 'FILL_STORE_SYSTEM_ERROR_MSG';
const SYSTEM_FORM_LANGUAGE = 'FORM_LANGUAGE';
const SYSTEM_FORM_LANGUAGE_A_ID = 'FORM_LANGUAGE_A_ID';
......@@ -567,26 +577,6 @@ const TOKEN_FOUND_AS_DEFAULT = 'default';
const RANDOM_LENGTH = 32;
// Report, BodyText
const TOKEN_SQL = 'sql';
const TOKEN_HEAD = 'head';
const TOKEN_ALT_HEAD = 'althead';
const TOKEN_TAIL = 'tail';
const TOKEN_RBEG = 'rbeg';
const TOKEN_REND = 'rend';
const TOKEN_RENR = 'renr';
const TOKEN_RSEP = 'rsep';
const TOKEN_FBEG = 'fbeg';
const TOKEN_FEND = 'fend';
const TOKEN_FSEP = 'fsep';
const TOKEN_RBGD = 'rbgd';
const TOKEN_DEBUG = 'debug';
const TOKEN_FORM = CLIENT_FORM;
const TOKEN_RECORD_ID = CLIENT_RECORD_ID;
const TOKEN_DEBUG_BODYTEXT = TYPO3_DEBUG_SHOW_BODY_TEXT;
const TOKEN_VALID_LIST = 'sql|head|althead|tail|rbeg|rend|renr|rsep|fbeg|fend|fsep|rbgd|debug|form|r|debugShowBodyText|sqlLog|sqlLogMode';
// FORM - copy from table 'form' of processed form
//const DEF_FORM_NAME = CLIENT_FORM;
......@@ -922,6 +912,7 @@ const FE_INPUT_EXTRA_BUTTON_PASSWORD = 'extraButtonPassword';
const FE_INPUT_EXTRA_BUTTON_INFO = 'extraButtonInfo';
const FE_INPUT_EXTRA_BUTTON_INFO_CLASS = 'extraButtonInfoClass';
const FE_TMP_EXTRA_BUTTON_HTML = '_extraButtonHtml'; // will be filled on the fly during building extrabutton
const FE_TMP_EXTRA_BUTTON_HTML = '_extraButtonHtml'; // will be filled on the fly during building extrabutton
const FE_CHECKBOX_CHECKED = 'checked';
const FE_CHECKBOX_UNCHECKED = 'unchecked';
const FE_RECORD_DESTINATION_TABLE = 'recordDestinationTable';
......@@ -1086,6 +1077,28 @@ const SENDMAIL_TOKEN_X_ID2 = 'y';
const SENDMAIL_TOKEN_X_ID3 = 'z';
const SENDMAIL_TOKEN_SRC = 'S';
// Report, BodyText
const TOKEN_SQL = 'sql';
const TOKEN_HEAD = 'head';
const TOKEN_ALT_HEAD = 'althead';
const TOKEN_TAIL = 'tail';
const TOKEN_RBEG = 'rbeg';
const TOKEN_REND = 'rend';
const TOKEN_RENR = 'renr';
const TOKEN_RSEP = 'rsep';
const TOKEN_FBEG = 'fbeg';
const TOKEN_FEND = 'fend';
const TOKEN_FSEP = 'fsep';
const TOKEN_RBGD = 'rbgd';
const TOKEN_DEBUG = 'debug';
const TOKEN_FORM = CLIENT_FORM;
const TOKEN_RECORD_ID = CLIENT_RECORD_ID;
const TOKEN_DEBUG_BODYTEXT = TYPO3_DEBUG_SHOW_BODY_TEXT;
const TOKEN_VALID_LIST = 'sql|head|althead|tail|rbeg|rend|renr|rsep|fbeg|fend|fsep|rbgd|debug|form|r|debugShowBodyText|sqlLog|sqlLogMode';
const TOKEN_COLUMN_CTRL = '_';
//Report: Column Token
const COLUMN_PPAGE = "Page";
const COLUMN_PPAGEC = "Pagec";
......
......@@ -166,7 +166,7 @@ class QuickFormQuery {
$updateDb = new DatabaseUpdate($this->dbArray[$this->dbIndexQfq]);
$updateDb->checkNupdate($dbUpdate);
$this->store->systemStoreUpdate(); // Do this after the DB-update
$this->store->StoreSystemUpdate(); // Do this after the DB-update
}
/**
......
......@@ -196,6 +196,28 @@ class OnArray {
return $new;
}
/**
* Remove from all keynames an optional '_'.
*
* @param array $arr
*
* @return array
*/
public static function keyNameRemoveLeadingUnderscore(array $arr) {
foreach ($arr as $key => $value) {
if ($key[0] == TOKEN_COLUMN_CTRL) {
$newKey = substr($key, 1);
if (!empty($newKey)) {
$arr[$newKey] = $value;
unset($arr[$key]);
}
}
}
return $arr;
}
/**
* Search in array $dest for all $keyNames if they exist. If not, check if they exist in $src. If yes, copy.
*
......
......@@ -1013,5 +1013,4 @@ class Support {
return $data;
}
}
\ No newline at end of file
......@@ -569,7 +569,7 @@ class Report {
$flagOutput = false;
$renderedColumn = $this->renderColumn($ii, $keys[$ii], $row[$ii], $full_level, $rowIndex, $flagOutput);
$keyAssoc = Support::stripFirstCharIf('_', $keys[$ii]);
$keyAssoc = Support::stripFirstCharIf(TOKEN_COLUMN_CTRL, $keys[$ii]);
if ($keyAssoc != '') {
$assoc[$keyAssoc] = $row[$ii];
}
......@@ -608,7 +608,7 @@ class Report {
$dummy = false;
// Empty columnnames are allowed: check with isset
if (isset($columnName[0]) && $columnName[0] === "_") {
if (isset($columnName[0]) && $columnName[0] === TOKEN_COLUMN_CTRL) {
$flagControl = true;
$columnName = substr($columnName, 1);
}
......
......@@ -43,12 +43,32 @@ class Config {
$config = self::renameConfigElements($config);
$config = self::setDefaults($config);
self::checkDeprecated($config);
self::checkForAttack($config);
return $config;
}
/**
* Checks for deprecated options.
*/
private static function checkDeprecated(array $config) {
foreach ([SYSTEM_VAR_ADD_BY_SQL] as $key) {
if (isset($config[$key])) {
$msg = '';
switch ($key) {
case SYSTEM_VAR_ADD_BY_SQL:
$msg = 'Replaced by: ' . SYSTEM_FILL_STORE_SYSTEM_BY_SQL . '_1|2|3';
}
throw new qfq\UserFormException ("Deprecated option in " . CONFIG_INI . ": " . SYSTEM_VAR_ADD_BY_SQL . " - " . $msg);
}
}
}
/**
* @param array $config
*/
......@@ -187,7 +207,7 @@ class Config {
Support::setIfNotSet($config, DOCUMENTATION_QFQ, DOCUMENTATION_QFQ_URL);
Support::setIfNotSet($config, SYSTEM_VAR_ADD_BY_SQL, SYSTEM_VAR_ADD_BY_SQL_DEFAULT);
Support::setIfNotSet($config, SYSTEM_FILL_STORE_SYSTEM_BY_SQL, SYSTEM_VAR_ADD_BY_SQL_DEFAULT);
return $config;
}
......
......@@ -819,21 +819,42 @@ class Store {
}
/**
* Read SYSTEM_VARIABLES_GET_FROM_DB from SYSTEM_STORE and if set:
* Read SYSTEM_FILL_STORE_SYSTEM_BY_SQL_1|2|3 from SYSTEM_STORE and if set:
* a) fire the SQL
* b) merge all columns to SYSTEM_STORE
* b) merge all columns to STORE_SYSTEM
*/
public static function systemStoreUpdate() {
public static function StoreSystemUpdate() {
$db = null;
$storeSystemAdd = array();
$storeSystem = self::getStore(STORE_SYSTEM);
if (!empty($storeSystem[SYSTEM_VAR_ADD_BY_SQL])) {
$db = new qfq\Database();
$arr = $db->sql($storeSystem[SYSTEM_VAR_ADD_BY_SQL], ROW_EXPECT_0_1);
if (!empty($arr)) {
$storeSystem = array_merge($storeSystem, $arr);
self::setStore($storeSystem, STORE_SYSTEM, true);
for ($ii = 1; $ii <= 3; $ii++) {
if (empty($storeSystem[SYSTEM_FILL_STORE_SYSTEM_BY_SQL . "_$ii"])) {
continue;
}
if ($db == null) {
$db = new qfq\Database();
}
$errMsg = "More than 1 record found. " . CONFIG_INI . ": " . SYSTEM_FILL_STORE_SYSTEM_BY_SQL . "_$ii";
$mode = ROW_EXPECT_0_1;
// If there is an error message defined, this means there should be exactly one record.
if (!empty($storeSystem[SYSTEM_FILL_STORE_SYSTEM_ERROR_MSG . "_$ii"])) {
$mode = ROW_EXPECT_1;
$errMsg = $storeSystem[SYSTEM_FILL_STORE_SYSTEM_ERROR_MSG . "_$ii"];
}
$storeSystemAdd = $db->sql($storeSystem[SYSTEM_FILL_STORE_SYSTEM_BY_SQL . "_$ii"], $mode, array(), $errMsg);
$storeSystemAdd = OnArray::keyNameRemoveLeadingUnderscore($storeSystemAdd);
$storeSystem = array_merge($storeSystem, $storeSystemAdd);
}
if (!empty($storeSystem)) {
self::setStore($storeSystem, STORE_SYSTEM, true);
}
}
......
......@@ -347,8 +347,8 @@ class EvaluateTest extends \AbstractDatabaseTest {
// LDAP_ESCAPE_FILTER => array('\\', '*', '(', ')', "\x00"),
// LDAP_ESCAPE_DN => array('\\', ',', '=', '+', '<', '>', ';', '"', '#'),
$this->store->setVar('a', ' hello world ', STORE_FORM, true);
// $this->assertEquals('\20hello world\20', $eval->substitute('a:F:all:L', $foundInStore));
$this->assertEquals(' hello world ', $eval->substitute('a:F:all:L', $foundInStore));
$this->assertEquals('\20hello world\20', $eval->substitute('a:F:all:L', $foundInStore));
// $this->assertEquals(' hello world ', $eval->substitute('a:F:all:L', $foundInStore));
$this->store->setVar('a', 'h\e,l=l+o< >w;o"r#ld', STORE_FORM, true);
$this->assertEquals('h\5ce\2cl\3dl\2bo\3c \3ew\3bo\22r\23ld', $eval->substitute('a:F:all:L', $foundInStore));
......
......@@ -167,4 +167,15 @@ class OnArrayTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals(['name' => "'john'", 'surname' => "'doe'"], OnArray::arrayEscapeshellarg(['name' => 'john', 'surname' => 'doe']));
$this->assertEquals(['name' => "'john'", 'sub' => ['surname' => "'doe'"]], OnArray::arrayEscapeshellarg(['name' => 'john', 'sub' => ['surname' => 'doe']]));
}
public function testArrayKeyNameRemoveLeadingUnderscore() {
$this->assertEquals(array(), OnArray::keyNameRemoveLeadingUnderscore(array()));
$this->assertEquals(['name' => 'john'], OnArray::keyNameRemoveLeadingUnderscore(['name' => 'john']));
$this->assertEquals(['name' => 'john', 'surname' => 'doe'], OnArray::keyNameRemoveLeadingUnderscore(['name' => 'john', 'surname' => 'doe']));
$this->assertEquals(['name' => '_john'], OnArray::keyNameRemoveLeadingUnderscore(['_name' => '_john']));
$this->assertEquals(['name' => 'john', 'surname' => 'doe'], OnArray::keyNameRemoveLeadingUnderscore(['_name' => 'john', 'surname' => 'doe']));
$this->assertEquals(['name' => 'john', 'surname' => 'doe'], OnArray::keyNameRemoveLeadingUnderscore(['name' => 'john', '_surname' => 'doe']));
$this->assertEquals(['name' => 'john', 'surname' => 'doe'], OnArray::keyNameRemoveLeadingUnderscore(['_name' => 'john', '_surname' => 'doe']));
}
}
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