Skip to content

Commit

Permalink
[BUGFIX] Fix timestamp handling in QueryGenerator
Browse files Browse the repository at this point in the history
Since https://review.typo3.org/c/51242/ all hidden
FormEngine fields work with ISO dates but the
QueryGenerator can only handle unix timestamp.
This patch fix the query building process for
timestamp record fields.

Resolves: #83675
Releases: master, 8.7
Change-Id: I79227762c4159984612d86dea640bdfd8b3a2784
Reviewed-on: https://review.typo3.org/55533
Reviewed-by: Tobi Kretschmann <tobi@tobishome.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Sascha Rademacher <sascha.rademacher+typo3@gmail.com>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
  • Loading branch information
nullwert authored and andreaskienast committed Feb 23, 2018
1 parent 725d8d9 commit 43a9f0c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions typo3/sysext/core/Classes/Database/QueryGenerator.php
Expand Up @@ -1268,6 +1268,13 @@ public function getQuery($queryConfig, $pad = '')
ksort($queryConfig);
$first = 1;
foreach ($queryConfig as $key => $conf) {
// Convert ISO-8601 timestamp (string) into unix timestamp (int)
if (strtotime($conf['inputValue'])) {
$conf['inputValue'] = strtotime($conf['inputValue']);
if ($conf['inputValue1'] && strtotime($conf['inputValue1'])) {
$conf['inputValue1'] = strtotime($conf['inputValue1']);
}
}
switch ($conf['type']) {
case 'newlevel':
$qs .= LF . $pad . trim($conf['operator']) . ' (' . $this->getQuery($queryConfig[$key]['nl'], ($pad . ' ')) . LF . $pad . ')';
Expand Down Expand Up @@ -1353,6 +1360,8 @@ public function cleanInputVal($conf, $suffix = '')
} else {
$inputVal = 0;
}
} elseif (strtotime($conf['inputValue' . $suffix])) {
$inputVal = $conf['inputValue' . $suffix];
} else {
$inputVal = (float)$conf['inputValue' . $suffix];
}
Expand Down Expand Up @@ -1660,20 +1669,19 @@ public function getSelectQuery($qString = ''): string

/**
* @param string $name the field name
* @param int $timestamp the unix timestamp
* @param string $timestamp ISO-8601 timestamp
* @param string $type [datetime, date, time, timesec, year]
*
* @return string
*/
protected function getDateTimePickerField($name, $timestamp, $type)
{
$dateFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['USdateFormat'] ? '%H:%M %m-%d-%Y' : '%H:%M %d-%m-%Y';
$value = ($timestamp > 0 ? strftime($dateFormat, $timestamp) : '');
$value = strtotime($timestamp) ? date($GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'] . ' ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], strtotime($timestamp)) : '';
$id = StringUtility::getUniqueId('dt_');
$html = [];
$html[] = '<div class="input-group" id="' . $id . '-wrapper">';
$html[] = ' <input data-formengine-input-name="' . htmlspecialchars($name) . '" value="' . $value . '" class="form-control t3js-datetimepicker t3js-clearable" data-date-type="' . htmlspecialchars($type) . '" type="text" id="' . $id . '">';
$html[] = ' <input name="' . htmlspecialchars($name) . '" value="' . (int)$timestamp . '" type="hidden">';
$html[] = ' <input name="' . htmlspecialchars($name) . '" value="' . htmlspecialchars($timestamp) . '" type="hidden">';
$html[] = ' <span class="input-group-btn">';
$html[] = ' <label class="btn btn-default" for="' . $id . '">';
$html[] = ' <span class="fa fa-calendar"></span>';
Expand Down

0 comments on commit 43a9f0c

Please sign in to comment.