/** * 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 Zend_Cloud_DocumentService_Exception('Error on document update: ' . $e->getMessage(), $e->getCode(), $e); } return true; }
public function testDeleteAttributes() { $domainName = $this->_testDomainNamePrefix . '_testDeleteAttributes'; $this->_amazon->deleteDomain($domainName); $this->_amazon->createDomain($domainName); try { $itemName = $this->_testItemNamePrefix . '_testDeleteAttributes'; $attributeName1 = $this->_testAttributeNamePrefix . '_testDeleteAttributes1'; $attributeName2 = $this->_testAttributeNamePrefix . '_testDeleteAttributes2'; $attributeName3 = $this->_testAttributeNamePrefix . '_testDeleteAttributes3'; $attributeName4 = $this->_testAttributeNamePrefix . '_testDeleteAttributes4'; $attributeValue1 = 'value1'; $attributeValue2 = 'value2'; $attributeValue3 = 'value3'; $attributeValue4 = 'value4'; $attributes = array(new Zend_Service_Amazon_SimpleDb_Attribute($itemName, $attributeName1, $attributeValue1), new Zend_Service_Amazon_SimpleDb_Attribute($itemName, $attributeName2, $attributeValue2), new Zend_Service_Amazon_SimpleDb_Attribute($itemName, $attributeName3, $attributeValue3), new Zend_Service_Amazon_SimpleDb_Attribute($itemName, $attributeName4, $attributeValue4)); // Now that everything's set up, test it $this->_amazon->putAttributes($domainName, $itemName, $attributes); $this->_wait(); $results = $this->_amazon->getAttributes($domainName, $itemName); $this->assertEquals(4, count($results)); $this->assertTrue(array_key_exists($attributeName1, $results)); $this->assertTrue(array_key_exists($attributeName2, $results)); $this->assertTrue(array_key_exists($attributeName3, $results)); $this->assertTrue(array_key_exists($attributeName4, $results)); $this->assertEquals($attributeValue1, current($results[$attributeName1]->getValues())); $this->assertEquals($attributeValue2, current($results[$attributeName2]->getValues())); $this->assertEquals($attributeValue3, current($results[$attributeName3]->getValues())); $this->assertEquals($attributeValue4, current($results[$attributeName4]->getValues())); $this->_amazon->deleteAttributes($domainName, $itemName, array($attributes[0])); $this->_wait(); $results = $this->_amazon->getAttributes($domainName, $itemName); $this->assertEquals(3, count($results)); $this->assertTrue(array_key_exists($attributeName2, $results)); $this->assertTrue(array_key_exists($attributeName3, $results)); $this->assertTrue(array_key_exists($attributeName4, $results)); $this->assertEquals($attributeValue2, current($results[$attributeName2]->getValues())); $this->assertEquals($attributeValue3, current($results[$attributeName3]->getValues())); $this->assertEquals($attributeValue4, current($results[$attributeName4]->getValues())); $this->_amazon->deleteAttributes($domainName, $itemName, array($attributes[1], $attributes[2])); $this->_wait(); $results = $this->_amazon->getAttributes($domainName, $itemName); $this->assertEquals(1, count($results)); $this->assertTrue(array_key_exists($attributeName4, $results)); $this->assertEquals($attributeValue4, current($results[$attributeName4]->getValues())); $this->_amazon->deleteAttributes($domainName, $itemName, array($attributes[3])); $this->_wait(); $results = $this->_amazon->getAttributes($domainName, $itemName); $this->assertEquals(0, count($results)); $this->_amazon->deleteDomain($domainName); } catch (Exception $e) { $this->_amazon->deleteDomain($domainName); throw $e; } }