Project

General

Profile

Actions

Bug #85788

closed

Escaping behaviour changed in QueryBuilder

Added by Timo Pfeffer over 5 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Database API (Doctrine DBAL)
Target version:
-
Start date:
2018-08-09
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
8
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

In 7.6 the code below works without any problems. In 8.7 the code below crashes, because the ordering gets escaped in other way, so that it is not possible to implement functions like this anymore.
To be more specific the setOrderings function with the input of orderByField causes the crash.

Code:

public function findByUids($uids){

    if(!isset($uids) || empty($uids)){
        return NULL;
    }

    $uidListString = $uids;
    if(!is_array($uids)){
        $uidListString = explode(',', $uids);
    }

    $query = $this->createQuery();
    $query->getQuerySettings()->setRespectStoragePage(FALSE);

    //here i set the orderings
    $orderings = $this->orderByField('uid', $uidListString);
    $query->setOrderings($orderings);

    $query->matching(
        $query->logicalAnd(
            $query->in('uid', $uidListString)
        )
    );

    return $query->execute();
}

/**
 * @param string $field
 * @param array $values
 *
 * @return array
 */
protected function orderByField($field, $values) {
    $orderings = array();
    foreach ($values as $value) {
        $orderings["$field={$value}"] =  \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING;
    }
    return $orderings;
}

Actions #1

Updated by Stephan Großberndt over 5 years ago

  • Project changed from 9 to TYPO3 Core
  • Category set to Database API (Doctrine DBAL)
  • TYPO3 Version set to 8
Actions #2

Updated by Timo Pfeffer about 5 years ago

Please lookup this ticket or close it if already obsolete or fixed.

Actions #3

Updated by Susanne Moog about 4 years ago

  • Status changed from New to Needs Feedback

I don't quite get the bug.

setOrderings is documented as:

Sets the property names to order the result by. Expected like this:
array(
 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
)

from what I can see, that has not changed at all and should continue to work as documented.

If I read your code right, you are not using a property name as key there and that broke. That in itself is no bug, as it was not documented and expected behaviour to work, however: Are you able to achieve what you want to achieve in another way with the API? For example by using Doctrine directly?

Actions #4

Updated by Christian Kuhn about 2 years ago

  • Status changed from Needs Feedback to Closed

Hey. I hope it's ok to close here due to lack of further feedback.

Actions

Also available in: Atom PDF