Skip to content
Browse files

Apply some object calisthenics to GridFS::doInsert()

  • Loading branch information...
1 parent 06c4e22 commit 7fb075c0a4a899dc9facd00039839c73feb4d673 @jmikola jmikola committed Sep 26, 2012
Showing with 15 additions and 9 deletions.
  1. +15 −9 lib/Doctrine/MongoDB/GridFS.php
View
24 lib/Doctrine/MongoDB/GridFS.php
@@ -111,18 +111,24 @@ protected function doBatchInsert(array &$a, array $options = array())
/** @override */
protected function doInsert(array &$a, array $options = array())
{
- // If file exists and is dirty then lets persist the file and store the file path or the bytes
- if (isset($a['file'])) {
- $file = $a['file']; // instanceof GridFSFile
- unset($a['file']);
- if ($file->isDirty()) {
- $this->storeFile($file, $a, $options);
- } else {
- parent::doInsert($a, $options);
- }
+ // If there is no file, perform a basic insertion
+ if (!isset($a['file'])) {
+ parent::doInsert($a, $options);
+ return;
+ }
+
+ /* If the file is dirty (i.e. it must be persisted), delegate to the
+ * storeFile() method. Otherwise, perform a basic insertion.
+ */
+ $file = $a['file']; // instanceof GridFSFile
+ unset($a['file']);
+
+ if ($file->isDirty()) {
+ $this->storeFile($file, $a, $options);
} else {
parent::doInsert($a, $options);
}
+
$a['file'] = $file;
return $a;
}

0 comments on commit 7fb075c

Please sign in to comment.
Something went wrong with that request. Please try again.