@@ 234-245 (lines=12) @@ | ||
231 | $data = $this->pb->prepareInsertData($document); |
|
232 | ||
233 | // Set the initial version for each insert |
|
234 | if ($this->class->isVersioned) { |
|
235 | $versionMapping = $this->class->fieldMappings[$this->class->versionField]; |
|
236 | if ($versionMapping['type'] === 'int') { |
|
237 | $nextVersion = max(1, (int) $this->class->reflFields[$this->class->versionField]->getValue($document)); |
|
238 | $this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion); |
|
239 | } elseif ($versionMapping['type'] === 'date') { |
|
240 | $nextVersionDateTime = new \DateTime(); |
|
241 | $nextVersion = new \MongoDate($nextVersionDateTime->getTimestamp()); |
|
242 | $this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersionDateTime); |
|
243 | } |
|
244 | $data[$versionMapping['name']] = $nextVersion; |
|
245 | } |
|
246 | ||
247 | $inserts[$oid] = $data; |
|
248 | } |
|
@@ 289-300 (lines=12) @@ | ||
286 | $data = $this->pb->prepareUpsertData($document); |
|
287 | ||
288 | // Set the initial version for each upsert |
|
289 | if ($this->class->isVersioned) { |
|
290 | $versionMapping = $this->class->fieldMappings[$this->class->versionField]; |
|
291 | if ($versionMapping['type'] === 'int') { |
|
292 | $nextVersion = max(1, (int) $this->class->reflFields[$this->class->versionField]->getValue($document)); |
|
293 | $this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion); |
|
294 | } elseif ($versionMapping['type'] === 'date') { |
|
295 | $nextVersionDateTime = new \DateTime(); |
|
296 | $nextVersion = new \MongoDate($nextVersionDateTime->getTimestamp()); |
|
297 | $this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersionDateTime); |
|
298 | } |
|
299 | $data['$set'][$versionMapping['name']] = $nextVersion; |
|
300 | } |
|
301 | ||
302 | try { |
|
303 | $this->executeUpsert($data, $options); |