Permalink
Browse files

Refactor inbox driver / wrapper using context

  • Loading branch information...
1 parent 383f094 commit d61761f8c2779a34c63503d27167c5b37760e3b0 @cdujeu cdujeu committed Jun 13, 2016
@@ -30,12 +30,19 @@
use Pydio\Core\Services\AuthService;
use Pydio\Core\Controller\Controller;
+use Pydio\Core\Services\ConfService;
use Pydio\Core\Services\LocaleService;
+use Pydio\Core\Services\RepositoryService;
use Pydio\Core\Services\UsersService;
use Pydio\Core\Utils\Utils;
defined('AJXP_EXEC') or die('Access not allowed');
+/**
+ * Driver for inbox repository
+ * Class inboxAccessDriver
+ * @package Pydio\Access\Driver\StreamProvider\Inbox
+ */
class inboxAccessDriver extends fsAccessDriver
{
private static $output;
@@ -50,6 +57,12 @@ protected function initRepository(ContextInterface $contextInterface)
$this->urlBase = $contextInterface->getUrlBase();
}
+ /**
+ * Hook to node.info event
+ * @param AJXP_Node $ajxpNode
+ * @param bool $parentNode
+ * @param bool $details
+ */
public function loadNodeInfo(&$ajxpNode, $parentNode = false, $details = false)
{
parent::loadNodeInfo($ajxpNode, $parentNode, $details);
@@ -60,7 +73,7 @@ public function loadNodeInfo(&$ajxpNode, $parentNode = false, $details = false)
if(isSet($originalNode["meta"])){
$meta = $originalNode["meta"];
}else{
- $meta = array();
+ $meta = [];
}
$label = $originalNode["label"];
@@ -74,39 +87,48 @@ public function loadNodeInfo(&$ajxpNode, $parentNode = false, $details = false)
}
}
+ /**
+ * Hook for load_repository_info event
+ * @param ContextInterface $ctx
+ * @param $data
+ */
public function loadRepositoryInfo(ContextInterface $ctx, &$data){
- $allNodes = self::getNodes(false, false);
- $data['access.inbox'] = array(
+ $allNodes = self::getNodes($ctx, false, false);
+ $data['access.inbox'] = [
'files' => count($allNodes)
- );
+ ];
}
+ /**
+ * @param string $nodePath Url of a node
+ * @return array|mixed
+ */
public static function getNodeData($nodePath){
- $basename = basename(parse_url($nodePath, PHP_URL_PATH));
- if(empty($basename)){
+ $nodeObject = new AJXP_Node($nodePath);
+ $basename = $nodeObject->getLabel();
+ if($nodeObject->isRoot()){
return ['stat' => stat(Utils::getAjxpTmpDir())];
}
- $allNodes = self::getNodes(false);
+ $allNodes = self::getNodes($nodeObject->getContext(), false);
$nodeData = $allNodes[$basename];
if(!isSet($nodeData["stat"])){
- if(in_array(pathinfo($basename, PATHINFO_EXTENSION), array("error", "invitation"))){
+ if(in_array(pathinfo($basename, PATHINFO_EXTENSION), ["error", "invitation"])){
$stat = stat(Utils::getAjxpTmpDir());
}else{
$url = $nodeData["url"];
- $node = new AJXP_Node($nodeData["url"]);
- $node->getRepository()->driverInstance = null;
+ $node = new AJXP_Node($url);
try{
$node->getDriver()->detectStreamWrapper(true);
if($node->getRepository()->hasContentFilter()){
$node->setLeaf(true);
}
- Controller::applyHook("node.read", array(&$node));
+ Controller::applyHook("node.read", [&$node]);
$stat = stat($url);
}catch (\Exception $e){
$stat = stat(Utils::getAjxpTmpDir());
}
- if(is_array($stat) && AuthService::getLoggedUser() != null){
- $acl = AuthService::getLoggedUser()->mergedRole->getAcl($nodeData["meta"]["shared_repository_id"]);
+ if(is_array($stat) && $nodeObject->getContext()->hasUser()){
+ $acl = $nodeObject->getContext()->getUser()->getMergedRole()->getAcl($nodeData["meta"]["shared_repository_id"]);
if($acl == "r"){
self::disableWriteInStat($stat);
}
@@ -118,34 +140,45 @@ public static function getNodeData($nodePath){
return $nodeData;
}
- public static function getNodes($checkStats = false, $touch = true){
+ /**
+ * @param ContextInterface $parentContext
+ * @param bool $checkStats
+ * @param bool $touch
+ * @return array
+ */
+ public static function getNodes(ContextInterface $parentContext, $checkStats = false, $touch = true){
if(isSet(self::$output)){
return self::$output;
}
- $globalContext = Context::fromGlobalServices();
$mess = LocaleService::getMessages();
- $repos = UsersService::getRepositoriesForUser($globalContext->getUser());
+ $repos = UsersService::getRepositoriesForUser($parentContext->getUser());
+ $userId = $parentContext->getUser()->getId();
- $output = array();
- $touchReposIds = array();
+ $output = [];
+ $touchReposIds = [];
foreach($repos as $repo) {
if (!$repo->hasOwner() || !$repo->hasContentFilter()) {
continue;
}
$repoId = $repo->getId();
- if(strpos("ocs_remote_share_", $repoId) !== 0){
+// DISABLE REMOTE SHARE FOR TESTING
+// if(strpos($repoId, "ocs_remote_share_") === 0){
+// continue;
+// }
+
+ if(strpos($repoId, "ocs_remote_share_") !== 0){
$touchReposIds[] = $repoId;
}
- $url = "pydio://" . $repoId . "/";
- $meta = array(
+ $url = "pydio://".$userId . "@" . $repoId . "/";
+ $meta = [
"shared_repository_id" => $repoId,
"ajxp_description" => "File shared by ".$repo->getOwner(). " ". Utils::relativeDate($repo->getSafeOption("CREATION_TIME"), $mess),
"share_meta_type" => 1
- );
+ ];
$cFilter = $repo->getContentFilter();
$filter = ($cFilter instanceof ContentFilter) ? array_keys($cFilter->filters)[0] : $cFilter;
@@ -169,14 +202,13 @@ public static function getNodes($checkStats = false, $touch = true){
if($checkStats){
- $node->getRepository()->driverInstance = null;
try{
$node->getDriver()->detectStreamWrapper(true);
}catch (\Exception $e){
$ext = "error";
$meta["ajxp_mime"] = "error";
}
- AJXP_MetaStreamWrapper::detectWrapperForNode($node, true);
+
$stat = @stat($url);
if($stat === false){
$ext = "error";
@@ -203,8 +235,8 @@ public static function getNodes($checkStats = false, $touch = true){
}else if($ext == "error"){
$label .= " (".$mess["inbox_driver.5"].")";
}
- if(is_array($stat) && AuthService::getLoggedUser() != null){
- $acl = AuthService::getLoggedUser()->mergedRole->getAcl($repoId);
+ if(is_array($stat) && $parentContext->hasUser()){
+ $acl = $parentContext->getUser()->getMergedRole()->getAcl($repoId);
if($acl == "r"){
self::disableWriteInStat($stat);
}
@@ -228,17 +260,16 @@ public static function getNodes($checkStats = false, $touch = true){
$output[$name.$suffix.".".$ext]['stat'] = $stat;
}
}
- //ConfService::loadDriverForRepository($globalContext->getRepository());
self::$output = $output;
if ($touch) {
- if (count($touchReposIds) && AuthService::getLoggedUser() != null) {
- $uPref = AuthService::getLoggedUser()->getPref("repository_last_connected");
- if (empty($uPref)) $uPref = array();
+ if (count($touchReposIds) && $parentContext->hasUser()) {
+ $uPref = $parentContext->getUser()->getPref("repository_last_connected");
+ if (empty($uPref)) $uPref = [];
foreach ($touchReposIds as $rId) {
$uPref[$rId] = time();
}
- AuthService::getLoggedUser()->setPref("repository_last_connected", $uPref);
+ $parentContext->getUser()->setPref("repository_last_connected", $uPref);
}
}
return $output;
@@ -30,6 +30,11 @@
defined('AJXP_EXEC') or die('Access not allowed');
+/**
+ * Class inboxAccessWrapper
+ * Stream wrapper for Inbox repository
+ * @package Pydio\Access\Driver\StreamProvider\Inbox
+ */
class inboxAccessWrapper implements IAjxpWrapper
{
/**
@@ -58,8 +63,9 @@ class inboxAccessWrapper implements IAjxpWrapper
*/
public function dir_opendir($path, $options)
{
- if(trim(parse_url($path, PHP_URL_PATH), "/") == ""){
- $this->nodesIterator = new ArrayIterator(inboxAccessDriver::getNodes(true));
+ $node = new AJXP_Node($path);
+ if($node->isRoot()){
+ $this->nodesIterator = new ArrayIterator(inboxAccessDriver::getNodes($node->getContext(), true));
}else{
$this->nodesIterator = new ArrayIterator([]);
}
@@ -118,9 +124,10 @@ public static function translateURL($path){
$pydioScheme = false;
self::$linkNode = null;
+ $initialNode = new AJXP_Node($path);
- $nodes = inboxAccessDriver::getNodes(false);
- $nodePath = basename(parse_url($path, PHP_URL_PATH));
+ $nodes = inboxAccessDriver::getNodes($initialNode->getContext(), false);
+ $nodePath = basename($initialNode->getPath());
$node = $nodes[ltrim($nodePath, '/')];
if (empty($node) || ! isset($node['url'])) {

0 comments on commit d61761f

Please sign in to comment.