當前位置: 首頁>>代碼示例>>PHP>>正文


PHP UnitOfWork::isScheduledForUpsert方法代碼示例

本文整理匯總了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;
 }
開發者ID:3116246,項目名稱:haolinju,代碼行數:67,代碼來源:DocumentPersister.php


注:本文中的Doctrine\ODM\MongoDB\UnitOfWork::isScheduledForUpsert方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。