diff options
author | Jörn Friedrich Dreyer <jfd@butonic.de> | 2014-06-17 22:06:56 +0200 |
---|---|---|
committer | Jörn Friedrich Dreyer <jfd@butonic.de> | 2014-06-18 12:53:20 +0200 |
commit | 5cae863408630aee768adf70fdb5c11f72b713fa (patch) | |
tree | 8de499b906379bd25e2e3a23b5a15581523586c9 /lib/private/files/objectstore | |
parent | 9335a5f07f667ae5c917cc1ee065bceecdb65795 (diff) | |
download | nextcloud-server-5cae863408630aee768adf70fdb5c11f72b713fa.tar.gz nextcloud-server-5cae863408630aee768adf70fdb5c11f72b713fa.zip |
change architecture from inheritance to composition
Diffstat (limited to 'lib/private/files/objectstore')
-rw-r--r-- | lib/private/files/objectstore/homeobjectstorestorage.php | 34 | ||||
-rw-r--r-- | lib/private/files/objectstore/objectstorestorage.php (renamed from lib/private/files/objectstore/abstractobjectstore.php) | 41 | ||||
-rw-r--r-- | lib/private/files/objectstore/swift.php | 30 |
3 files changed, 62 insertions, 43 deletions
diff --git a/lib/private/files/objectstore/homeobjectstorestorage.php b/lib/private/files/objectstore/homeobjectstorestorage.php new file mode 100644 index 00000000000..0c889725828 --- /dev/null +++ b/lib/private/files/objectstore/homeobjectstorestorage.php @@ -0,0 +1,34 @@ +<?php +/** + * @author Jörn Friedrich Dreyer + * @copyright (c) 2014 Jörn Friedrich Dreyer <jfd@owncloud.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OC\Files\ObjectStore; + +class HomeObjectStoreStorage extends ObjectStoreStorage { + + public function __construct($params) { + parent::__construct($params); + + //initialize cache with root directory in cache + if ( ! $this->is_dir('files') ) { + $this->mkdir('files'); + } + } + +}
\ No newline at end of file diff --git a/lib/private/files/objectstore/abstractobjectstore.php b/lib/private/files/objectstore/objectstorestorage.php index de82003f0e8..6b48e2d78dd 100644 --- a/lib/private/files/objectstore/abstractobjectstore.php +++ b/lib/private/files/objectstore/objectstorestorage.php @@ -20,32 +20,14 @@ namespace OC\Files\ObjectStore; -abstract class AbstractObjectStore extends \OC\Files\Storage\Common { +use OCP\Files\ObjectStore\IObjectStore; - /** - * @param string $urn the unified resource name used to identify the object - * @param string $tmpFile path to the local temporary file that the object - * should be loaded from - * @return void - * @throws Exception when something goes wrong, message will be logged - */ - abstract protected function createObject($urn, $tmpFile = null); +class ObjectStoreStorage extends \OC\Files\Storage\Common { /** - * @param string $urn the unified resource name used to identify the object - * @param string $tmpFile path to the local temporary file that should be - * used to store the object - * @return void - * @throws Exception when something goes wrong, message will be logged + * @var \OCP\Files\ObjectStore\IObjectStore $objectStore */ - abstract protected function getObject($urn, $tmpFile); - - /** - * @param string $urn the unified resource name used to identify the object - * @return void - * @throws Exception when something goes wrong, message will be logged - */ - abstract protected function deleteObject($urn); + protected $objectStore; /** * @var \OC\User\User $user @@ -58,11 +40,16 @@ abstract class AbstractObjectStore extends \OC\Files\Storage\Common { private static $tmpFiles = array(); public function __construct($params) { - if (isset($params['user']) && is_object($params['user'])) { + if (isset($params['user']) && $params['user'] instanceof \OC\User\User) { $this->user = $params['user']; } else { $this->user = null; } + if (isset($params['objectstore']) && $params['objectstore'] instanceof IObjectStore) { + $this->objectStore = $params['objectstore']; + } else { + throw new \Exception('missing IObjectStore instance'); + } //initialize cache with root directory in cache if ( ! $this->is_dir('/') ) { $this->mkdir('/'); @@ -243,7 +230,7 @@ abstract class AbstractObjectStore extends \OC\Files\Storage\Common { return $this->rmdir($path); } try { - $this->deleteObject($this->getURN($stat['fileid'])); + $this->objectStore->deleteObject($this->getURN($stat['fileid'])); } catch (\Exception $ex) { if ($ex->getCode() !== 404) { \OCP\Util::writeLog('objectstore', 'Could not delete object: '.$ex->getMessage(), \OCP\Util::ERROR); @@ -269,7 +256,7 @@ abstract class AbstractObjectStore extends \OC\Files\Storage\Common { $tmpFile = \OC_Helper::tmpFile(); self::$tmpFiles[$tmpFile] = $path; try { - $this->getObject($this->getURN($stat['fileid']), $tmpFile); + $this->objectStore->getObject($this->getURN($stat['fileid']), $tmpFile); } catch (\Exception $ex) { \OCP\Util::writeLog('objectstore', 'Could not get object: '.$ex->getMessage(), \OCP\Util::ERROR); return false; @@ -376,7 +363,7 @@ abstract class AbstractObjectStore extends \OC\Files\Storage\Common { ); $fileId = $this->getCache()->put($path, $stat); try { - $this->createObject($this->getURN($fileId)); + $this->objectStore->updateObject($this->getURN($fileId)); } catch (\Exception $ex) { $this->getCache()->remove($path); \OCP\Util::writeLog('objectstore', 'Could not create object: '.$ex->getMessage(), \OCP\Util::ERROR); @@ -424,7 +411,7 @@ abstract class AbstractObjectStore extends \OC\Files\Storage\Common { $fileId = $this->getCache()->put($path, $stat); try { //upload to object storage - $this->createObject($this->getURN($fileId), $tmpFile); + $this->objectStore->updateObject($this->getURN($fileId), $tmpFile); } catch (\Exception $ex) { $this->getCache()->remove($path); \OCP\Util::writeLog('objectstore', 'Could not create object: '.$ex->getMessage(), \OCP\Util::ERROR); diff --git a/lib/private/files/objectstore/swift.php b/lib/private/files/objectstore/swift.php index 53367367af0..f66b03889d2 100644 --- a/lib/private/files/objectstore/swift.php +++ b/lib/private/files/objectstore/swift.php @@ -23,7 +23,7 @@ namespace OC\Files\ObjectStore; use Guzzle\Http\Exception\ClientErrorResponseException; use OpenCloud\OpenStack; -class Swift extends AbstractObjectStore { +class Swift implements \OCP\Files\ObjectStore\IObjectStore { /** * @var \OpenCloud\ObjectStore\Service @@ -78,19 +78,22 @@ class Swift extends AbstractObjectStore { throw $ex; } } - - //set the user via parent constructor, also initializes the root of the filecache - parent::__construct($params); } + /** * @param string $urn Unified Resource Name + * @param string $tmpFile * @return void * @throws Exception from openstack lib when something goes wrong */ - protected function deleteObject($urn) { - $object = $this->container->getObject($urn); - $object->delete(); + public function updateObject($urn, $tmpFile = null) { + $fileData = ''; + if ($tmpFile) { + $fileData = fopen($tmpFile, 'r'); + } + + $this->container->uploadObject($urn, $fileData); } /** @@ -99,7 +102,7 @@ class Swift extends AbstractObjectStore { * @return void * @throws Exception from openstack lib when something goes wrong */ - protected function getObject($urn, $tmpFile) { + public function getObject($urn, $tmpFile) { $object = $this->container->getObject($urn); /** @var $objectContent \Guzzle\Http\EntityBody **/ @@ -112,17 +115,12 @@ class Swift extends AbstractObjectStore { /** * @param string $urn Unified Resource Name - * @param string $tmpFile * @return void * @throws Exception from openstack lib when something goes wrong */ - protected function createObject($urn, $tmpFile = null) { - $fileData = ''; - if ($tmpFile) { - $fileData = fopen($tmpFile, 'r'); - } - - $this->container->uploadObject($urn, $fileData); + public function deleteObject($urn) { + $object = $this->container->getObject($urn); + $object->delete(); } public function deleteContainer($recursive = false) { |