ZF-11114: Zend_Cloud_StorageService_Adapter_S3 method copyItem not implemented

Description

The code if copyItem metod does not work at all. If needed, I can submit the correct implementation - it should be very easy, only forward the call to $this->_s3->copyObject method.

copyObject method could also be used as a workaround for storeMetadata.

Comments

The issue here appears to be that {{Zend_Cloud_StorageService_Adapter_S3::copyItem}} does fetch+store operations instead of using the available method {{Zend_Service_Amazon_S3::copyObject}} to signal Amazon S3 to perform the copy. There is a TODO to this effect in the code:


        try {
            // TODO We *really* need to add support for object copying in the S3 adapter
            $item = $this->fetch($_getFullPath(sourcePath), $options);
            $this->storeItem($item, $destinationPath, $options);
        } catch (Zend_Service_Amazon_S3_Exception  $e) {
            throw new Zend_Cloud_StorageService_Exception('Error on copy: '.$e->getMessage(), $e->getCode(), $e);
        }

@[~matthew], [~zimuel]: Is this on the development radar for ZFv1's {{Zend_Cloud}}? Is it as simple as the OP suggests (just call {{$this->_s3->copyObject(...)}})?

Here is a patch implementing the change:



Index: library/Zend/Cloud/StorageService/Adapter/S3.php
===================================================================
--- library/Zend/Cloud/StorageService/Adapter/S3.php    (revision 24628)
+++ library/Zend/Cloud/StorageService/Adapter/S3.php    (working copy)
@@ -177,9 +177,14 @@
     public function copyItem($sourcePath, $destinationPath, $options = array())
     {
         try {
-            // TODO We *really* need to add support for object copying in the S3 adapter
-            $item = $this->fetch($_getFullPath(sourcePath), $options);
-            $this->storeItem($item, $destinationPath, $options);
+            $fullSourcePath = $this->_getFullPath($sourcePath, $options);
+            $fullDestPath   = $this->_getFullPath($destinationPath, $options);
+            return $this->_s3->copyObject(
+                $fullSourcePath,
+                $fullDestPath,
+                empty($options[self::METADATA]) ? null : $options[self::METADATA]
+            );
+
         } catch (Zend_Service_Amazon_S3_Exception  $e) {
             throw new Zend_Cloud_StorageService_Exception('Error on copy: '.$e->getMessage(), $e->getCode(), $e);
         }

Fixed in trunk (1.12.0): r24752 Fixed in release-1.11 (1.11.12): r24753