Doctrine\ODM\MongoDB\Persisters\DocumentPersister::executeInserts PHP Метод

executeInserts() публичный Метод

If no inserts are queued, invoking this method is a NOOP.
public executeInserts ( array $options = [] ) : array
$options array Array of options to be used with batchInsert()
Результат array An array of any generated post-insert IDs. This will be an empty array if the document class does not use the IDENTITY generation strategy.
    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;
    }