@@ 225-236 (lines=12) @@ | ||
222 | $data = $this->pb->prepareInsertData($document); |
|
223 | ||
224 | // Set the initial version for each insert |
|
225 | if ($this->class->isVersioned) { |
|
226 | $versionMapping = $this->class->fieldMappings[$this->class->versionField]; |
|
227 | if ($versionMapping['type'] === 'int') { |
|
228 | $nextVersion = max(1, (int) $this->class->reflFields[$this->class->versionField]->getValue($document)); |
|
229 | $this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion); |
|
230 | } elseif ($versionMapping['type'] === 'date') { |
|
231 | $nextVersionDateTime = new \DateTime(); |
|
232 | $nextVersion = new \MongoDate($nextVersionDateTime->getTimestamp()); |
|
233 | $this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersionDateTime); |
|
234 | } |
|
235 | $data[$versionMapping['name']] = $nextVersion; |
|
236 | } |
|
237 | ||
238 | $inserts[$oid] = $data; |
|
239 | } |
|
@@ 280-291 (lines=12) @@ | ||
277 | $data = $this->pb->prepareUpsertData($document); |
|
278 | ||
279 | // Set the initial version for each upsert |
|
280 | if ($this->class->isVersioned) { |
|
281 | $versionMapping = $this->class->fieldMappings[$this->class->versionField]; |
|
282 | if ($versionMapping['type'] === 'int') { |
|
283 | $nextVersion = max(1, (int) $this->class->reflFields[$this->class->versionField]->getValue($document)); |
|
284 | $this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion); |
|
285 | } elseif ($versionMapping['type'] === 'date') { |
|
286 | $nextVersionDateTime = new \DateTime(); |
|
287 | $nextVersion = new \MongoDate($nextVersionDateTime->getTimestamp()); |
|
288 | $this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersionDateTime); |
|
289 | } |
|
290 | $data['$set'][$versionMapping['name']] = $nextVersion; |
|
291 | } |
|
292 | ||
293 | try { |
|
294 | $this->executeUpsert($data, $options); |