コード例 #1
0
ファイル: WindowsAzure.php プロジェクト: robertodormepoco/zf2
 /**
  * Update document.
  *
  * The new document is merged the existing document.
  *
  * @param  string $collectionName
  * @param  mixed|\Zend\Cloud\DocumentService\Document $documentId Document identifier or document containing updates
  * @param  null|array|\Zend\Cloud\DocumentService\Document Fields to update (or new fields))
  * @param  array $options
  * @return boolean
  */
 public function updateDocument($collectionName, $documentId, $fieldset = null, $options = null)
 {
     if (null === $fieldset && $documentId instanceof \Zend\Cloud\DocumentService\Document) {
         $fieldset = $documentId->getFields();
         $documentId = $documentId->getId();
     } elseif ($fieldset instanceof \Zend\Cloud\DocumentService\Document) {
         if ($documentId == null) {
             $documentId = $fieldset->getId();
         }
         $fieldset = $fieldset->getFields();
     }
     $this->_validateCompositeKey($documentId, $collectionName);
     $this->_validateFields($fieldset);
     try {
         $entity = new DynamicTableEntity($documentId[0], $documentId[1]);
         // Ensure timestamp is set correctly
         if (isset($fieldset[self::TIMESTAMP_KEY])) {
             $entity->setTimestamp($fieldset[self::TIMESTAMP_KEY]);
             unset($fieldset[self::TIMESTAMP_KEY]);
         }
         $entity->setAzureValues($fieldset, true);
         if (isset($options[self::VERIFY_ETAG])) {
             $entity->setEtag($options[self::VERIFY_ETAG]);
         }
         $this->_storageClient->mergeEntity($collectionName, $entity, isset($options[self::VERIFY_ETAG]));
     } catch (WindowsAzureException\ExceptionInterface $e) {
         throw new Exception\RuntimeException('Error on document update: ' . $e->getMessage(), $e->getCode(), $e);
     }
 }
コード例 #2
0
ファイル: SimpleDb.php プロジェクト: brikou/zend_cloud
 /**
  * Update document. The new document replaces the existing document.
  *
  * Option 'merge' specifies to add all attributes (if true) or
  * specific attributes ("attr" => true) instead of replacing them.
  * By default, attributes are replaced.
  *
  * @param  string $collectionName
  * @param  mixed|\Zend\Cloud\DocumentService\Document $documentId Document ID, adapter-dependent
  * @param  array|\Zend\Cloud\DocumentService\Document $fieldset Set of fields to update
  * @param  array $options
  * @return boolean
  */
 public function updateDocument($collectionName, $documentId, $fieldset = null, $options = null)
 {
     if (null === $fieldset && $documentId instanceof \Zend\Cloud\DocumentService\Document) {
         $fieldset = $documentId->getFields();
         if (empty($documentId)) {
             $documentId = $documentId->getId();
         }
     } elseif ($fieldset instanceof \Zend\Cloud\DocumentService\Document) {
         if (empty($documentId)) {
             $documentId = $fieldset->getId();
         }
         $fieldset = $fieldset->getFields();
     }
     $replace = array();
     if (empty($options[self::MERGE_OPTION])) {
         // no merge option - we replace all
         foreach ($fieldset as $key => $value) {
             $replace[$key] = true;
         }
     } elseif (is_array($options[self::MERGE_OPTION])) {
         foreach ($fieldset as $key => $value) {
             if (empty($options[self::MERGE_OPTION][$key])) {
                 // if there's merge key, we add it, otherwise we replace it
                 $replace[$key] = true;
             }
         }
     }
     // otherwise $replace is empty - all is merged
     try {
         $this->_simpleDb->putAttributes($collectionName, $documentId, $this->_makeAttributes($documentId, $fieldset), $replace);
     } catch (\Zend\Service\Amazon\Exception $e) {
         throw new Exception\RunTimeException('Error on document update: ' . $e->getMessage(), $e->getCode(), $e);
     }
     return true;
 }