本文整理汇总了PHP中Doctrine\ODM\MongoDB\UnitOfWork::isScheduledForUpsert方法的典型用法代码示例。如果您正苦于以下问题:PHP UnitOfWork::isScheduledForUpsert方法的具体用法?PHP UnitOfWork::isScheduledForUpsert怎么用?PHP UnitOfWork::isScheduledForUpsert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ODM\MongoDB\UnitOfWork
的用法示例。
在下文中一共展示了UnitOfWork::isScheduledForUpsert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: executeInserts
/**
* Executes all queued document insertions and returns any generated post-insert
* identifiers that were created as a result of the insertions.
*
* If no inserts are queued, invoking this method is a NOOP.
*
* @param array $options Array of options to be used with batchInsert()
* @return 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();
$upserts = array();
foreach ($this->queuedInserts as $oid => $document) {
$upsert = $this->uow->isScheduledForUpsert($document);
if ($upsert) {
$data = $this->pb->prepareUpsertData($document);
} else {
$data = $this->pb->prepareInsertData($document);
}
// Set the initial version for each insert
if ($this->class->isVersioned) {
$versionMapping = $this->class->fieldMappings[$this->class->versionField];
if ($versionMapping['type'] === 'int') {
$currentVersion = $this->class->reflFields[$this->class->versionField]->getValue($document);
$data[$versionMapping['name']] = $currentVersion;
$this->class->reflFields[$this->class->versionField]->setValue($document, $currentVersion);
} elseif ($versionMapping['type'] === 'date') {
$nextVersion = new \DateTime();
$data[$versionMapping['name']] = new \MongoDate($nextVersion->getTimestamp());
$this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion);
}
}
if ($upsert) {
$upserts[$oid] = $data;
} else {
$inserts[$oid] = $data;
}
}
if ($inserts) {
$this->collection->batchInsert($inserts, $options);
foreach ($inserts as $oid => $data) {
$document = $this->queuedInserts[$oid];
$postInsertIds[] = array($this->class->getPHPIdentifierValue($data['_id']), $document);
}
}
if ($upserts) {
$upsertOptions = $options;
$upsertOptions['upsert'] = true;
foreach ($upserts as $oid => $data) {
$criteria = array('_id' => $data[$this->cmd . 'set']['_id']);
unset($data[$this->cmd . 'set']['_id']);
// stupid php
if (empty($data[$this->cmd . 'set'])) {
$data[$this->cmd . 'set'] = new \stdClass();
}
$this->collection->update($criteria, $data, $upsertOptions);
}
}
$this->queuedInserts = array();
return $postInsertIds;
}