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

Commit

Permalink
Hunting down global references
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Jun 9, 2016
1 parent b9d5e69 commit 89b823c
Show file tree
Hide file tree
Showing 29 changed files with 104 additions and 133 deletions.
Expand Up @@ -54,7 +54,7 @@ class AuthCliMiddleware
public static function handleRequest(ServerRequestInterface $requestInterface, ResponseInterface $responseInterface, callable $next = null){

$driverImpl = ConfService::getAuthDriverImpl();
PluginsService::getInstance()->setPluginUniqueActiveForType("auth", $driverImpl->getName(), $driverImpl);
PluginsService::getInstance(Context::emptyContext())->setPluginUniqueActiveForType("auth", $driverImpl->getName(), $driverImpl);

$options = $requestInterface->getAttribute("cli-options");
$optUser = $options["u"];
Expand Down
2 changes: 1 addition & 1 deletion core/src/core/src/pydio/Core/Http/Dav/AuthBackendBasic.php
Expand Up @@ -139,7 +139,7 @@ public function authenticate(Sabre\DAV\Server $server, $realm)

// NOW UPDATE CONTEXT
$this->context->setUserId($this->currentUser);
PluginsService::getInstance($this->context);
//PluginsService::getInstance($this->context);
AJXP_Logger::updateContext($this->context);
TextEncoder::updateContext($this->context);

Expand Down
Expand Up @@ -132,7 +132,6 @@ public function authenticate(Sabre\DAV\Server $server, $realm)

// NOW UPDATE CONTEXT
$this->context->setUserObject($loggedUser);
PluginsService::getInstance($this->context);
AJXP_Logger::updateContext($this->context);
TextEncoder::updateContext($this->context);

Expand Down
7 changes: 6 additions & 1 deletion core/src/core/src/pydio/Core/Http/Dav/Node.php
Expand Up @@ -84,7 +84,12 @@ public function updateRepository($repository){
*/
public function getAccessDriver()
{
return $this->context->getRepository()->getDriverInstance();
$driver = $this->context->getRepository()->getDriverInstance();
if(empty($driver)){
$n = new AJXP_Node($this->getUrl());
return $n->getDriver();
}
throw new \Exception("Cannot find driver instance for current node! ".$this->path);
}

/**
Expand Down
Expand Up @@ -28,6 +28,7 @@
use Pydio\Core\Exception\PydioException;
use Pydio\Core\Exception\RepositoryLoadException;
use Pydio\Core\Http\Server;
use Pydio\Core\Model\Context;
use Pydio\Core\Model\ContextInterface;
use Pydio\Core\PluginFramework\PluginsService;
use Pydio\Core\Services\AuthService;
Expand Down Expand Up @@ -59,7 +60,7 @@ public static function handleRequest(\Psr\Http\Message\ServerRequestInterface &$
try{

$driverImpl = ConfService::getAuthDriverImpl();
PluginsService::getInstance()->setPluginUniqueActiveForType("auth", $driverImpl->getName(), $driverImpl);
PluginsService::getInstance(Context::emptyContext())->setPluginUniqueActiveForType("auth", $driverImpl->getName(), $driverImpl);

$response = FrontendsLoader::frontendsAsAuthMiddlewares($requestInterface, $responseInterface);
if($response != null){
Expand Down
4 changes: 2 additions & 2 deletions core/src/core/src/pydio/Core/PluginFramework/Plugin.php
Expand Up @@ -878,7 +878,7 @@ public function logError($prefix, $message)
* @param bool $register
* @return array|bool
*/
public function detectStreamWrapper($register = false)
public function detectStreamWrapper($register = false, ContextInterface $ctx = null)
{
if (isSet($this->streamData)) {
if($this->streamData === false) return false;
Expand All @@ -905,7 +905,7 @@ public function detectStreamWrapper($register = false)
$this->streamData = $streamData;
}
if ($register) {
$pServ = PluginsService::getInstance();
$pServ = PluginsService::getInstance($ctx);
$wrappers = stream_get_wrappers();
if (!in_array($streamData["protocol"], $wrappers)) {
stream_wrapper_register($streamData["protocol"], $streamData["classname"]);
Expand Down
13 changes: 11 additions & 2 deletions core/src/core/src/pydio/Core/PluginFramework/PluginsService.php
Expand Up @@ -827,9 +827,18 @@ public function registerWrapperClass($protocol, $wrapperClassName)
* @param $protocol
* @return string
*/
public function getWrapperClassName($protocol)
public function getWrapperClassName($protocol, $register = false)
{
return $this->registeredWrappers[$protocol];
if(isSet($this->registeredWrappers[$protocol])){
return $this->registeredWrappers[$protocol];
}
/** @var AbstractAccessDriver $access */
$access = $this->getActivePluginsForType("access", true);
$data = $access->detectStreamWrapper($register);
if($data !== null && $data["protocol"] == $protocol){
return $data["classname"];
}
return null;
}

/**
Expand Down
46 changes: 6 additions & 40 deletions core/src/core/src/pydio/Core/Services/ConfService.php
Expand Up @@ -22,6 +22,7 @@

use Pydio\Access\Core\AbstractAccessDriver;
use Pydio\Access\Core\AJXP_MetaStreamWrapper;
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Auth\Core\AbstractAuthDriver;
use Pydio\Cache\Core\AbstractCacheDriver;
use Pydio\Conf\Core\AbstractAjxpUser;
Expand Down Expand Up @@ -309,7 +310,10 @@ public function detectRepositoryStreamsInst(UserInterface $user, $register = fal
$streams = array();
$currentRepos = UsersService::getRepositoriesForUser($user);
foreach ($currentRepos as $repository) {
AJXP_MetaStreamWrapper::detectWrapperForRepository($repository,$register, $streams);
$ctx = new Context();
$ctx->setUserObject($user);
$ctx->setRepositoryObject($repository);
AJXP_MetaStreamWrapper::detectWrapperForNode(new AJXP_Node($ctx->getUrlBase()),$register, $streams);
}
return $streams;
}
Expand Down Expand Up @@ -401,6 +405,7 @@ public static function getDeclaredUnsecureActions()
{
return PluginsService::searchManifestsWithCache("//action[@skipSecureToken]", function($nodes){
$res = array();
/** @var \DOMElement $node */
foreach ($nodes as $node) {
$res[] = $node->getAttribute("name");
}
Expand Down Expand Up @@ -523,45 +528,6 @@ public static function getUserPersonalParameter($parameterName, $userIdOrObject,

}


/**
* @static
* @param RepositoryInterface $repository
* @return AbstractAccessDriver
*/
public static function loadDriverForRepository(&$repository)
{
return self::getInstance()->loadRepositoryDriverInst($repository);
}

/**
* See static method
* @param RepositoryInterface $repository
* @throws PydioException|\Exception
* @return AbstractAccessDriver
*/
private function loadRepositoryDriverInst(&$repository)
{
$instance = $repository->getDriverInstance();
if (!empty($instance)) {
return $instance;
}

/** @var AbstractAccessDriver $plugInstance */
$accessType = $repository->getAccessType();
$pServ = PluginsService::getInstance();
$plugInstance = $pServ->getPluginByTypeName("access", $accessType);

/*
$ctxId = $this->getContextRepositoryId();
if ( (!empty($ctxId) || $ctxId === 0) && $ctxId == $repository->getId()) {
$this->configs["REPOSITORY"] = $repository;
$this->cacheRepository($ctxId, $repository);
}
*/
return $plugInstance;
}


/**
* Singleton method
Expand Down
Expand Up @@ -59,7 +59,6 @@ protected function initRepository(ContextInterface $contextInterface)
$this->driverConf = array();
}

$this->detectStreamWrapper(true);
$this->urlBase =$contextInterface->getUrlBase();

if (!Utils::searchIncludePath('HTTP/OAuth/Consumer.php')) {
Expand Down
11 changes: 6 additions & 5 deletions core/src/plugins/access.fs/class.fsAccessDriver.php
Expand Up @@ -99,7 +99,6 @@ protected function initRepository(ContextInterface $contextInterface)
$path = TextEncoder::toStorageEncoding($repository->getContextOption($contextInterface, "PATH"));
$recycle = $repository->getContextOption($contextInterface, "RECYCLE_BIN");
$chmod = $repository->getContextOption($contextInterface, "CHMOD_VALUE");
$this->detectStreamWrapper(true);
$this->urlBase = $contextInterface->getUrlBase();


Expand Down Expand Up @@ -366,7 +365,7 @@ public function uploadAction(ServerRequestInterface &$request, ResponseInterface
$dir = Utils::sanitize($httpVars["dir"], AJXP_SANITIZE_DIRNAME) OR "";
/** @var ContextInterface $ctx */
$ctx = $request->getAttribute("ctx");
if (AJXP_MetaStreamWrapper::actualRepositoryWrapperClass($ctx->getRepositoryId()) == "fsAccessWrapper") {
if (AJXP_MetaStreamWrapper::actualRepositoryWrapperClass(new AJXP_Node($ctx->getUrlBase())) == "fsAccessWrapper") {
$dir = fsAccessWrapper::patchPathForBaseDir($dir);
}
$dir = Utils::securePath($dir);
Expand Down Expand Up @@ -1120,8 +1119,10 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
}else{
$dir = Utils::sanitize($httpVars["dir"], AJXP_SANITIZE_DIRNAME) OR "";
}
if (AJXP_MetaStreamWrapper::actualRepositoryWrapperClass($ctx->getRepositoryId()) == "fsAccessWrapper") {
$patch = false;
if (AJXP_MetaStreamWrapper::actualRepositoryWrapperClass(new AJXP_Node($selection->currentBaseUrl())) == "fsAccessWrapper") {
$dir = fsAccessWrapper::patchPathForBaseDir($dir);
$patch = true;
}
$dir = Utils::securePath($dir);

Expand All @@ -1139,7 +1140,7 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
$startTime = microtime();
$path = $selection->nodeForPath(($dir!= ""?($dir[0]=="/"?"":"/").$dir:""))->getUrl();
$nonPatchedPath = $path;
if (AJXP_MetaStreamWrapper::actualRepositoryWrapperClass($ctx->getRepositoryId()) == "fsAccessWrapper") {
if ($patch) {
$nonPatchedPath = fsAccessWrapper::unPatchPathForBaseDir($path);
}
$testPath = @stat($path);
Expand Down Expand Up @@ -2193,7 +2194,7 @@ public function recursivePurge($dirName, $hardPurgeTime, $softPurgeTime = 0)
* @param \Pydio\Access\Core\Model\AJXP_Node $node
*/
public function setHiddenAttribute($node){
if(AJXP_MetaStreamWrapper::actualRepositoryWrapperClass($node->getRepositoryId()) == "fsAccessWrapper" && strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){
if(AJXP_MetaStreamWrapper::actualRepositoryWrapperClass($node) == "fsAccessWrapper" && strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){
$realPath = AJXP_MetaStreamWrapper::getRealFSReference($node->getUrl());
@shell_exec("attrib +H " . escapeshellarg($realPath));
}
Expand Down
1 change: 0 additions & 1 deletion core/src/plugins/access.ftp/class.ftpAccessDriver.php
Expand Up @@ -90,7 +90,6 @@ protected function initRepository(ContextInterface $contextInterface)
} else {
$this->driverConf = array();
}
$this->detectStreamWrapper(true);
$this->urlBase = $contextInterface->getUrlBase();
$recycle = $contextInterface->getRepository()->getContextOption($contextInterface, "RECYCLE_BIN");
if ($recycle != "") {
Expand Down
1 change: 0 additions & 1 deletion core/src/plugins/access.imap/class.imapAccessDriver.php
Expand Up @@ -58,7 +58,6 @@ protected function initRepository(ContextInterface $contextInterface)
$this->driverConf = array();
}

$this->detectStreamWrapper(true);
$this->urlBase = $contextInterface->getUrlBase();

}
Expand Down
10 changes: 4 additions & 6 deletions core/src/plugins/access.inbox/class.inboxAccessDriver.php
Expand Up @@ -47,7 +47,6 @@ class inboxAccessDriver extends fsAccessDriver
*/
protected function initRepository(ContextInterface $contextInterface)
{
$this->detectStreamWrapper(true);
$this->urlBase = $contextInterface->getUrlBase();
}

Expand Down Expand Up @@ -97,8 +96,7 @@ public static function getNodeData($nodePath){
$node = new AJXP_Node($nodeData["url"]);
$node->getRepository()->driverInstance = null;
try{
ConfService::loadDriverForRepository($node->getRepository());
AJXP_MetaStreamWrapper::detectWrapperForRepository($node->getRepository(), true);
$node->getDriver()->detectStreamWrapper(true);
if($node->getRepository()->hasContentFilter()){
$node->setLeaf(true);
}
Expand Down Expand Up @@ -173,12 +171,12 @@ public static function getNodes($checkStats = false, $touch = true){

$node->getRepository()->driverInstance = null;
try{
ConfService::loadDriverForRepository($node->getRepository());
$node->getDriver()->detectStreamWrapper(true);
}catch (\Exception $e){
$ext = "error";
$meta["ajxp_mime"] = "error";
}
AJXP_MetaStreamWrapper::detectWrapperForRepository($node->getRepository(), true);
AJXP_MetaStreamWrapper::detectWrapperForNode($node, true);
$stat = @stat($url);
if($stat === false){
$ext = "error";
Expand Down Expand Up @@ -230,7 +228,7 @@ public static function getNodes($checkStats = false, $touch = true){
$output[$name.$suffix.".".$ext]['stat'] = $stat;
}
}
ConfService::loadDriverForRepository($globalContext->getRepository());
//ConfService::loadDriverForRepository($globalContext->getRepository());
self::$output = $output;

if ($touch) {
Expand Down
10 changes: 5 additions & 5 deletions core/src/plugins/access.inbox/class.inboxAccessWrapper.php
Expand Up @@ -145,11 +145,11 @@ public static function translateURL($path){
$node->setLabel($label);
$node->getRepository()->driverInstance = null;
try{
ConfService::loadDriverForRepository($node->getRepository());
$node->getDriver();
}catch (\Exception $e){

}
AJXP_MetaStreamWrapper::detectWrapperForRepository($node->getRepository(), true);
AJXP_MetaStreamWrapper::detectWrapperForNode($node, true);
}
return $url;
}
Expand All @@ -173,7 +173,7 @@ public static function getRealFSReference($path, $persistent = false)
copy($realFilePointer, $tmpname);
$realFilePointer = $tmpname;
}
ConfService::loadDriverForRepository(self::$linkNode->getRepository());
self::$linkNode->getDriver();
return $realFilePointer;
}else{
$tmpname = tempnam(Utils::getAjxpTmpDir(), "real-file-inbox-pointer");
Expand All @@ -200,7 +200,7 @@ public static function copyFileInStream($path, $stream)
call_user_func(array($wrapperClass, "copyFileInStream"), $url, $stream);
*/
if(self::$linkNode !== null){
ConfService::loadDriverForRepository(self::$linkNode->getRepository());
self::$linkNode->getDriver();
}
}

Expand Down Expand Up @@ -281,7 +281,7 @@ public function stream_close()
if($this->fp !== null){
fclose($this->fp);
if(self::$linkNode !== null){
ConfService::loadDriverForRepository(self::$linkNode->getRepository());
self::$linkNode->getDriver();
}
}
}
Expand Down
1 change: 0 additions & 1 deletion core/src/plugins/access.s3/class.s3AccessDriver.php
Expand Up @@ -62,7 +62,6 @@ public function performChecks()
*/
protected function initRepository(ContextInterface $contextInterface)
{
$this->detectStreamWrapper(true);

if (is_array($this->pluginConf)) {
$this->driverConf = $this->pluginConf;
Expand Down
1 change: 0 additions & 1 deletion core/src/plugins/access.sftp/class.sftpAccessDriver.php
Expand Up @@ -72,7 +72,6 @@ protected function initRepository(ContextInterface $contextInterface)
ConfService::setConf("PROBE_REAL_SIZE", false);
$path = $contextInterface->getRepository()->getContextOption($contextInterface, "PATH");
$recycle = $contextInterface->getRepository()->getContextOption($contextInterface, "RECYCLE_BIN");
$this->detectStreamWrapper(true);
$this->urlBase = $contextInterface->getUrlBase();
restore_error_handler();
if (!file_exists($contextInterface->getUrlBase())) {
Expand Down
Expand Up @@ -68,16 +68,15 @@ protected function initRepository(ContextInterface $contextInterface)

require_once($this->getBaseDir()."/SFTPPSL_StreamWrapper.php");

$this->detectStreamWrapper(true);
$this->urlBase = $contextInterface->getUrlBase();
}

public function detectStreamWrapper($register = false)
public function detectStreamWrapper($register = false, ContextInterface $ctx = null)
{
if ($register) {
require_once($this->getBaseDir()."/SFTPPSL_StreamWrapper.php");
}
return parent::detectStreamWrapper($register);
return parent::detectStreamWrapper($register, $ctx);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions core/src/plugins/access.smb/class.smbAccessDriver.php
Expand Up @@ -27,6 +27,7 @@
use Pydio\Access\Core\RecycleBinManager;
use Pydio\Access\Core\Model\Repository;
use Pydio\Access\Driver\StreamProvider\FS\fsAccessDriver;
use Pydio\Core\Model\Context;
use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Services\ConfService;
use Pydio\Core\Exception\PydioException;
Expand Down Expand Up @@ -73,7 +74,6 @@ protected function initRepository(ContextInterface $contextInterface)
//$create = $this->repository->getOption("CREATE");
$recycle = $this->repository->getContextOption($contextInterface, "RECYCLE_BIN");

$this->detectStreamWrapper(true);
$this->urlBase = $contextInterface->getUrlBase();

if ($recycle!= "" && !is_dir($contextInterface->getUrlBase()."/".$recycle)) {
Expand All @@ -88,12 +88,12 @@ protected function initRepository(ContextInterface $contextInterface)

}

public function detectStreamWrapper($register = false)
public function detectStreamWrapper($register = false, ContextInterface $ctx = null)
{
if ($register) {
require_once($this->getBaseDir()."/smb.php");
}
return parent::detectStreamWrapper($register);
return parent::detectStreamWrapper($register, $ctx);
}

/**
Expand Down
1 change: 0 additions & 1 deletion core/src/plugins/access.swift/class.swiftAccessDriver.php
Expand Up @@ -86,7 +86,6 @@ protected function initRepository(ContextInterface $contextInterface)

$recycle = $this->repository->getContextOption($contextInterface, "RECYCLE_BIN");
ConfService::setConf("PROBE_REAL_SIZE", false);
$this->detectStreamWrapper(true);
$this->urlBase = $contextInterface->getUrlBase();
if ($recycle != "") {
RecycleBinManager::init($contextInterface->getUrlBase(), "/".$recycle);
Expand Down

0 comments on commit 89b823c

Please sign in to comment.