Skip to content

Commit

Permalink
[Bug]: Fix missing QueryBuilder parameter support in Listing Dao (pim…
Browse files Browse the repository at this point in the history
…core#16381)

* use getParameters instead of model->getConditionVariables

* replace string type cast to getSQL

* replace string type cast to getSQL
  • Loading branch information
kingjia90 authored Jan 24, 2024
1 parent ad458f3 commit 3737470
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions doc/20_Extending_Pimcore/17_Custom_Persistent_Models.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ class Dao extends Listing\Dao\AbstractDao
public function loadIdList(): array
{
$query = $this->getQueryBuilder();
$objectIds = $this->db->fetchFirstColumn((string) $query, $this->model->getConditionVariables(), $this->model->getConditionVariableTypes());
$objectIds = $this->db->fetchFirstColumn($query->getSQL(), $query->getParameters(), $query->getParameterTypes());
$this->totalCount = (int) $this->db->fetchOne('SELECT FOUND_ROWS()');

return array_map('intval', $objectIds);
Expand Down Expand Up @@ -447,7 +447,7 @@ class Dao extends Listing\Dao\AbstractDao
$queryBuilder = $this->getQueryBuilder();
$this->prepareQueryBuilderForTotalCount($queryBuilder, $this->getTableName() . '.id');

$totalCount = $this->db->fetchOne((string) $queryBuilder, $this->model->getConditionVariables(), $this->model->getConditionVariableTypes());
$totalCount = $this->db->fetchOne($queryBuilder->getSql(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes());

return (int) $totalCount;
}
Expand Down
6 changes: 3 additions & 3 deletions models/Asset/Listing/Dao.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function load(): array
$assets = [];

$queryBuilder = $this->getQueryBuilder('assets.id', 'assets.type');
$assetsData = $this->db->fetchAllAssociative((string) $queryBuilder, $this->model->getConditionVariables(), $this->model->getConditionVariableTypes());
$assetsData = $this->db->fetchAllAssociative($queryBuilder->getSQL(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes());

foreach ($assetsData as $assetData) {
if ($assetData['type']) {
Expand Down Expand Up @@ -74,7 +74,7 @@ public function getQueryBuilder(...$columns): DoctrineQueryBuilder
public function loadIdList(): array
{
$queryBuilder = $this->getQueryBuilder('assets.id');
$assetIds = $this->db->fetchFirstColumn((string) $queryBuilder, $this->model->getConditionVariables(), $this->model->getConditionVariableTypes());
$assetIds = $this->db->fetchFirstColumn($queryBuilder->getSql(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes());

return array_map('intval', $assetIds);
}
Expand All @@ -95,7 +95,7 @@ public function getTotalCount(): int
$queryBuilder = $this->getQueryBuilder();
$this->prepareQueryBuilderForTotalCount($queryBuilder, 'assets.id');

$amount = (int) $this->db->fetchOne((string) $queryBuilder, $this->model->getConditionVariables(), $this->model->getConditionVariableTypes());
$amount = (int) $this->db->fetchOne($queryBuilder->getSql(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes());

return $amount;
}
Expand Down
4 changes: 2 additions & 2 deletions models/DataObject/Listing/Dao.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function getTotalCount(): int
$queryBuilder = $this->getQueryBuilder();
$this->prepareQueryBuilderForTotalCount($queryBuilder, $this->getTableName() . '.id');

$totalCount = $this->db->fetchOne((string) $queryBuilder, $this->model->getConditionVariables(), $this->model->getConditionVariableTypes());
$totalCount = $this->db->fetchOne($queryBuilder->getSql(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes());

return (int) $totalCount;
}
Expand All @@ -102,7 +102,7 @@ public function getCount(): int
public function loadIdList(): array
{
$queryBuilder = $this->getQueryBuilder([sprintf('%s as id', $this->getTableName() . '.id'), sprintf('%s as `type`', $this->getTableName() . '.type')]);
$objectIds = $this->db->fetchFirstColumn((string) $queryBuilder, $this->model->getConditionVariables(), $this->model->getConditionVariableTypes());
$objectIds = $this->db->fetchFirstColumn($queryBuilder->getSql(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes());

return array_map('intval', $objectIds);
}
Expand Down
8 changes: 4 additions & 4 deletions models/Document/Listing/Dao.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function load(): array
$documents = [];
$select = $this->getQueryBuilder('documents.id', 'documents.type');

$documentsData = $this->db->fetchAllAssociative((string) $select, $this->model->getConditionVariables(), $this->model->getConditionVariableTypes());
$documentsData = $this->db->fetchAllAssociative($select->getSQL(), $select->getParameters(), $select->getParameterTypes());

foreach ($documentsData as $documentData) {
if ($documentData['type']) {
Expand Down Expand Up @@ -76,7 +76,7 @@ public function getQueryBuilder(...$columns): DoctrineQueryBuilder
public function loadIdList(): array
{
$queryBuilder = $this->getQueryBuilder('documents.id');
$documentIds = $this->db->fetchFirstColumn((string) $queryBuilder, $this->model->getConditionVariables(), $this->model->getConditionVariableTypes());
$documentIds = $this->db->fetchFirstColumn($queryBuilder->getSql(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes());

return array_map('intval', $documentIds);
}
Expand All @@ -87,7 +87,7 @@ public function loadIdList(): array
public function loadIdPathList(): array
{
$queryBuilder = $this->getQueryBuilder('documents.id', 'CONCAT(documents.path, documents.key) as `path`');
$documentIds = $this->db->fetchAllAssociative((string) $queryBuilder, $this->model->getConditionVariables(), $this->model->getConditionVariableTypes());
$documentIds = $this->db->fetchAllAssociative($queryBuilder->getSql(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes());

return $documentIds;
}
Expand All @@ -108,7 +108,7 @@ public function getTotalCount(): int
$queryBuilder = $this->getQueryBuilder();
$this->prepareQueryBuilderForTotalCount($queryBuilder, 'documents.id');

$amount = (int) $this->db->fetchOne((string) $queryBuilder, $this->model->getConditionVariables(), $this->model->getConditionVariableTypes());
$amount = (int) $this->db->fetchOne($queryBuilder->getSql(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes());

return $amount;
}
Expand Down
6 changes: 3 additions & 3 deletions models/Translation/Listing/Dao.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function getAllTranslations(): array
if (!empty($this->model->getConditionParams()) || !$translations = Cache::load($cacheKey)) {
$translations = [];
$queryBuilder->setMaxResults(null); //retrieve all results
$translationsData = $this->db->fetchAllAssociative((string) $queryBuilder, $this->model->getConditionVariables());
$translationsData = $this->db->fetchAllAssociative($queryBuilder->getSql(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes());

foreach ($translationsData as $t) {
if (!isset($translations[$t['key']])) {
Expand Down Expand Up @@ -103,7 +103,7 @@ public function getAllTranslations(): array
public function loadRaw(): array
{
$queryBuilder = $this->getQueryBuilder('*');
$translationsData = $this->db->fetchAllAssociative((string) $queryBuilder, $this->model->getConditionVariables());
$translationsData = $this->db->fetchAllAssociative($queryBuilder->getSql(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes());

return $translationsData;
}
Expand All @@ -117,7 +117,7 @@ public function load(): array

if (!empty($this->model->getConditionParams()) || !$translations = Cache::load($cacheKey)) {
$translations = [];
$translationsData = $this->db->fetchAllAssociative((string) $queryBuilder, $this->model->getConditionVariables());
$translationsData = $this->db->fetchAllAssociative($queryBuilder->getSql(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes());
foreach ($translationsData as $t) {
$transObj = Model\Translation::getByKey(id: $t['key'], domain: $this->model->getDomain(), languages: $this->model->getLanguages());

Expand Down

0 comments on commit 3737470

Please sign in to comment.