Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Fix repository->getDriverInstance(), pass a context.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Jun 27, 2016
1 parent bc7862d commit 3f4cf1c
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 26 deletions.
2 changes: 1 addition & 1 deletion core/src/core/src/pydio/Core/Controller/XMLWriter.php
Expand Up @@ -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;
}
Expand Down
18 changes: 14 additions & 4 deletions core/src/core/src/pydio/Core/Exception/RepositoryLoadException.php
Expand Up @@ -24,7 +24,10 @@

defined('AJXP_EXEC') or die('Access not allowed');


/**
* Class RepositoryLoadException
* @package Pydio\Core\Exception
*/
class RepositoryLoadException extends PydioException
{
/**
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/core/src/pydio/Core/Http/Dav/Node.php
Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions core/src/core/src/pydio/Core/Model/Context.php
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions core/src/core/src/pydio/Core/Model/ContextInterface.php
Expand Up @@ -20,6 +20,8 @@
*/
namespace Pydio\Core\Model;

use Pydio\Access\Core\AbstractAccessDriver;

defined('AJXP_EXEC') or die('Access not allowed');


Expand Down
5 changes: 4 additions & 1 deletion core/src/core/src/pydio/Core/Model/RepositoryInterface.php
Expand Up @@ -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;


/**
Expand All @@ -37,9 +38,11 @@ interface RepositoryInterface extends IGroupPathProvider
{

/**
* @param ContextInterface $ctx
* @return AbstractAccessDriver
* @throws RepositoryLoadException
*/
public function getDriverInstance();
public function getDriverInstance(ContextInterface $ctx);

/**
* @param AbstractAccessDriver $driverInstance
Expand Down
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion core/src/core/src/pydio/Core/Serializer/RepositoryXML.php
Expand Up @@ -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());
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/plugins/action.share/src/ShareCenter.php
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}


Expand Down
3 changes: 1 addition & 2 deletions core/src/plugins/core.access/src/Model/AJXP_Node.php
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/core.access/src/Model/NodesList.php
Expand Up @@ -72,7 +72,7 @@ public function addBranch($nodeOrList){
}

/**
* @return array
* @return AJXP_Node[]|NodesList[]
*/
public function getChildren(){
return $this->children;
Expand Down
13 changes: 12 additions & 1 deletion core/src/plugins/core.access/src/Model/Repository.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/core.conf/AbstractConfDriver.php
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/plugins/index.lucene/LuceneIndexer.php
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/meta.simple_lock/SimpleLockManager.php
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/meta.syncable/ChangesTracker.php
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/meta.user/UserMetaManager.php
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/metastore.s3/S3MetaStore.php
Expand Up @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions core/src/plugins/uploader.jumploader/Jumploader.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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"]);
Expand Down

0 comments on commit 3f4cf1c

Please sign in to comment.