Skip to content

Commit ea01905

Browse files
authored
[Improvement]: Add support to DBAL v4 (#295)
* Update composer.json * Update pimcore/pimcore version constraint * Update pimcore/pimcore version in composer.json * fix variantic * Apply php-cs-fixer changes * remove setAlgorithm, bc break from v12 * Apply php-cs-fixer changes * test with typecast test with string 0 fix select * fix * fix * fix * fix * fix tests * fix tests --------- Co-authored-by: kingjia90 <[email protected]>
1 parent 3b1e97d commit ea01905

File tree

8 files changed

+50
-44
lines changed

8 files changed

+50
-44
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"pimcore/static-resolver-bundle": "^1.4.0 || ^2.0",
2424
"pimcore/opensearch-client": "^1.1",
2525
"pimcore/elasticsearch-client": "^1.1",
26-
"doctrine/orm": "^2.17.2",
26+
"doctrine/orm": "^2.17.2 || ^3.0",
2727
"symfony/scheduler": "^6.4",
2828
"symfony/messenger": "^6.4"
2929
},

src/Repository/IndexQueueRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function deleteQueueEntries(array $entries): void
119119
foreach ($chunk as $entry) {
120120
$condition[] = sprintf(
121121
'(elementId = %s AND elementType = %s and operationTime = %s)',
122-
$this->connection->quote($entry->getElementId()),
122+
$this->connection->quote((string)$entry->getElementId()),
123123
$this->connection->quote($entry->getElementType()),
124124
$this->connection->quote($entry->getOperationTime())
125125
);
@@ -155,7 +155,7 @@ public function generateSelectQuery(
155155
array_unshift($fields, $idField);
156156

157157
$qb = $this->connection->createQueryBuilder()
158-
->select($fields)
158+
->addSelect(...$fields)
159159
->from($tableName);
160160

161161
$this->addWhereStatements($qb, $whereParameters);

src/Service/SearchIndex/IndexQueue/EnqueueService.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ public function enqueueByTag(Tag $tag): EnqueueService
6565
ElementType::ASSET->value,
6666
IndexName::ASSET->value,
6767
IndexQueueOperation::UPDATE->value,
68-
$this->timeService->getCurrentMillisecondTimestamp(),
69-
0,
68+
(string)$this->timeService->getCurrentMillisecondTimestamp(),
69+
'0',
7070
],
7171
'id',
7272
['ctype' => ElementType::ASSET->value, 'tagid' => $tag->getId()],
@@ -80,8 +80,8 @@ public function enqueueByTag(Tag $tag): EnqueueService
8080
[
8181
ElementType::DATA_OBJECT->value,
8282
IndexQueueOperation::UPDATE->value,
83-
$this->timeService->getCurrentMillisecondTimestamp(),
84-
0,
83+
(string)$this->timeService->getCurrentMillisecondTimestamp(),
84+
'0',
8585
],
8686
'id, className',
8787
['ctype' => ElementType::DATA_OBJECT->value, 'tagid' => $tag->getId()],
@@ -104,8 +104,8 @@ public function enqueueByClassDefinition(ClassDefinition $classDefinition): Enqu
104104
ElementType::DATA_OBJECT->value,
105105
$classDefinition->getName(),
106106
IndexQueueOperation::UPDATE->value,
107-
$this->timeService->getCurrentMillisecondTimestamp(),
108-
0,
107+
(string)$this->timeService->getCurrentMillisecondTimestamp(),
108+
'0',
109109
],
110110
'oo_id'
111111
);
@@ -125,8 +125,8 @@ public function enqueueDataObjectFolders(): EnqueueServiceInterface
125125
ElementType::DATA_OBJECT->value,
126126
IndexName::DATA_OBJECT_FOLDER->value,
127127
IndexQueueOperation::UPDATE->value,
128-
$this->timeService->getCurrentMillisecondTimestamp(),
129-
0,
128+
(string)$this->timeService->getCurrentMillisecondTimestamp(),
129+
'0',
130130
],
131131
)->where('type = "folder"');
132132
$this->indexQueueRepository->enqueueBySelectQuery($selectQuery);
@@ -151,8 +151,8 @@ public function enqueueAssets(): EnqueueService
151151
ElementType::ASSET->value,
152152
IndexName::ASSET->value,
153153
IndexQueueOperation::UPDATE->value,
154-
$this->timeService->getCurrentMillisecondTimestamp(),
155-
0,
154+
(string)$this->timeService->getCurrentMillisecondTimestamp(),
155+
'0',
156156
]
157157
);
158158
$this->indexQueueRepository->enqueueBySelectQuery($selectQuery);
@@ -177,8 +177,8 @@ public function enqueueDocuments(): EnqueueService
177177
ElementType::DOCUMENT->value,
178178
IndexName::DOCUMENT->value,
179179
IndexQueueOperation::UPDATE->value,
180-
$this->timeService->getCurrentMillisecondTimestamp(),
181-
0,
180+
(string)$this->timeService->getCurrentMillisecondTimestamp(),
181+
'0',
182182
]
183183
);
184184
$this->indexQueueRepository->enqueueBySelectQuery($selectQuery);

