Actions
Bug #34152
closedstdWrap function numRows() fails in 4.6 due to wrong SELECT clause
Start date:
2012-02-21
Due date:
% Done:
100%
Estimated time:
TYPO3 Version:
4.5
PHP Version:
5.3
Tags:
Complexity:
Is Regression:
Sprint Focus:
Description
Hello,
this piece of TS does not work anymore since an update from 4.5.11 to 4.6.4:
ATagParams.cObject = TEXT ATagParams.cObject { value = class="hasSubpage" if.isTrue.numRows { table = pages select { pidInList.field = uid where = doktype IN (1,199) } } }
While tracking tslib_cObj::getQuery(), I found out that the sanitizeSelectPart() is introcuced since 4.6. This uses the PHP function strpos() to check if wildcard is set in the SELECT clause, which leads to wrong SQL query in the special case of tslib_cObj::numRows(), where 'count(*)' is set in selectFields property.
The retrieved SQL query would be:
SELECT count(*), pages.uid as uid, pages.pid as pid, pages.t3ver_state as t3ver_state FROM pages WHERE pages.pid IN (6) AND nav_hide!=1 AND doktype!=5 AND doktype!=6 AND pages.deleted=0 AND pages.hidden=0 AND pages.starttime<=1329827460 AND (pages.endtime=0 OR pages.endtime>1329827460) AND NOT pages.t3ver_state>0 AND pages.doktype<200 AND (pages.fe_group='' OR pages.fe_group IS NULL OR pages.fe_group='0' OR FIND_IN_SET('0',pages.fe_group) OR FIND_IN_SET('-1',pages.fe_group))
but the expected SQL query should be:
SELECT count(*) FROM pages WHERE pages.pid IN (6) AND nav_hide!=1 AND doktype!=5 AND doktype!=6 AND pages.deleted=0 AND pages.hidden=0 AND pages.starttime<=1329827460 AND (pages.endtime=0 OR pages.endtime>1329827460) AND NOT pages.t3ver_state>0 AND pages.doktype<200 AND (pages.fe_group='' OR pages.fe_group IS NULL OR pages.fe_group='0' OR FIND_IN_SET('0',pages.fe_group) OR FIND_IN_SET('-1',pages.fe_group))
I would suggest to exclude "count(*)" in the if statement of tslib_cObj::sanitizeSelectPart():
protected function sanitizeSelectPart($selectPart, $table) { // pattern matching parts $matchStart = '/(^\s*|,\s*|' . $table . '\.)'; $matchEnd = '(\s*,|\s*$)/'; $necessaryFields = array('uid', 'pid'); $wsFields = array('t3ver_state'); - if (isset($GLOBALS['TCA'][$table]) && strpos($selectPart, '*')!== FALSE) { + if (isset($GLOBALS['TCA'][$table]) && strpos($selectPart, '*')!== FALSE && $selectPart != 'count(*)') { foreach ($necessaryFields as $field) { $match = $matchStart . $field . $matchEnd; if (!preg_match($match, $selectPart)) { $selectPart .= ', ' . $table . '.' . $field . ' as ' . $field; } } if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) { foreach ($wsFields as $field) { $match = $matchStart . $field . $matchEnd; if (!preg_match($match, $selectPart)) { $selectPart .= ', ' . $table . '.' . $field . ' as ' . $field; } } } } return $selectPart; }
Thank you and best regards,
Alain
Actions