Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "Cannot use object of type stdClass as array" in search index drop #2689

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/Doctrine/ODM/MongoDB/SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down
6 changes: 6 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@
<code><![CDATA[array]]></code>
</LessSpecificImplementedReturnType>
</file>
<file src="lib/Doctrine/ODM/MongoDB/SchemaManager.php">
<InvalidArgument>
<code><![CDATA[['typeMap' => ['root' => 'array']]]]></code>
<code><![CDATA[['typeMap' => ['root' => 'array']]]]></code>
</InvalidArgument>
</file>
<file src="lib/Doctrine/ODM/MongoDB/Tools/Console/Command/ClearCache/MetadataCommand.php">
<UndefinedInterfaceMethod>
<code><![CDATA[getDocumentManager]]></code>
Expand Down