Permalink
Browse files

Fix repository->getDriverInstance(), pass a context.

  • Loading branch information...
1 parent bc7862d commit 3f4cf1c90475a67af819bc3e9cc66ce206cad352 @cdujeu cdujeu committed Jun 27, 2016
@@ -450,7 +450,7 @@ public static function writeBookmarks($allBookmarks, $context, $print = true, $f
$driver = false;
$repository = $context->getRepository();
if ($format == "node_list") {
- $driver = $repository->getDriverInstance();
+ $driver = $repository->getDriverInstance($context);
if (!($driver instanceof IAjxpWrapperProvider)) {
$driver = false;
}
@@ -24,7 +24,10 @@
defined('AJXP_EXEC') or die('Access not allowed');
-
+/**
+ * Class RepositoryLoadException
+ * @package Pydio\Core\Exception
+ */
class RepositoryLoadException extends PydioException
{
/**
@@ -33,16 +36,23 @@ class RepositoryLoadException extends PydioException
private $repository;
/**
* RepositoryLoadException constructor.
- * @param RepositoryInterface $repository
+ * @param RepositoryInterface|String $repository
* @param array $errors
*/
public function __construct($repository, $errors)
{
- $message = "Error while loading workspace ".$repository->getDisplay()." : ".implode("\n-", $errors);
- $this->repository = $repository;
+ if($repository instanceof RepositoryInterface){
+ $message = "Error while loading workspace ".$repository->getDisplay()." : ".implode("\n-", $errors);
+ $this->repository = $repository;
+ }else{
+ $message = "Error while loading workspace ".$repository." : ".implode("\n-", $errors);
+ }
parent::__construct($message, false, 5000);
}
+ /**
+ * @return RepositoryInterface|String
+ */
public function getRepository(){
return $this->repository;
}
@@ -85,7 +85,7 @@ public function updateRepository($repository){
*/
public function getAccessDriver()
{
- $driver = $this->context->getRepository()->getDriverInstance();
+ $driver = $this->context->getRepository()->getDriverInstance($this->context);
if(empty($driver)){
$n = new AJXP_Node($this->getUrl());
return $n->getDriver();
@@ -208,11 +208,18 @@ public function setRepositoryObject($repository)
}
}
+ /**
+ * Set repositoryId and repositoryObject to null
+ */
public function resetRepository()
{
$this->repositoryId = $this->repositoryObject = null;
}
+ /**
+ * Build a unique string identifier for this context
+ * @return string
+ */
public function getStringIdentifier()
{
$u = $this->userId == null ? "shared" : $this->userId;
@@ -20,6 +20,8 @@
*/
namespace Pydio\Core\Model;
+use Pydio\Access\Core\AbstractAccessDriver;
+
defined('AJXP_EXEC') or die('Access not allowed');
@@ -25,6 +25,7 @@
use Pydio\Access\Core\AbstractAccessDriver;
use Pydio\Access\Core\Filter\ContentFilter;
use Pydio\Conf\Core\IGroupPathProvider;
+use Pydio\Core\Exception\RepositoryLoadException;
/**
@@ -37,9 +38,11 @@
{
/**
+ * @param ContextInterface $ctx
* @return AbstractAccessDriver
+ * @throws RepositoryLoadException
*/
- public function getDriverInstance();
+ public function getDriverInstance(ContextInterface $ctx);
/**
* @param AbstractAccessDriver $driverInstance
@@ -223,6 +223,9 @@ private function initRepositoryPlugins($ctx){
$errors = [];
$repository = $ctx->getRepository();
+ if(empty($repository)){
+ throw new RepositoryLoadException($repository, []);
+ }
$accessType = $repository->getAccessType();
/** @var AbstractAccessDriver $plugInstance */
$plugInstance = $this->getPluginByTypeName("access", $accessType);
@@ -177,7 +177,7 @@ protected function repositoryToXML($repoObject, $isActive, $exposed, $streams, $
*/
protected function repositoryClientSettings($repoObject, $ctx){
- $plugin = $repoObject->getDriverInstance();
+ $plugin = $repoObject->getDriverInstance($ctx);
if(empty($plugin)){
$plugin = PluginsService::getInstance($ctx)->getPluginByTypeName("access", $repoObject->getAccessType());
}
@@ -125,10 +125,10 @@ public function init(ContextInterface $ctx, $options = [])
//$this->enabled = true;
}
$this->repository = $ctx->getRepository();
- if (!($this->repository->getDriverInstance() instanceof \Pydio\Access\Core\IAjxpWrapperProvider)) {
+ if (!($this->repository->getDriverInstance($ctx) instanceof \Pydio\Access\Core\IAjxpWrapperProvider)) {
return;
}
- $this->accessDriver = $this->repository->getDriverInstance();
+ $this->accessDriver = $this->repository->getDriverInstance($ctx);
$this->urlBase = $ctx->getUrlBase();
if (array_key_exists("meta.watch", PluginsService::getInstance($ctx)->getActivePlugins())) {
$this->watcher = PluginsService::getInstance($ctx)->getPluginById("meta.watch");
@@ -521,7 +521,7 @@ public function switchAction(ServerRequestInterface &$requestInterface, Response
if (strpos($action, "sharelist") === false && !isSet($this->accessDriver)) {
//throw new \Exception("Cannot find access driver!");
- $this->accessDriver = $ctx->getRepository()->getDriverInstance();
+ $this->accessDriver = $ctx->getRepository()->getDriverInstance($ctx);
}
@@ -196,8 +196,7 @@ public function getDriver()
if (!isSet($this->_accessDriver)) {
$repo = $this->getRepository();
if ($repo != null) {
- $accessType = $repo->getAccessType();
- $this->_accessDriver = PluginsService::getInstance($this->getContext())->getPluginByTypeName("access", $accessType);
+ $this->_accessDriver = $repo->getDriverInstance($this->getContext());
}
}
return $this->_accessDriver;
@@ -72,7 +72,7 @@ public function addBranch($nodeOrList){
}
/**
- * @return array
+ * @return AJXP_Node[]|NodesList[]
*/
public function getChildren(){
return $this->children;
@@ -23,10 +23,12 @@
use Pydio\Access\Core\AbstractAccessDriver;
use Pydio\Access\Core\Filter\ContentFilter;
use Pydio\Core\Exception\PydioException;
+use Pydio\Core\Exception\RepositoryLoadException;
use Pydio\Core\Model\Context;
use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Model\RepositoryInterface;
+use Pydio\Core\PluginFramework\PluginsService;
use Pydio\Core\Services\LocaleService;
use Pydio\Core\Services\RepositoryService;
use Pydio\Core\Utils\Vars\InputFilter;
@@ -184,10 +186,19 @@ public function getContentFilter()
}
/**
+ * @param ContextInterface $contextInterface
* @return AbstractAccessDriver
+ * @throws RepositoryLoadException
*/
- public function getDriverInstance()
+ public function getDriverInstance(ContextInterface $contextInterface)
{
+ if(!isSet($this->driverInstance)){
+ $plugin = PluginsService::getInstance($contextInterface)->getUniqueActivePluginForType("access");
+ if(empty($plugin)){
+ throw new RepositoryLoadException($this, ["Cannot find access driver for repository ".$this->getSlug()]);
+ }
+ $this->driverInstance = $plugin;
+ }
return $this->driverInstance;
}
@@ -686,7 +686,7 @@ public function switchAction(ServerRequestInterface $requestInterface, ResponseI
}
/** @var ContextInterface $ctx */
$ctx = $requestInterface->getAttribute("ctx");
- $driver = $ctx->getRepository()->getDriverInstance();
+ $driver = $ctx->getRepository()->getDriverInstance($ctx);
if (!($driver instanceof IAjxpWrapperProvider)) {
$driver = false;
}
@@ -269,7 +269,7 @@ public function applyAction(\Psr\Http\Message\ServerRequestInterface &$requestIn
}
$basename = basename($tmpNode->getPath());
$isLeaf = $tmpNode->isLeaf();
- if (!$ctx->getRepository()->getDriverInstance()->filterNodeName($ctx, $tmpNode->getPath(), $basename, $isLeaf, ["d" => true, "f" => true, "z" => true])){
+ if (!$ctx->getRepository()->getDriverInstance($ctx)->filterNodeName($ctx, $tmpNode->getPath(), $basename, $isLeaf, ["d" => true, "f" => true, "z" => true])){
continue;
}
$tmpNode->search_score = sprintf("%0.2f", $hit->score);
@@ -349,7 +349,7 @@ public function applyAction(\Psr\Http\Message\ServerRequestInterface &$requestIn
}
$basename = basename($tmpNode->getPath());
$isLeaf = $tmpNode->isLeaf();
- if (!$ctx->getRepository()->getDriverInstance()->filterNodeName($ctx, $tmpNode->getPath(), $basename, $isLeaf, ["d"=>true, "f"=>true])){
+ if (!$ctx->getRepository()->getDriverInstance($ctx)->filterNodeName($ctx, $tmpNode->getPath(), $basename, $isLeaf, ["d"=>true, "f"=>true])){
continue;
}
$tmpNode->search_score = sprintf("%0.2f", $hit->score);
@@ -822,7 +822,7 @@ protected function loadIndex(ContextInterface $ctx, $create = true, $iPath = nul
} else {
if (!$create) {
$messages = LocaleService::getMessages();
- throw new Exception($messages["index.lucene.9"]);
+ throw new \Exception($messages["index.lucene.9"]);
}
try{
$index = \Zend_Search_Lucene::create($iPath);
@@ -74,7 +74,7 @@ public function applyChangeLock(\Psr\Http\Message\ServerRequestInterface $reques
/** @var ContextInterface $ctx */
$ctx = $requestInterface->getAttribute("ctx");
- if ($ctx->getRepository()->getDriverInstance() instanceof \Pydio\Access\Driver\StreamProvider\FS\DemoAccessDriver) {
+ if ($ctx->getRepository()->getDriverInstance($ctx) instanceof \Pydio\Access\Driver\StreamProvider\FS\DemoAccessDriver) {
throw new \Exception("Write actions are disabled in demo mode!");
}
$repo = $ctx->getRepository();
@@ -72,7 +72,7 @@ protected function excludeFromSync($ctx, $path){
return true;
}
try{
- $ctx->getRepository()->getDriverInstance()->filterUserSelectionToHidden($ctx, [$path]);
+ $ctx->getRepository()->getDriverInstance($ctx)->filterUserSelectionToHidden($ctx, [$path]);
}catch(\Exception $e){
return true;
}
@@ -256,7 +256,7 @@ public function editMeta(\Psr\Http\Message\ServerRequestInterface &$requestInter
/** @var ContextInterface $ctx */
$ctx = $requestInterface->getAttribute("ctx");
$httpVars = $requestInterface->getParsedBody();
- if ($ctx->getRepository()->getDriverInstance() instanceof \Pydio\Access\Driver\StreamProvider\FS\DemoAccessDriver) {
+ if ($ctx->getRepository()->getDriverInstance($ctx) instanceof \Pydio\Access\Driver\StreamProvider\FS\DemoAccessDriver) {
throw new \Exception("Write actions are disabled in demo mode!");
}
$user = $ctx->getUser();
@@ -70,8 +70,8 @@ protected function getUserId($node)
*/
protected function getAwsService(ContextInterface $ctx)
{
- if(method_exists($ctx->getRepository()->getDriverInstance(), "getS3Service")){
- return $ctx->getRepository()->getDriverInstance()->getS3Service();
+ if(method_exists($ctx->getRepository()->getDriverInstance($ctx), "getS3Service")){
+ return $ctx->getRepository()->getDriverInstance($ctx)->getS3Service();
}
return null;
}
@@ -20,6 +20,7 @@
*/
namespace Pydio\Uploader\Processor;
+use Pydio\Access\Core\AbstractAccessDriver;
use Pydio\Access\Core\MetaStreamWrapper;
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\Model\UserSelection;
@@ -98,7 +99,7 @@ public function preProcess(\Psr\Http\Message\ServerRequestInterface &$request, \
/** @var \Pydio\Core\Model\ContextInterface $ctx */
$ctx = $request->getAttribute("ctx");
$repository = $ctx->getRepository();
- $driver = $repository->getDriverInstance();
+ $driver = $repository->getDriverInstance($ctx);
if (method_exists($driver, "storeFileToCopy")) {
self::$remote = true;
@@ -277,7 +278,7 @@ public function postProcess(\Psr\Http\Message\ServerRequestInterface &$request,
/** @var \Pydio\Core\Model\ContextInterface $ctx */
$ctx = $request->getAttribute("ctx");
$repository = $ctx->getRepository();
- $driver = $repository->getDriverInstance();
+ $driver = $repository->getDriverInstance($ctx);
if ($httpVars["lastPartition"]) {
$dir = InputFilter::decodeSecureMagic($httpVars["dir"]);

0 comments on commit 3f4cf1c

Please sign in to comment.