Example #1
0
 /**
  * Update document.
  *
  * The new document is merged the existing document.
  *
  * @param  string $collectionName
  * @param  mixed|\ZendCloud\DocumentService\Document $documentId Document identifier or document containing updates
  * @param  null|array|\ZendCloud\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 \ZendCloud\DocumentService\Document) {
         $fieldset = $documentId->getFields();
         $documentId = $documentId->getId();
     } elseif ($fieldset instanceof \ZendCloud\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);
     }
 }