Skip to content

Commit

Permalink
Fix: Clean cmd Exception when using MongoDB Docs
Browse files Browse the repository at this point in the history
findAndRemove() find the first element and return it
This leads to an exception when trying to count it in L54 of the CleanCommand.php

Add: Return the correct number of deleted rows

Thanks to @jmikola,
We're using the Query Option "safe" to get the number of rows modified by the query.

When executing the query, it now returns the following Array:
Array
(
    [n] => 0
    [connectionId] => 113959
    [err] =>
    [ok] => 1
)

Where n is the number of deleted rows.
  • Loading branch information
jmig committed Oct 23, 2012
1 parent c437696 commit 0ea8017
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions Document/AuthCodeManager.php
Expand Up @@ -78,12 +78,14 @@ public function deleteAuthCode(AuthCodeInterface $authCode)
*/
public function deleteExpired()
{
return $this
$result = $this
->repository
->createQueryBuilder()
->findAndRemove()
->remove()
->field('expiresAt')->lt(time())
->getQuery()
->getQuery(array('safe' => true))
->execute();

return $result['n'];
}
}
8 changes: 5 additions & 3 deletions Document/TokenManager.php
Expand Up @@ -79,12 +79,14 @@ public function deleteToken(TokenInterface $token)
*/
public function deleteExpired()
{
return $this
$result = $this
->repository
->createQueryBuilder()
->findAndRemove()
->remove()
->field('expiresAt')->lt(time())
->getQuery()
->getQuery(array('safe' => true))
->execute();

return $result['n'];
}
}

0 comments on commit 0ea8017

Please sign in to comment.