Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add check in doUpdate() to make sure the document containing the file is returned #61

Merged
merged 1 commit into from

3 participants

@pgodel

Added check in doUpdate() to make sure the document containing the file is returned when updating an existing document with a new file.

I had this rare issue when connecting to a replicaSet. Issue appears to be fixed in PHP mongo driver already but a check here would not hurt.

@pgodel pgodel Added check in doUpdate() to make sure the document containing the fi…
…le is returned when updating an existing document with a new file.
0cc2a9a
@jmikola
Owner

I don't understand why doUpdate() is using findAndRemove() at all. The MongoGridFS docs have an example of updating a file, but doUpdate() has this comment:

It is impossible to update a file on the grid so we have to remove it and persist a new file with the same data

Is this because it's not possible to update a file's chunk data without also destroying the metadata? So we use findAndRemove() to fetch the metadata?

I imagine the PECL driver wouldn't error out if you attempted to update something that didn't exist, so perhaps we should NOP if we don't find an existing file.

@jwage jwage merged commit de0c453 into doctrine:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 10, 2012
  1. @pgodel

    Added check in doUpdate() to make sure the document containing the fi…

    pgodel authored
    …le is returned when updating an existing document with a new file.
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 1 deletion.
  1. +4 −1 lib/Doctrine/MongoDB/GridFS.php
View
5 lib/Doctrine/MongoDB/GridFS.php
@@ -70,7 +70,10 @@ protected function doUpdate($query, array $newObj, array $options = array())
// First do a find and remove query to remove the file metadata and chunks so
// we can restore the file below
- $document = $this->findAndRemove($query, $options);
+ if (null === $document = $this->findAndRemove($query, $options)) {
+ throw new \Exception("Could not find original document containing file");
+ }
+
unset(
$document['filename'],
$document['length'],
Something went wrong with that request. Please try again.