Permalink
Browse files

Finished replacing getOption by getContextOption / getSafeOption, no …

…more usage.
  • Loading branch information...
1 parent 3907463 commit 54dff9d300b779eeb0e1ce9a1135aab5b6a08d85 @cdujeu cdujeu committed Jun 7, 2016
@@ -113,7 +113,7 @@ public function authenticate(Sabre\DAV\Server $server, $realm)
AJXP_Safe::storeCredentials($this->currentUser, $userpass[1]);
}
$repoId = $this->context->getRepositoryId();
- if(isSet($repoId) && ConfService::getRepositoryById($repoId)->getOption("AJXP_WEBDAV_DISABLED") === true){
+ if(isSet($repoId) && ConfService::getRepositoryById($repoId)->getContextOption($this->context, "AJXP_WEBDAV_DISABLED") === true){
throw new Sabre\DAV\Exception\NotAuthenticated('You are not allowed to access this workspace');
}
ConfService::switchRootDir($repoId);
@@ -62,7 +62,7 @@ public function getChildren()
foreach ($repos as $repository) {
$accessType = $repository->getAccessType();
$driver = PluginsService::getInstance()->getPluginByTypeName("access", $accessType);
- if ($driver instanceof \Pydio\Access\Core\IAjxpWrapperProvider && $repository->getOption("AJXP_WEBDAV_DISABLED") !== true) {
+ if ($driver instanceof \Pydio\Access\Core\IAjxpWrapperProvider && $repository->getContextOption($this->context, "AJXP_WEBDAV_DISABLED") !== true) {
$this->children[$repository->getSlug()] = new Sabre\DAV\SimpleCollection($repository->getSlug());
}
}
@@ -137,13 +137,13 @@ public function getResourceUrl($path)
}
/**
- * @param String $directoryPath
- * @param array $repositoryResolvedOptions
+ * @param AJXP_Node $node
* @return int
*/
- public function directoryUsage($directoryPath, $repositoryResolvedOptions = []){
+ public function directoryUsage(AJXP_Node $node){
- $dir = (isSet($repositoryResolvedOptions["PATH"]) ? $repositoryResolvedOptions["PATH"] : $this->repository->getOption("PATH")).$directoryPath;
+ //$dir = (isSet($repositoryResolvedOptions["PATH"]) ? $repositoryResolvedOptions["PATH"] : $this->repository->getOption("PATH")).$directoryPath;
+ $dir = $node->getRealFile();
$size = -1;
if ( ( PHP_OS == "WIN32" || PHP_OS == "WINNT" || PHP_OS == "Windows") && class_exists("COM") ) {
$obj = new COM ( 'scripting.filesystemobject' );
@@ -141,7 +141,7 @@ public static function getNodes($checkStats = false, $touch = true){
$url = "pydio://" . $repoId . "/";
$meta = array(
"shared_repository_id" => $repoId,
- "ajxp_description" => "File shared by ".$repo->getOwner(). " ". Utils::relativeDate($repo->getOption("CREATION_TIME"), $mess),
+ "ajxp_description" => "File shared by ".$repo->getOwner(). " ". Utils::relativeDate($repo->getSafeOption("CREATION_TIME"), $mess),
"share_meta_type" => 1
);
@@ -96,14 +96,13 @@ public function getS3Service(){
}
/**
- * @param String $directoryPath
- * @param array $repositoryResolvedOptions
+ * @param AJXP_Node $node
* @return int
*/
- public function directoryUsage($directoryPath, $repositoryResolvedOptions = []){
+ public function directoryUsage(AJXP_Node $node){
$client = $this->getS3Service();
- $bucket = (isSet($repositoryResolvedOptions["CONTAINER"])?$repositoryResolvedOptions["CONTAINER"]:$this->repository->getOption("CONTAINER"));
- $path = (isSet($repositoryResolvedOptions["PATH"])?$repositoryResolvedOptions["PATH"]:"");
+ $bucket = $node->getRepository()->getContextOption($node->getContext(), "CONTAINER"); //(isSet($repositoryResolvedOptions["CONTAINER"])?$repositoryResolvedOptions["CONTAINER"]:$this->repository->getOption("CONTAINER"));
+ $path = rtrim($node->getRepository()->getContextOption($node->getContext(), "PATH"), "/").$node->getPath(); //(isSet($repositoryResolvedOptions["PATH"])?$repositoryResolvedOptions["PATH"]:"");
$objects = $client->getIterator('ListObjects', array(
'Bucket' => $bucket,
'Prefix' => $path
@@ -33,6 +33,7 @@
use Pydio\Access\Core\Model\UserSelection;
use Pydio\Core\Http\Message\UserMessage;
use Pydio\Core\Http\Response\SerializableResponseStream;
+use Pydio\Core\Model\Context;
use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Model\RepositoryInterface;
use Pydio\Core\Services\AuthService;
@@ -54,9 +55,7 @@
use Pydio\Share\View\PublicAccessManager;
use Pydio\OCS as OCS;
use Zend\Diactoros\Response;
-use Zend\Diactoros\Response\EmptyResponse;
use Zend\Diactoros\Response\JsonResponse;
-use Zend\Diactoros\ServerRequestFactory;
defined('AJXP_EXEC') or die( 'Access not allowed');
require_once("plugins/action.share/vendor/autoload.php");
@@ -292,7 +291,7 @@ public function getShareStore(){
$hMin = $this->getContextualOption($this->currentContext, "HASH_MIN_LENGTH");
}
$this->shareStore = new ShareStore(
- $this->currentContext,
+ isSet($this->currentContext) ? $this->currentContext : Context::fromGlobalServices(),
ConfService::getCoreConf("PUBLIC_DOWNLOAD_FOLDER"),
$hMin
);
@@ -340,7 +339,7 @@ protected function getRightsManager(){
);
}
$this->rightsManager = new ShareRightsManager(
- $this->currentContext,
+ isSet($this->currentContext) ? $this->currentContext : Context::fromGlobalServices(),
$options,
$this->getShareStore(),
$this->watcher);
@@ -912,7 +911,7 @@ public function switchAction(ServerRequestInterface &$requestInterface, Response
}else if($userContext == "user" && $ctx->getUser()->isAdmin() && !empty($httpVars["user_id"])){
$currentUser = Utils::sanitize($httpVars["user_id"], AJXP_SANITIZE_EMAILCHARS);
}
- $nodes = $this->listSharesAsNodes("/data/repositories/$parentRepoId/shares", $currentUser, $parentRepoId);
+ $nodes = $this->listSharesAsNodes($ctx, "/data/repositories/$parentRepoId/shares", $currentUser, $parentRepoId);
$nodesList = new NodesList();
if($userContext == "current"){
@@ -1065,6 +1064,7 @@ public function cleanUserShares($userId){
*/
private function findMirrorNodesInShares($node, $direction){
$result = array();
+ $crtContext = $node->getContext();
if($direction !== "UP"){
$upmetas = array();
$this->getShareStore()->getMetaManager()->collectSharesInParent($node, $upmetas);
@@ -1083,7 +1083,8 @@ private function findMirrorNodesInShares($node, $direction){
}
$sharedNode = $metadata["SOURCE_NODE"];
$sharedPath = substr($node->getPath(), strlen($sharedNode->getPath()));
- $sharedNodeUrl = $node->getScheme() . "://".$wsId.$sharedPath;
+ $newContext = $crtContext->withRepositoryId($wsId);
+ $sharedNodeUrl = $newContext->getUrlBase().$sharedPath;// $node->getScheme() . "://".$wsId.$sharedPath;
$result[$wsId] = array(new AJXP_Node($sharedNodeUrl), "DOWN");
$this->logDebug('MIRROR NODES', 'Found shared in parent - register node '.$sharedNodeUrl);
}
@@ -1095,19 +1096,18 @@ private function findMirrorNodesInShares($node, $direction){
$parentRepoId = $node->getRepository()->getParentId();
$parentRepository = ConfService::getRepositoryById($parentRepoId);
if(!empty($parentRepository) && !$parentRepository->isTemplate){
- $currentRoot = $node->getRepository()->getOption("PATH");
+ $currentRoot = $node->getRepository()->getContextOption($crtContext, "PATH");
+ $newContext = $crtContext->withRepositoryId($parentRepoId);
$owner = $node->getRepository()->getOwner();
- $resolveUser = null;
- if($owner != null){
- $resolveUser = ConfService::getConfStorageImpl()->createUserObject($owner);
+ if($owner !== null){
+ $newContext = $newContext->withUserId($owner);
}
- $parentRoot = $parentRepository->getOption("PATH", false, $resolveUser);
+ $parentRoot = $parentRepository->getContextOption($newContext, "PATH");
$relative = substr($currentRoot, strlen($parentRoot));
$relative = TextEncoder::toStorageEncoding($relative);
- $parentNodeURL = $node->getScheme()."://".$parentRepoId.$relative.$node->getPath();
+ $parentNodeURL = $newContext->getUrlBase().$relative.$node->getPath();
$this->logDebug("action.share", "Should trigger on ".$parentNodeURL);
$parentNode = new AJXP_Node($parentNodeURL);
- if($owner != null) $parentNode->setUserId($owner);
$result[$parentRepoId] = array($parentNode, "UP");
}
}
@@ -1411,7 +1411,7 @@ protected function createOrLoadSharedRepository($httpVars, &$update){
$replace = true;
}
$newScope = ((isSet($httpVars["share_scope"]) && $httpVars["share_scope"] == "public") ? "public" : "private");
- $oldScope = $editingRepo->getOption("SHARE_ACCESS");
+ $oldScope = $editingRepo->getSafeOption("SHARE_ACCESS");
$currentOwner = $editingRepo->getOwner();
if($newScope != $oldScope && $currentOwner != $loggedUser->getId()){
$mess = ConfService::getMessages();
@@ -1758,14 +1758,15 @@ public function listShares($currentUser = true, $parentRepositoryId="", $cursor
}
/**
+ * @param ContextInterface $ctx
* @param $rootPath
* @param bool|string $currentUser if true, currently logged user. if false all users. If string, user ID.
* @param string $parentRepositoryId
* @param null $cursor
* @param bool $xmlPrint
* @return AJXP_Node[]
*/
- public function listSharesAsNodes($rootPath, $currentUser = true, $parentRepositoryId = "", $cursor = null, $xmlPrint = false){
+ public function listSharesAsNodes(ContextInterface $ctx, $rootPath, $currentUser = true, $parentRepositoryId = "", $cursor = null, $xmlPrint = false){
$shares = $this->listShares($currentUser, $parentRepositoryId, $cursor);
$nodes = array();
@@ -1817,12 +1818,14 @@ public function listSharesAsNodes($rootPath, $currentUser = true, $parentReposit
$meta["owner"] = $repoObject->getOwner();
$meta["shared_element_parent_repository"] = $repoObject->getParentId();
if(!empty($parent)) {
- $parentPath = $parent->getOption("PATH", false, $meta["owner"]);
+ $ctx = new Context($meta["owner"], $parent->getId());
+ $parentPath = $parent->getContextOption($ctx, "PATH");
$meta["shared_element_parent_repository_label"] = $parent->getDisplay();
}else{
$crtParent = ConfService::getRepositoryById($repoObject->getParentId());
if(!empty($crtParent)){
- $parentPath = $crtParent->getOption("PATH", false, $meta["owner"]);
+ $ctx = new Context($meta["owner"], $repoObject->getParentId());
+ $parentPath = $crtParent->getContextOption($ctx, "PATH");
$meta["shared_element_parent_repository_label"] = $crtParent->getDisplay();
}else {
$meta["shared_element_parent_repository_label"] = $repoObject->getParentId();
@@ -1835,7 +1838,7 @@ public function listSharesAsNodes($rootPath, $currentUser = true, $parentReposit
}else{
$meta["ajxp_shared_minisite"] = "public";
$meta["icon"] = "folder.png";
- $meta["original_path"] = $repoObject->getOption("PATH");
+ $meta["original_path"] = $repoObject->getContextOption($ctx, "PATH");
}
if(!empty($parentPath) && strpos($meta["original_path"], $parentPath) === 0){
$meta["original_path"] = substr($meta["original_path"], strlen($parentPath));
@@ -584,7 +584,7 @@ public function moveSharesFromMeta($shares, $operation="move", $oldNode, $newNod
$repo->setDisplay($newNodeLabel);
}
$cFilter = $repo->getContentFilter();
- $path = $repo->getOption("PATH", true);
+ $path = $repo->getSafeOption("PATH");
$save = false;
if(isSet($cFilter)){
if($parentRepositoryPath !== null){
@@ -608,7 +608,7 @@ public function moveSharesFromMeta($shares, $operation="move", $oldNode, $newNod
//ConfService::getConfStorageImpl()->saveRepository($repo, true);
ConfService::replaceRepository($repo->getId(), $repo);
}
- $access = $repo->getOption("SHARE_ACCESS");
+ $access = $repo->getSafeOption("SHARE_ACCESS");
if(!empty($access) && $access == "PUBLIC"){
$publicShares[$id] = $data;
}else{
@@ -123,12 +123,11 @@ public function makePublicletOptions($filePath, $password, $expires, $downloadli
public function makeSharedRepositoryOptions(ContextInterface $ctx, $httpVars){}
/**
- * @param $directoryPath string
- * @param $repositoryResolvedOptions array
+ * @param $node AJXP_Node
* @return int
* @throws \Exception
*/
- public function directoryUsage($directoryPath, $repositoryResolvedOptions = []){
+ public function directoryUsage(AJXP_Node $node){
throw new \Exception("Current driver does not support recursive directory usage!");
}
@@ -624,7 +624,7 @@ public function getSizeRecursive(){
Controller::applyHook("node.size.recursive", array(&$this, &$result));
if($result == -1){
try{
- return $this->getDriver()->directoryUsage($this->getPath(), []);
+ return $this->getDriver()->directoryUsage($this);
}catch(\Exception $e){
return -1;
}
@@ -345,53 +345,6 @@ public function getContextOption(ContextInterface $ctx, $oName){
}
- public function getOption($oName, $safe=false, $resolveUser = null)
- {
- if(isSet($this->inferOptionsFromParent) && isSet($this->parentId)){
- $parentTemplateObject = ConfService::getRepositoryById($this->parentId);
- if(empty($parentTemplateObject) || !is_a($parentTemplateObject, "Repository")) {
- throw new \Exception("Option should be loaded from parent repository, but it was not found");
- }
- }
- if (!$safe && $this->inferOptionsFromParent) {
- if (isSet($parentTemplateObject)) {
- $pvalue = $parentTemplateObject->getOption($oName, $safe);
- $pathChanged = false;
- if (is_string($pvalue) && strstr($pvalue, "AJXP_WORKSPACE_UUID") !== false) {
- $pvalue = rtrim(str_replace("AJXP_WORKSPACE_UUID", $this->getUniqueId(), $pvalue), "/");
- $pathChanged = true;
- }
- if (is_string($pvalue) && strstr($pvalue, "AJXP_WORKSPACE_SLUG") !== false) {
- $pvalue = rtrim(str_replace("AJXP_WORKSPACE_SLUG", $this->getSlug(), $pvalue), "/");
- $pathChanged = true;
- }
- if (is_string($pvalue) && strstr($pvalue, "AJXP_ALLOW_SUB_PATH") !== false) {
- $pvalue = rtrim(str_replace("AJXP_ALLOW_SUB_PATH", "", $pvalue), "/")."/".$this->options[$oName];
- $pathChanged = true;
- }
- if ($pathChanged) {
- return \Pydio\Core\Utils\Utils::securePath($pvalue);
- }
- }
- }
- if (isSet($this->options[$oName])) {
- $value = $this->options[$oName];
- $tmpContext = Context::fromGlobalServices();
- if($resolveUser !== null) $tmpContext->setUserId($resolveUser);
- if(!$safe) $value = VarsFilter::filter($value, $tmpContext);
- return $value;
- }
- if ($this->inferOptionsFromParent) {
- if (!isset($parentTemplateObject)) {
- $parentTemplateObject = ConfService::getRepositoryById($this->parentId);
- }
- if (isSet($parentTemplateObject)) {
- return $parentTemplateObject->getOption($oName, $safe);
- }
- }
- return "";
- }
-
public function getOptionsDefined()
{
//return array_keys($this->options);
@@ -112,6 +112,7 @@ public function start($baseUri = "/"){
* @return Collection|SharingCollection
* @throws \Exception
*/
+ /*
protected function initCollectionForFileOrFolderAsUniqueItem(&$baseUri){
try{
$testBackend = new BasicAuthNoPass();
@@ -138,7 +139,7 @@ protected function initCollectionForFileOrFolderAsUniqueItem(&$baseUri){
}
return $rootCollection;
}
-
-
+ */
+
}

0 comments on commit 54dff9d

Please sign in to comment.