Example #1
0
 /**
  * Replace document.
  *
  * The new document replaces the existing document.
  *
  * @param  \ZendCloud\DocumentService\Document $document
  * @param  array $options
  * @return boolean
  */
 public function replaceDocument($collectionName, $document, $options = null)
 {
     if (is_array($document)) {
         $document = $this->_getDocumentFromArray($document, $collectionName);
     }
     if (!$document instanceof \ZendCloud\DocumentService\Document) {
         throw new Exception\InvalidArgumentException('Invalid document supplied');
     }
     $key = $this->_validateDocumentId($document->getId(), $collectionName);
     $this->_validateFields($document);
     try {
         $entity = new DynamicTableEntity($key[0], $key[1]);
         $entity->setAzureValues($document->getFields(), true);
         if (isset($options[self::VERIFY_ETAG])) {
             $entity->setEtag($options[self::VERIFY_ETAG]);
         }
         $this->_storageClient->updateEntity($collectionName, $entity, isset($options[self::VERIFY_ETAG]));
     } catch (WindowsAzureException\ExceptionInterface $e) {
         throw new Exception\RuntimeException('Error on document replace: ' . $e->getMessage(), $e->getCode(), $e);
     }
 }