summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2016-01-13 14:21:55 +0100
committerRoeland Jago Douma <rullzer@owncloud.com>2016-01-13 16:35:15 +0100
commit5f5951c8cf5ae1a0e194e94e1e409bf4c9bb0073 (patch)
treebc45c03e143337d22861241948682e066f363aab /lib
parentcbd3050f4c5d0c98cc627cfab5d1ab8b85f1ae7c (diff)
downloadnextcloud-server-5f5951c8cf5ae1a0e194e94e1e409bf4c9bb0073.tar.gz
nextcloud-server-5f5951c8cf5ae1a0e194e94e1e409bf4c9bb0073.zip
[Share 2.0] Let the factory do the factory stuff
* Updated unit tests (bit cleaner now)
Diffstat (limited to 'lib')
-rw-r--r--lib/private/share20/defaultshareprovider.php13
-rw-r--r--lib/private/share20/iproviderfactory.php18
-rw-r--r--lib/private/share20/ishareprovider.php7
-rw-r--r--lib/private/share20/manager.php102
-rw-r--r--lib/private/share20/providerfactory.php44
5 files changed, 53 insertions, 131 deletions
diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php
index 60c3c4390fc..7a08ecb1210 100644
--- a/lib/private/share20/defaultshareprovider.php
+++ b/lib/private/share20/defaultshareprovider.php
@@ -68,19 +68,6 @@ class DefaultShareProvider implements IShareProvider {
}
/**
- * Return the share types this provider handles
- *
- * @return int[]
- */
- public function shareTypes() {
- return [
- \OCP\Share::SHARE_TYPE_USER,
- \OCP\Share::SHARE_TYPE_GROUP,
- \OCP\Share::SHARE_TYPE_LINK,
- ];
- }
-
- /**
* Return the identifier of this provider.
*
* @return string Containing only [a-zA-Z0-9]
diff --git a/lib/private/share20/iproviderfactory.php b/lib/private/share20/iproviderfactory.php
index 0bbd304e6b8..9dabe2f6134 100644
--- a/lib/private/share20/iproviderfactory.php
+++ b/lib/private/share20/iproviderfactory.php
@@ -20,6 +20,8 @@
*/
namespace OC\Share20;
+use OC\Share20\Exception\ProviderException;
+
/**
* Interface IProviderFactory
*
@@ -29,10 +31,16 @@ namespace OC\Share20;
interface IProviderFactory {
/**
- * Creates and returns the shareProviders
- *
- * @return IShareProvider[]
- * @since 9.0.0
+ * @param string $id
+ * @return IShareProvider
+ * @throws ProviderException
+ */
+ public function getProvider($id);
+
+ /**
+ * @param int $shareType
+ * @return IShareProvider
+ * @throws ProviderException
*/
- public function getProviders();
+ public function getProviderForType($shareType);
}
diff --git a/lib/private/share20/ishareprovider.php b/lib/private/share20/ishareprovider.php
index e3a8e3c55b0..d1f82557a5f 100644
--- a/lib/private/share20/ishareprovider.php
+++ b/lib/private/share20/ishareprovider.php
@@ -27,13 +27,6 @@ use OCP\IUser;
interface IShareProvider {
/**
- * Return the share types this provider handles
- *
- * @return int[]
- */
- public function shareTypes();
-
- /**
* Return the identifier of this provider.
*
* @return string Containing only [a-zA-Z0-9]
diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php
index 0784a53ecc2..0c6f9cb59db 100644
--- a/lib/private/share20/manager.php
+++ b/lib/private/share20/manager.php
@@ -26,7 +26,6 @@ use OC\Share20\Exception\ProviderException;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
-use OCP\Preview\IProvider;
use OCP\Security\ISecureRandom;
use OCP\Security\IHasher;
use OCP\Files\Mount\IMountManager;
@@ -46,9 +45,6 @@ class Manager {
/** @var IProviderFactory */
private $factory;
- /** @var IShareProvider[] */
- private $providers;
-
/** @var array */
private $type2provider;
@@ -109,92 +105,6 @@ class Manager {
}
/**
- * @param IShareProvider[] $providers
- * @throws ProviderException
- */
- private function addProviders(array $providers) {
- foreach ($providers as $provider) {
- $id = $provider->identifier();
- $class = get_class($provider);
-
- if (!($provider instanceof IShareProvider)) {
- throw new ProviderException($class . ' is not an instance of IShareProvider');
- }
-
- if (isset($this->providers[$id])) {
- throw new ProviderException($id . ' is already registered');
- }
-
- $this->providers[$id] = $provider;
- $types = $provider->shareTypes();
-
- if ($types === []) {
- throw new ProviderException('Provider ' . $id . ' must supply share types it can handle');
- }
-
- foreach ($types as $type) {
- if (isset($this->type2provider[$type])) {
- throw new ProviderException($id . ' tried to register for share type ' . $type . ' but this type is already handled by ' . $this->type2provider[$type]);
- }
-
- $this->type2provider[$type] = $id;
- }
- }
- }
-
- /**
- * Run the factory if this is not done yet
- *
- * @throws ProviderException
- */
- private function runFactory() {
- if (!empty($this->providers)) {
- return;
- }
-
- $this->addProviders($this->factory->getProviders());
- }
-
- /**
- * @param string $id
- * @return IShareProvider
- * @throws ProviderException
- */
- private function getProvider($id) {
- $this->runFactory();
-
- if (!isset($this->providers[$id])) {
- throw new ProviderException('No provider with id ' . $id . ' found');
- }
-
- return $this->providers[$id];
- }
-
- /**
- * @param int $shareType
- * @return IShareProvider
- * @throws ProviderException
- */
- private function getProviderForType($shareType) {
- $this->runFactory();
-
- if (!isset($this->type2provider[$shareType])) {
- throw new ProviderException('No share provider registered for share type ' . $shareType);
- }
-
- return $this->getProvider($this->type2provider[$shareType]);
- }
-
- /**
- * @return IShareProvider[]
- */
- private function getProviders() {
- $this->runFactory();
-
- return $this->providers;
- }
-
- /**
* Convert from a full share id to a tuple (providerId, shareId)
*
* @param string $id
@@ -376,7 +286,7 @@ class Manager {
*
* Also this is not what we want in the future.. then we want to squash identical shares.
*/
- $provider = $this->getProviderForType(\OCP\Share::SHARE_TYPE_USER);
+ $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_USER);
$existingShares = $provider->getSharesByPath($share->getPath());
foreach($existingShares as $existingShare) {
// Identical share already existst
@@ -412,7 +322,7 @@ class Manager {
*
* Also this is not what we want in the future.. then we want to squash identical shares.
*/
- $provider = $this->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP);
+ $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP);
$existingShares = $provider->getSharesByPath($share->getPath());
foreach($existingShares as $existingShare) {
if ($existingShare->getSharedWith() === $share->getSharedWith()) {
@@ -563,7 +473,7 @@ class Manager {
throw new \Exception($error);
}
- $provider = $this->getProviderForType($share->getShareType());
+ $provider = $this->factory->getProviderForType($share->getShareType());
$share = $provider->create($share);
$share->setProviderId($provider->identifier());
@@ -602,7 +512,7 @@ class Manager {
protected function deleteChildren(IShare $share) {
$deletedShares = [];
- $provider = $this->getProviderForType($share->getShareType());
+ $provider = $this->factory->getProviderForType($share->getShareType());
foreach ($provider->getChildren($share) as $child) {
$deletedChildren = $this->deleteChildren($child);
@@ -662,7 +572,7 @@ class Manager {
$deletedShares = $this->deleteChildren($share);
// Do the actual delete
- $provider = $this->getProviderForType($share->getShareType());
+ $provider = $this->factory->getProviderForType($share->getShareType());
$provider->delete($share);
// All the deleted shares caused by this delete
@@ -703,7 +613,7 @@ class Manager {
}
list($providerId, $id) = $this->splitFullId($id);
- $provider = $this->getProvider($providerId);
+ $provider = $this->factory->getProvider($providerId);
$share = $provider->getShareById($id);
$share->setProviderId($provider->identifier());
diff --git a/lib/private/share20/providerfactory.php b/lib/private/share20/providerfactory.php
index 55ba2aadf0a..178db262d10 100644
--- a/lib/private/share20/providerfactory.php
+++ b/lib/private/share20/providerfactory.php
@@ -20,6 +20,8 @@
*/
namespace OC\Share20;
+use OC\Share20\Exception\ProviderException;
+
/**
* Class ProviderFactory
*
@@ -27,28 +29,50 @@ namespace OC\Share20;
*/
class ProviderFactory implements IProviderFactory {
+ /** @var DefaultShareProvider */
+ private $defaultProvider = null;
+
/**
* Create the default share provider.
*
* @return DefaultShareProvider
*/
protected function defaultShareProvider() {
- return new DefaultShareProvider(
- \OC::$server->getDatabaseConnection(),
- \OC::$server->getUserManager(),
- \OC::$server->getGroupManager(),
- \OC::$server->getRootFolder()
- );
+ if ($this->defaultProvider === null) {
+ $this->defaultProvider = new DefaultShareProvider(
+ \OC::$server->getDatabaseConnection(),
+ \OC::$server->getUserManager(),
+ \OC::$server->getGroupManager(),
+ \OC::$server->getRootFolder()
+ );
+ }
+
+ return $this->defaultProvider;
}
/**
* @inheritdoc
*/
- public function getProviders() {
- $providers = [];
+ public function getProvider($id) {
+ if ($id === 'ocinternal') {
+ return $this->defaultShareProvider();
+ }
+
+ throw new ProviderException('No provider with id .' . $id . ' found.');
+ }
- $providers[] = $this->defaultShareProvider();
+ /**
+ * @inheritdoc
+ */
+ public function getProviderForType($shareType) {
+ //FIXME we should not report type 2
+ if ($shareType === \OCP\Share::SHARE_TYPE_USER ||
+ $shareType === 2 ||
+ $shareType === \OCP\Share::SHARE_TYPE_GROUP ||
+ $shareType === \OCP\Share::SHARE_TYPE_LINK) {
+ return $this->defaultShareProvider();
+ }
- return $providers;
+ throw new ProviderException('No share provider for share type ' . $shareType);
}
}