Skip to content
This repository
Browse code

Apply some object calisthenics to GridFS::doInsert()

  • Loading branch information...
commit 7fb075c0a4a899dc9facd00039839c73feb4d673 1 parent 06c4e22
Jeremy Mikola jmikola authored

Showing 1 changed file with 15 additions and 9 deletions. Show diff stats Hide diff stats

  1. +15 9 lib/Doctrine/MongoDB/GridFS.php
24 lib/Doctrine/MongoDB/GridFS.php
@@ -111,18 +111,24 @@ protected function doBatchInsert(array &$a, array $options = array())
111 111 /** @override */
112 112 protected function doInsert(array &$a, array $options = array())
113 113 {
114   - // If file exists and is dirty then lets persist the file and store the file path or the bytes
115   - if (isset($a['file'])) {
116   - $file = $a['file']; // instanceof GridFSFile
117   - unset($a['file']);
118   - if ($file->isDirty()) {
119   - $this->storeFile($file, $a, $options);
120   - } else {
121   - parent::doInsert($a, $options);
122   - }
  114 + // If there is no file, perform a basic insertion
  115 + if (!isset($a['file'])) {
  116 + parent::doInsert($a, $options);
  117 + return;
  118 + }
  119 +
  120 + /* If the file is dirty (i.e. it must be persisted), delegate to the
  121 + * storeFile() method. Otherwise, perform a basic insertion.
  122 + */
  123 + $file = $a['file']; // instanceof GridFSFile
  124 + unset($a['file']);
  125 +
  126 + if ($file->isDirty()) {
  127 + $this->storeFile($file, $a, $options);
123 128 } else {
124 129 parent::doInsert($a, $options);
125 130 }
  131 +
126 132 $a['file'] = $file;
127 133 return $a;
128 134 }

0 comments on commit 7fb075c

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