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