Permalink
Browse files

Fix: Clean cmd Exception when using MongoDB Docs

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...
1 parent c437696 commit 0ea8017807e6b8e9a545b43d16454a1e50756613 @jmig jmig committed Oct 19, 2012
Showing with 10 additions and 6 deletions.
  1. +5 −3 Document/AuthCodeManager.php
  2. +5 −3 Document/TokenManager.php
@@ -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'];
}
}
@@ -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.