src/Service/SearchIndex/IndexService/ElementTypeAdapter/AssetTypeAdapter.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,18 @@ public function getRelatedItemsOnUpdateQuery(
8686
int $operationTime,
8787
bool $includeElement = false
8888
): ?QueryBuilder {
89+
90+
$selects = [
91+
(string)$element->getId(),
92+
"'" . ElementType::ASSET->value . "'",
93+
"'" . IndexName::ASSET->value . "'",
94+
"'$operation'",
95+
"'$operationTime'",
96+
'0',
97+
];
98+
8999
return $this->dbConnection->createQueryBuilder()
90-
->select([
91-
$element->getId(),
92-
"'" . ElementType::ASSET->value . "'",
93-
"'" . IndexName::ASSET->value . "'",
94-
"'$operation'",
95-
"'$operationTime'",
96-
'0',
97-
])
100+
->addSelect(...$selects)
98101
->from('DUAL') // just a dummy query to fit into the query builder interface
99102
->setMaxResults(1);
100103
}

src/Service/SearchIndex/IndexService/ElementTypeAdapter/DataObjectTypeAdapter.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,17 @@ public function getRelatedItemsOnUpdateQuery(
112112
if ($operation !== IndexQueueOperation::UPDATE->value) {
113113
return null;
114114
}
115+
$selects = [
116+
'id',
117+
"'" . ElementType::DATA_OBJECT->value . "'",
118+
'className',
119+
"'$operation'",
120+
"'$operationTime'",
121+
'0',
122+
];
115123

116124
$select = $this->dbConnection->createQueryBuilder()
117-
->select([
118-
'id',
119-
"'" . ElementType::DATA_OBJECT->value . "'",
120-
'className',
121-
"'$operation'",
122-
"'$operationTime'",
123-
'0',
124-
])
125+
->addSelect(...$selects)
125126
->from('objects')
126127
->where('classId = :classId')
127128
->andWhere('path LIKE :path')
@@ -164,7 +165,7 @@ private function getRelatedItemsQueryBuilder(
164165
}
165166

166167
$queryBuilder = $this->dbConnection->createQueryBuilder()
167-
->select($this->getSelectParametersByOperation($element, $operation, $operationTime))
168+
->addSelect(...$this->getSelectParametersByOperation($element, $operation, $operationTime))
168169
->setMaxResults(1);
169170

170171
if ($operation === IndexQueueOperation::DELETE->value) {
@@ -185,7 +186,7 @@ private function getSelectParametersByOperation(Concrete $element, string $opera
185186
}
186187

187188
return [
188-
$element->getId(),
189+
(string)$element->getId(),
189190
"'" . ElementType::DATA_OBJECT->value . "'",
190191
$classId,
191192
"'$operation'",

src/Service/SearchIndex/IndexService/ElementTypeAdapter/DocumentTypeAdapter.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,17 @@ public function getRelatedItemsOnUpdateQuery(
8686
int $operationTime,
8787
bool $includeElement = false
8888
): ?QueryBuilder {
89+
$selects = [
90+
(string)$element->getId(),
91+
"'" . ElementType::DOCUMENT->value . "'",
92+
"'" . IndexName::DOCUMENT->value . "'",
93+
"'$operation'",
94+
"'$operationTime'",
95+
'0',
96+
];
97+
8998
return $this->dbConnection->createQueryBuilder()
90-
->select([
91-
$element->getId(),
92-
"'" . ElementType::DOCUMENT->value . "'",
93-
"'" . IndexName::DOCUMENT->value . "'",
94-
"'$operation'",
95-
"'$operationTime'",
96-
'0',
97-
])
99+
->addSelect(...$selects)
98100
->from('DUAL') // just a dummy query to fit into the query builder interface
99101
->setMaxResults(1);
100102
}

tests/Functional/SearchIndex/IndexQueueTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ public function testIndexQueueRepository(): void
9797
ElementType::ASSET->value,
9898
IndexName::ASSET->value,
9999
IndexQueueOperation::UPDATE->value,
100-
1234,
101-
0,
100+
'1234',
101+
'0',
102102
])
103103
);
104104
$this->assertEquals(

tests/Support/Helper/Index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function setupPimcoreClass_Unittest($name = 'unittest', $filename = 'clas
192192
$panel->addChild($this->createDataChild('numeric', 'number'));
193193

194194
$passwordField = $this->createDataChild('password');
195-
$passwordField->setAlgorithm(ClassDefinition\Data\Password::HASH_FUNCTION_PASSWORD_HASH);
195+
196196
$panel->addChild($passwordField);
197197

198198
$panel->addChild($this->createDataChild('rgbaColor', 'rgbaColor', false, false));

0 commit comments

Comments
 (0)