Skip to content

Commit 2ec1204

Browse files
committed
Fix dropping search index
Error Cannot use object of type stdClass as array
1 parent 6af8698 commit 2ec1204

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/Doctrine/ODM/MongoDB/SchemaManager.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,9 @@ public function updateDocumentSearchIndexes(string $documentName): void
413413

414414
$definedNames = array_column($searchIndexes, 'name');
415415
try {
416-
$existingNames = array_column(iterator_to_array($collection->listSearchIndexes()), 'name');
416+
/* The typeMap option can be removed when bug is fixed in the minimum required version.
417+
* https://jira.mongodb.org/browse/PHPLIB-1548 */
418+
$existingNames = array_column(iterator_to_array($collection->listSearchIndexes(['typeMap' => ['root' => 'array']])), 'name');
417419
} catch (CommandException $e) {
418420
/* If $listSearchIndexes doesn't exist, only throw if search indexes have been defined.
419421
* If no search indexes are defined and the server doesn't support search indexes, there's
@@ -465,7 +467,9 @@ public function deleteDocumentSearchIndexes(string $documentName): void
465467
$collection = $this->dm->getDocumentCollection($class->name);
466468

467469
try {
468-
$searchIndexes = $collection->listSearchIndexes();
470+
/* The typeMap option can be removed when bug is fixed in the minimum required version.
471+
* https://jira.mongodb.org/browse/PHPLIB-1548 */
472+
$searchIndexes = $collection->listSearchIndexes(['typeMap' => ['root' => 'array']]);
469473
} catch (CommandException $e) {
470474
// If the server does not support search indexes, there are no indexes to remove in any case
471475
if ($this->isSearchIndexCommandException($e)) {

psalm-baseline.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@
184184
<code><![CDATA[array]]></code>
185185
</LessSpecificImplementedReturnType>
186186
</file>
187+
<file src="lib/Doctrine/ODM/MongoDB/SchemaManager.php">
188+
<InvalidArgument>
189+
<code><![CDATA[['typeMap' => ['root' => 'array']]]]></code>
190+
<code><![CDATA[['typeMap' => ['root' => 'array']]]]></code>
191+
</InvalidArgument>
192+
</file>
187193
<file src="lib/Doctrine/ODM/MongoDB/Tools/Console/Command/ClearCache/MetadataCommand.php">
188194
<UndefinedInterfaceMethod>
189195
<code><![CDATA[getDocumentManager]]></code>

0 commit comments

Comments
 (0)