Browse Source

WindowsAzure functional updates

- Updated Storage object to add method for returning HTTP client
  (getHttpChannelClient()) (makes debugging easier)
- Updated Table to use timestamp of entity, if provided
- Updated TableEntity to allow better timestamp handling

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22946 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 15 years ago
parent
commit
360f96e678

+ 10 - 0
library/Zend/Service/WindowsAzure/Storage.php

@@ -238,6 +238,16 @@ class Zend_Service_WindowsAzure_Storage
 	{
 		$this->_httpClientChannel->setAdapter($adapterInstance);
 	}
+
+    /**
+     * Retrieve HTTP client channel
+     * 
+     * @return Zend_Http_Client_Adapter_Interface
+     */
+    public function getHttpClientChannel()
+    {
+        return $this->_httpClientChannel;
+    }
 	
 	/**
 	 * Set retry policy to use when making requests

+ 12 - 3
library/Zend/Service/WindowsAzure/Storage/Table.php

@@ -655,6 +655,9 @@ class Zend_Service_WindowsAzure_Storage_Table
 		} else {
 			$mergeEntity = $entity;
 		}
+
+        // Ensure entity timestamp matches updated timestamp 
+        $entity->setTimestamp($this->isoDate());
 		
 	    return $this->_changeEntity(Zend_Http_Client::MERGE, $tableName, $mergeEntity, $verifyEtag);
 	}
@@ -720,8 +723,14 @@ class Zend_Service_WindowsAzure_Storage_Table
                           </content>
                         </entry>';
 		
+        // Attempt to get timestamp from entity
+        $timestamp = $entity->getTimestamp();
+        if ($timestamp == Zend_Service_WindowsAzure_Storage_TableEntity::DEFAULT_TIMESTAMP) {
+            $timestamp = $this->isoDate();
+        }
+
         $requestBody = $this->_fillTemplate($requestBody, array(
-        	'Updated'    => $this->isoDate(),
+        	'Updated'    => $timestamp,
             'Properties' => $this->_generateAzureRepresentation($entity)
         ));
 
@@ -737,10 +746,10 @@ class Zend_Service_WindowsAzure_Storage_Table
 		// Perform request
 		$response = null;
 	    if ($this->isInBatch()) {
-		    $this->getCurrentBatch()->enlistOperation($tableName . '(PartitionKey=\'' . $entity->getPartitionKey() . '\', RowKey=\'' . $entity->getRowKey() . '\')', '', $httpVerb, $headers, true, $requestBody);
+		    $this->getCurrentBatch()->enlistOperation($tableName . '(PartitionKey=\'' . $entity->getPartitionKey() . '\',RowKey=\'' . $entity->getRowKey() . '\')', '', $httpVerb, $headers, true, $requestBody);
 		    return null;
 		} else {
-		    $response = $this->_performRequest($tableName . '(PartitionKey=\'' . $entity->getPartitionKey() . '\', RowKey=\'' . $entity->getRowKey() . '\')', '', $httpVerb, $headers, true, $requestBody);
+		    $response = $this->_performRequest($tableName . '(PartitionKey=\'' . $entity->getPartitionKey() . '\',RowKey=\'' . $entity->getRowKey() . '\')', '', $httpVerb, $headers, true, $requestBody);
 		}
 		if ($response->isSuccessful()) {
 		    // Update properties

+ 6 - 1
library/Zend/Service/WindowsAzure/Storage/TableEntity.php

@@ -35,6 +35,8 @@ require_once 'Zend/Service/WindowsAzure/Exception.php';
  */
 class Zend_Service_WindowsAzure_Storage_TableEntity
 {
+    const DEFAULT_TIMESTAMP = '1900-01-01T00:00:00';
+
     /**
      * Partition key
      * 
@@ -54,7 +56,7 @@ class Zend_Service_WindowsAzure_Storage_TableEntity
      * 
      * @var string
      */
-    protected $_timestamp = '1900-01-01T00:00:00';
+    protected $_timestamp;
     
     /**
      * Etag
@@ -127,6 +129,9 @@ class Zend_Service_WindowsAzure_Storage_TableEntity
      */
     public function getTimestamp()
     {
+        if (null === $this->_timestamp) {
+            $this->setTimestamp(self::DEFAULT_TIMESTAMP);
+        }
         return $this->_timestamp;
     }