equal
deleted
inserted
replaced
11 * to license@zend.com so we can send you a copy immediately. |
11 * to license@zend.com so we can send you a copy immediately. |
12 * |
12 * |
13 * @category Zend |
13 * @category Zend |
14 * @package Zend_Cloud |
14 * @package Zend_Cloud |
15 * @subpackage StorageService |
15 * @subpackage StorageService |
16 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
16 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
17 * @license http://framework.zend.com/license/new-bsd New BSD License |
17 * @license http://framework.zend.com/license/new-bsd New BSD License |
18 */ |
18 */ |
19 |
19 |
20 require_once 'Zend/Cloud/StorageService/Adapter.php'; |
20 require_once 'Zend/Cloud/StorageService/Adapter.php'; |
21 require_once 'Zend/Cloud/StorageService/Exception.php'; |
21 require_once 'Zend/Cloud/StorageService/Exception.php'; |
25 * Adapter for Nirvanix cloud storage |
25 * Adapter for Nirvanix cloud storage |
26 * |
26 * |
27 * @category Zend |
27 * @category Zend |
28 * @package Zend_Cloud |
28 * @package Zend_Cloud |
29 * @subpackage StorageService |
29 * @subpackage StorageService |
30 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
30 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
31 * @license http://framework.zend.com/license/new-bsd New BSD License |
31 * @license http://framework.zend.com/license/new-bsd New BSD License |
32 */ |
32 */ |
33 class Zend_Cloud_StorageService_Adapter_Nirvanix |
33 class Zend_Cloud_StorageService_Adapter_Nirvanix |
34 implements Zend_Cloud_StorageService_Adapter |
34 implements Zend_Cloud_StorageService_Adapter |
35 { |
35 { |
36 const USERNAME = 'auth_username'; |
36 const USERNAME = 'auth_username'; |
37 const PASSWORD = 'auth_password'; |
37 const PASSWORD = 'auth_password'; |
38 const APP_KEY = 'auth_accesskey'; |
38 const APP_KEY = 'auth_accesskey'; |
48 protected $_remoteDirectory; |
48 protected $_remoteDirectory; |
49 private $maxPageSize = 500; |
49 private $maxPageSize = 500; |
50 |
50 |
51 /** |
51 /** |
52 * Constructor |
52 * Constructor |
53 * |
53 * |
54 * @param array|Zend_Config $options |
54 * @param array|Zend_Config $options |
55 * @return void |
55 * @return void |
56 */ |
56 */ |
57 function __construct($options = array()) |
57 function __construct($options = array()) |
58 { |
58 { |
59 if ($options instanceof Zend_Config) { |
59 if ($options instanceof Zend_Config) { |
60 $options = $options->toArray(); |
60 $options = $options->toArray(); |
61 } |
61 } |
62 |
62 |
72 $nirvanix_options = array(); |
72 $nirvanix_options = array(); |
73 if (isset($options[self::HTTP_ADAPTER])) { |
73 if (isset($options[self::HTTP_ADAPTER])) { |
74 $httpc = new Zend_Http_Client(); |
74 $httpc = new Zend_Http_Client(); |
75 $httpc->setAdapter($options[self::HTTP_ADAPTER]); |
75 $httpc->setAdapter($options[self::HTTP_ADAPTER]); |
76 $nirvanix_options['httpClient'] = $httpc; |
76 $nirvanix_options['httpClient'] = $httpc; |
77 } |
77 } |
78 try { |
78 try { |
79 $this->_nirvanix = new Zend_Service_Nirvanix($auth, $nirvanix_options); |
79 $this->_nirvanix = new Zend_Service_Nirvanix($auth, $nirvanix_options); |
80 $this->_remoteDirectory = $options[self::REMOTE_DIRECTORY]; |
80 $this->_remoteDirectory = $options[self::REMOTE_DIRECTORY]; |
81 $this->_imfNs = $this->_nirvanix->getService('IMFS'); |
81 $this->_imfNs = $this->_nirvanix->getService('IMFS'); |
82 $this->_metadataNs = $this->_nirvanix->getService('Metadata'); |
82 $this->_metadataNs = $this->_nirvanix->getService('Metadata'); |
83 } catch (Zend_Service_Nirvanix_Exception $e) { |
83 } catch (Zend_Service_Nirvanix_Exception $e) { |
84 throw new Zend_Cloud_StorageService_Exception('Error on create: '.$e->getMessage(), $e->getCode(), $e); |
84 throw new Zend_Cloud_StorageService_Exception('Error on create: '.$e->getMessage(), $e->getCode(), $e); |
85 } |
85 } |
86 } |
86 } |
87 |
87 |
88 /** |
88 /** |
195 * @param string $path |
195 * @param string $path |
196 * @param string $name |
196 * @param string $name |
197 * @param array $options |
197 * @param array $options |
198 * @return void |
198 * @return void |
199 */ |
199 */ |
200 public function renameItem($path, $name, $options = null) |
200 public function renameItem($path, $name, $options = null) |
201 { |
201 { |
202 require_once 'Zend/Cloud/OperationNotAvailableException.php'; |
202 require_once 'Zend/Cloud/OperationNotAvailableException.php'; |
203 throw new Zend_Cloud_OperationNotAvailableException('Renaming not implemented'); |
203 throw new Zend_Cloud_OperationNotAvailableException('Renaming not implemented'); |
204 } |
204 } |
205 |
205 |
217 try { |
217 try { |
218 $metadataNode = $this->_metadataNs->getMetadata(array('path' => $path)); |
218 $metadataNode = $this->_metadataNs->getMetadata(array('path' => $path)); |
219 } catch (Zend_Service_Nirvanix_Exception $e) { |
219 } catch (Zend_Service_Nirvanix_Exception $e) { |
220 throw new Zend_Cloud_StorageService_Exception('Error on fetching metadata: '.$e->getMessage(), $e->getCode(), $e); |
220 throw new Zend_Cloud_StorageService_Exception('Error on fetching metadata: '.$e->getMessage(), $e->getCode(), $e); |
221 } |
221 } |
222 |
222 |
223 $metadata = array(); |
223 $metadata = array(); |
224 $length = count($metadataNode->Metadata); |
224 $length = count($metadataNode->Metadata); |
225 |
225 |
226 // Need to special case this as Nirvanix returns an array if there is |
226 // Need to special case this as Nirvanix returns an array if there is |
227 // more than one, but doesn't return an array if there is only one. |
227 // more than one, but doesn't return an array if there is only one. |
242 /** |
242 /** |
243 * Store a key/value array of metadata at the given path. |
243 * Store a key/value array of metadata at the given path. |
244 * WARNING: This operation overwrites any metadata that is located at |
244 * WARNING: This operation overwrites any metadata that is located at |
245 * $destinationPath. |
245 * $destinationPath. |
246 * |
246 * |
247 * @param array $metadata - An associative array specifying the key/value pairs for the metadata. |
247 * @param string $destinationPath |
248 * @param $destinationPath |
248 * @param array $metadata associative array specifying the key/value pairs for the metadata. |
249 * @param array $options |
249 * @param array $options |
250 * @return void |
250 * @return void |
251 */ |
251 */ |
252 public function storeMetadata($destinationPath, $metadata, $options = null) |
252 public function storeMetadata($destinationPath, $metadata, $options = null) |
253 { |
253 { |
254 $destinationPath = $this->_getFullPath($destinationPath); |
254 $destinationPath = $this->_getFullPath($destinationPath); |
291 )); |
291 )); |
292 } |
292 } |
293 } |
293 } |
294 } catch (Zend_Service_Nirvanix_Exception $e) { |
294 } catch (Zend_Service_Nirvanix_Exception $e) { |
295 throw new Zend_Cloud_StorageService_Exception('Error on deleting metadata: '.$e->getMessage(), $e->getCode(), $e); |
295 throw new Zend_Cloud_StorageService_Exception('Error on deleting metadata: '.$e->getMessage(), $e->getCode(), $e); |
296 } |
296 } |
297 } |
297 } |
298 |
298 |
299 /* |
299 /* |
300 * Recursively traverse all the folders and build an array that contains |
300 * Recursively traverse all the folders and build an array that contains |
301 * the path names for each folder. |
301 * the path names for each folder. |
302 * |
302 * |
303 * @param $path - The folder path to get the list of folders from. |
303 * @param string $path folder path to get the list of folders from. |
304 * @param &$resultArray - reference to the array that contains the path names |
304 * @param array& $resultArray reference to the array that contains the path names |
305 * for each folder. |
305 * for each folder. |
306 */ |
306 */ |
307 private function getAllFolders($path, &$resultArray) |
307 private function getAllFolders($path, &$resultArray) |
308 { |
308 { |
309 $response = $this->_imfNs->ListFolder(array( |
309 $response = $this->_imfNs->ListFolder(array( |
310 'folderPath' => $path, |
310 'folderPath' => $path, |
353 'pageNumber' => 1, |
353 'pageNumber' => 1, |
354 'pageSize' => $this->maxPageSize, |
354 'pageSize' => $this->maxPageSize, |
355 )); |
355 )); |
356 } catch (Zend_Service_Nirvanix_Exception $e) { |
356 } catch (Zend_Service_Nirvanix_Exception $e) { |
357 throw new Zend_Cloud_StorageService_Exception('Error on list: '.$e->getMessage(), $e->getCode(), $e); |
357 throw new Zend_Cloud_StorageService_Exception('Error on list: '.$e->getMessage(), $e->getCode(), $e); |
358 } |
358 } |
359 |
359 |
360 $numFiles = $response->ListFolder->TotalFileCount; |
360 $numFiles = $response->ListFolder->TotalFileCount; |
361 |
361 |
362 //Add the file names to the array |
362 //Add the file names to the array |
363 if ($numFiles != 0) { |
363 if ($numFiles != 0) { |
364 //Need to special case this as Nirvanix returns an array if there is |
364 //Need to special case this as Nirvanix returns an array if there is |
377 return $resultArray; |
377 return $resultArray; |
378 } |
378 } |
379 |
379 |
380 /** |
380 /** |
381 * Get full path to an object |
381 * Get full path to an object |
382 * |
382 * |
383 * @param string $path |
383 * @param string $path |
384 * @return string |
384 * @return string |
385 */ |
385 */ |
386 private function _getFullPath($path) |
386 private function _getFullPath($path) |
387 { |
387 { |
388 return $this->_remoteDirectory . $path; |
388 return $this->_remoteDirectory . $path; |
389 } |
389 } |
390 |
390 |
391 /** |
391 /** |
392 * Get the concrete client. |
392 * Get the concrete client. |
393 * @return Zend_Service_Nirvanix |
393 * @return Zend_Service_Nirvanix |
394 */ |
394 */ |
395 public function getClient() |
395 public function getClient() |
396 { |
396 { |
397 return $this->_nirvanix; |
397 return $this->_nirvanix; |
398 } |
398 } |
399 } |
399 } |