Skip to content
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Yii Framework 2 mongodb extension Change Log
3.0.4 under development
-----------------------

- no changes in this release.
- Bug #388: Fix `MongoDB\Driver\Cursor::getId() expects exactly 0 arguments, 1 given` (vanyabrovary)


3.0.3 May 06, 2025
Expand Down
2 changes: 1 addition & 1 deletion src/BatchQueryResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected function fetchData()
if ($this->_iterator === null) {
$this->query->addOptions(['batchSize' => $this->batchSize]);
$cursor = $this->query->buildCursor($this->db);
$token = 'fetch cursor id = ' . $cursor->getId(true);
$token = 'fetch cursor id = ' . $cursor->getId();
Yii::info($token, __METHOD__);
Comment on lines +132 to 133
Copy link

Copilot AI Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the invalid argument from the getId() call to fix the bug related to incorrect method usage.

Suggested change
$token = 'fetch cursor id = ' . $cursor->getId();
Yii::info($token, __METHOD__);
if (method_exists($cursor, 'getId')) {
$token = 'fetch cursor id = ' . $cursor->getId();
Yii::info($token, __METHOD__);
} else {
Yii::warning('Cursor does not support getId()', __METHOD__);
}

Copilot uses AI. Check for mistakes.


if ($cursor instanceof \Iterator) {
Expand Down
2 changes: 1 addition & 1 deletion src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function buildCursor($db = null)
*/
protected function fetchRows($cursor, $all = true, $indexBy = null)
{
$token = 'fetch cursor id = ' . $cursor->getId(true);
$token = 'fetch cursor id = ' . $cursor->getId();
Copy link

Copilot AI Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated getId() by removing the extraneous argument to prevent runtime exceptions in logging.

Suggested change
$token = 'fetch cursor id = ' . $cursor->getId();
$token = 'fetch cursor hash = ' . spl_object_hash($cursor);

Copilot uses AI. Check for mistakes.

Yii::info($token, __METHOD__);
try {
Yii::beginProfile($token, __METHOD__);
Expand Down
2 changes: 1 addition & 1 deletion src/file/Cursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function toArray()
*/
public function getId()
{
return $this->getInnerIterator()->getId(true);
return $this->getInnerIterator()->getId();
Copy link

Copilot AI Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the unsupported argument from getId(), which now aligns with the MongoDB driver's expected method signature.

Suggested change
return $this->getInnerIterator()->getId();
$innerIterator = $this->getInnerIterator();
if ($innerIterator instanceof \MongoDB\Driver\Cursor) {
return $innerIterator->getId();
}
throw new \RuntimeException('Inner iterator is not an instance of \MongoDB\Driver\Cursor.');

Copilot uses AI. Check for mistakes.

}

/**
Expand Down