本文整理汇总了PHP中Doctrine\ODM\MongoDB\UnitOfWork::hasScheduledCollections方法的典型用法代码示例。如果您正苦于以下问题:PHP UnitOfWork::hasScheduledCollections方法的具体用法?PHP UnitOfWork::hasScheduledCollections怎么用?PHP UnitOfWork::hasScheduledCollections使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ODM\MongoDB\UnitOfWork
的用法示例。
在下文中一共展示了UnitOfWork::hasScheduledCollections方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Updates the already persisted document if it has any new changesets.
*
* @param object $document
* @param array $options Array of options to be used with update()
* @throws \Doctrine\ODM\MongoDB\LockException
*/
public function update($document, array $options = array())
{
$id = $this->uow->getDocumentIdentifier($document);
$update = $this->pb->prepareUpdateData($document);
if (!empty($update) || $this->uow->hasScheduledCollections($document)) {
$id = $this->class->getDatabaseIdentifierValue($id);
$query = array('_id' => $id);
// Include versioning logic to set the new version value in the database
// and to ensure the version has not changed since this document object instance
// was fetched from the database
if ($this->class->isVersioned) {
$versionMapping = $this->class->fieldMappings[$this->class->versionField];
$currentVersion = $this->class->reflFields[$this->class->versionField]->getValue($document);
if ($versionMapping['type'] === 'int') {
$nextVersion = $currentVersion + 1;
$update['$inc'][$versionMapping['name']] = 1;
$query[$versionMapping['name']] = $currentVersion;
$this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion);
} elseif ($versionMapping['type'] === 'date') {
$nextVersion = new \DateTime();
$update['$set'][$versionMapping['name']] = new \MongoDate($nextVersion->getTimestamp());
$query[$versionMapping['name']] = new \MongoDate($currentVersion->getTimestamp());
$this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion);
}
}
$atomicCollectionQuery = $this->getAtomicCollectionUpdateQuery($document);
if (!empty($atomicCollectionQuery)) {
$update = array_merge_recursive($update, $atomicCollectionQuery);
}
/* We got here because the document has one or more related
* PersistentCollections to be committed later; however, if the
* document is not versioned then there is nothing left to do.
*/
if (empty($update)) {
return;
}
// Include locking logic so that if the document object in memory is currently
// locked then it will remove it, otherwise it ensures the document is not locked.
if ($this->class->isLockable) {
$isLocked = $this->class->reflFields[$this->class->lockField]->getValue($document);
$lockMapping = $this->class->fieldMappings[$this->class->lockField];
if ($isLocked) {
$update['$unset'] = array($lockMapping['name'] => true);
} else {
$query[$lockMapping['name']] = array('$exists' => false);
}
}
unset($update['$set']['_id']);
$result = $this->collection->update($query, $update, $options);
if (($this->class->isVersioned || $this->class->isLockable) && !$result['n']) {
throw LockException::lockFailed($document);
}
}
}
示例2: cascadePostUpdate
/**
* Cascades the postUpdate and postPersist events to embedded documents.
*
* @param ClassMetadata $class
* @param object $document
*/
private function cascadePostUpdate(ClassMetadata $class, $document)
{
foreach ($class->getEmbeddedFieldsMappings() as $mapping) {
$value = $class->reflFields[$mapping['fieldName']]->getValue($document);
if ($value === null) {
continue;
}
$values = $mapping['type'] === ClassMetadata::ONE ? array($value) : $value;
foreach ($values as $entry) {
if (empty($this->uow->getDocumentChangeSet($entry)) && !$this->uow->hasScheduledCollections($entry)) {
continue;
}
$entryClass = $this->dm->getClassMetadata(get_class($entry));
$event = $this->uow->isScheduledForInsert($entry) ? Events::postPersist : Events::postUpdate;
$entryClass->invokeLifecycleCallbacks($event, $entry, array(new LifecycleEventArgs($entry, $this->dm)));
$this->evm->dispatchEvent($event, new LifecycleEventArgs($entry, $this->dm));
$this->cascadePostUpdate($entryClass, $entry);
}
}
}