public function executeInserts(array $options = array())
{
if ( ! $this->queuedInserts) {
return;
}
$postInsertIds = array();
$inserts = array();
foreach ($this->queuedInserts as $oid => $document) {
$data = $this->dp->prepareInsertData($document);
if ( ! $data) {
continue;
}
if ($this->class->isVersioned) {
$versionMapping = $this->class->fieldMappings[$this->class->versionField];
if ($versionMapping['type'] === 'int') {
$currentVersion = $this->class->getFieldValue($document, $this->class->versionField);
$data[$versionMapping['name']] = $currentVersion;
$this->class->setFieldValue($document, $this->class->versionField, $currentVersion);
} elseif ($versionMapping['type'] === 'date') {
$nextVersion = new \DateTime();
$data[$versionMapping['name']] = new \MongoDate($nextVersion->getTimestamp());
$this->class->setFieldValue($document, $this->class->versionField, $nextVersion);
}
}
$inserts[$oid] = $data;
}
if (empty($inserts)) {
return;
}
$this->collection->batchInsert($inserts, $options);
foreach ($inserts as $oid => $data) {
$document = $this->queuedInserts[$oid];
$postInsertIds[] = array($data['_id'], $document);
}
$this->queuedInserts = array();
return $postInsertIds;
}