Permalink
Browse files

Move GridFS logic out of Collection class (fixes #62)

  • Loading branch information...
1 parent 9ac0ba4 commit 06c4e22505635ee5daa9222565a17018a828f751 @jmikola jmikola committed Sep 15, 2012
Showing with 13 additions and 10 deletions.
  1. +1 −10 lib/Doctrine/MongoDB/Collection.php
  2. +12 −0 lib/Doctrine/MongoDB/GridFS.php
@@ -286,18 +286,9 @@ protected function doFindAndRemove(array $query, array $options = array())
$command['remove'] = true;
$command = array_merge($command, $options);
- $document = null;
-
$result = $this->database->command($command);
- if (isset($result['value'])) {
- $document = $result['value'];
- if ($this->getMongoCollection() instanceof \MongoGridFS) {
- // Remove the file data from the chunks collection
- $this->getMongoCollection()->chunks->remove(array('files_id' => $document['_id']), $options);
- }
- }
- return $document;
+ return isset($result['value']) ? $result['value'] : null;
}
public function findAndUpdate(array $query, array $newObj, array $options = array())
@@ -159,4 +159,16 @@ public function storeFile($file, array &$document, array $options = array())
$file->setMongoGridFSFile(new \MongoGridFSFile($this->getMongoCollection(), $document));
return $file;
}
+
+ protected function doFindAndRemove(array $query, array $options = array())
+ {
+ $document = parent::doFindAndRemove($query, $options);
+
+ if (isset($document)) {
+ // Remove the file data from the chunks collection
+ $this->getMongoCollection()->chunks->remove(array('files_id' => $document['_id']), $options);
+ }
+
+ return $document;
+ }
}

0 comments on commit 06c4e22

Please sign in to comment.