From 8ac8b3afe00c74856fe0c87539e97b332c60c2bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Mon, 14 Oct 2024 13:22:04 +0200 Subject: [PATCH] Fix dropping search index (#2689) Error "Cannot use object of type stdClass as array" --- lib/Doctrine/ODM/MongoDB/SchemaManager.php | 8 ++++++-- psalm-baseline.xml | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ODM/MongoDB/SchemaManager.php b/lib/Doctrine/ODM/MongoDB/SchemaManager.php index b142f1902..160be2328 100644 --- a/lib/Doctrine/ODM/MongoDB/SchemaManager.php +++ b/lib/Doctrine/ODM/MongoDB/SchemaManager.php @@ -413,7 +413,9 @@ public function updateDocumentSearchIndexes(string $documentName): void $definedNames = array_column($searchIndexes, 'name'); try { - $existingNames = array_column(iterator_to_array($collection->listSearchIndexes()), 'name'); + /* The typeMap option can be removed when bug is fixed in the minimum required version. + * https://jira.mongodb.org/browse/PHPLIB-1548 */ + $existingNames = array_column(iterator_to_array($collection->listSearchIndexes(['typeMap' => ['root' => 'array']])), 'name'); } catch (CommandException $e) { /* If $listSearchIndexes doesn't exist, only throw if search indexes have been defined. * 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 $collection = $this->dm->getDocumentCollection($class->name); try { - $searchIndexes = $collection->listSearchIndexes(); + /* The typeMap option can be removed when bug is fixed in the minimum required version. + * https://jira.mongodb.org/browse/PHPLIB-1548 */ + $searchIndexes = $collection->listSearchIndexes(['typeMap' => ['root' => 'array']]); } catch (CommandException $e) { // If the server does not support search indexes, there are no indexes to remove in any case if ($this->isSearchIndexCommandException($e)) { diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 110172f14..221a7a95f 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -184,6 +184,12 @@ + + + ['root' => 'array']]]]> + ['root' => 'array']]]]> + +