Permalink
Browse files

Try to remove reference to $this->accessDriver inside MetaSources

  • Loading branch information...
1 parent f38b3d5 commit d6d2462d24ede5b9e86e6d28771b51fb20e66282 @cdujeu cdujeu committed Jun 25, 2016
@@ -46,11 +46,10 @@
public function initMeta(ContextInterface $ctx, AbstractAccessDriver $accessDriver)
{
- $this->accessDriver = $accessDriver;
// Override options with parent META SOURCE options
// Could be refined ?
- if($this->accessDriver->repository->hasParent()){
- $parentRepo = RepositoryService::getRepositoryById($this->accessDriver->repository->getParentId());
+ if($ctx->getRepository()->hasParent()){
+ $parentRepo = RepositoryService::getRepositoryById($ctx->getRepository()->getParentId());
if($parentRepo != null){
$sources = $parentRepo->getContextOption($ctx, "META_SOURCES");
$qParent = $sources["meta.quota"];
@@ -90,7 +90,6 @@ public function init(ContextInterface $ctx, $options = [])
*/
public function initMeta(ContextInterface $ctx, \Pydio\Access\Core\AbstractAccessDriver $accessDriver)
{
- $this->accessDriver = $accessDriver;
if (!empty($this->metaFields) || $this->indexContent) {
$metaFields = $this->metaFields;
/** @var \DOMElement $el */
@@ -134,7 +134,6 @@ public function switchActions($actionName, $httpVars, $fileVars, ContextInterfac
if ($existingFeed == null) {
$existingFeed = array();
}
- $this->accessDriver = $ctx->getRepository()->getDriverInstance();
$mess = LocaleService::getMessages();
switch ($actionName) {
@@ -183,7 +182,7 @@ public function switchActions($actionName, $httpVars, $fileVars, ContextInterfac
$limit = isSet($httpVars["limit"]) ? intval($httpVars["limit"]) : 100;
$uniqNode->loadNodeInfo();
$data = $feedStore->findMetaObjectsByIndexPath(
- $this->accessDriver->repository->getId(),
+ $ctx->getRepositoryId(),
$uniqNode->getPath(),
$ctx->getUser()->getId(),
$ctx->getUser()->getGroupPath(),
@@ -38,18 +38,11 @@
class FilesystemMounter extends AbstractMetaSource
{
/**
- * @var Repository
- */
- protected $repository;
-
- /**
* @param ContextInterface $ctx
* @param AbstractAccessDriver $accessDriver
*/
public function beforeInitMeta(ContextInterface $ctx, AbstractAccessDriver $accessDriver)
{
- $this->accessDriver = $accessDriver;
- $this->repository = $ctx->getRepository();
if($this->isAlreadyMounted($ctx)) {
return;
}
@@ -63,7 +56,6 @@ public function beforeInitMeta(ContextInterface $ctx, AbstractAccessDriver $acce
public function initMeta(ContextInterface $ctx, AbstractAccessDriver $accessDriver)
{
parent::initMeta($ctx, $accessDriver);
- $this->repository = $this->accessDriver->repository;
}
/**
@@ -110,7 +102,7 @@ protected function getOption(ContextInterface $ctx, $name, $user="", $pass="", $
$opt = str_replace("AJXP_SERVER_UID", posix_getuid(), $opt);
$opt = str_replace("AJXP_SERVER_GID", posix_getgid(), $opt);
if (stristr($opt, "AJXP_REPOSITORY_PATH") !== false) {
- $repo = $this->repository;
+ $repo = $ctx->getRepository();
$path = $repo->getContextOption($ctx, "PATH");
$opt = str_replace("AJXP_REPOSITORY_PATH", $path, $opt);
}
@@ -150,7 +142,7 @@ public function mountFS(ContextInterface $ctx)
{
list($user, $password) = $this->getCredentials();
$this->logDebug("FSMounter::mountFS Should mount" . $user);
- $repo = $this->repository;
+ $repo = $ctx->getRepository();
if(isset($this->options["MOUNT_DEVIL"]) && !empty($this->options["MOUNT_DEVIL"]) && $this->options["MOUNT_DEVIL"]) {
$udevil = "udevil ";
@@ -177,7 +177,7 @@ public function recomputeQuotaUsage($oldNode = null, $newNode = null, $copy = fa
protected function storeUsage(ContextInterface $ctx, $quota)
{
$data = $this->getUserData($ctx);
- $repo = $this->accessDriver->repository->getId();
+ $repo = $ctx->getRepositoryId();
if(!isset($data["REPO_USAGES"])) $data["REPO_USAGES"] = array();
$data["REPO_USAGES"][$repo] = $quota;
$this->saveUserData($ctx, $data);
@@ -74,10 +74,10 @@ public function applyChangeLock(\Psr\Http\Message\ServerRequestInterface $reques
/** @var ContextInterface $ctx */
$ctx = $requestInterface->getAttribute("ctx");
- if ($this->accessDriver instanceof \Pydio\Access\Driver\StreamProvider\FS\DemoAccessDriver) {
+ if ($ctx->getRepository()->getDriverInstance() instanceof \Pydio\Access\Driver\StreamProvider\FS\DemoAccessDriver) {
throw new \Exception("Write actions are disabled in demo mode!");
}
- $repo = $this->accessDriver->repository;
+ $repo = $ctx->getRepository();
$user = $ctx->getUser();
if (!UsersService::usersEnabled() && $user!=null && !$user->canWrite($repo->getId())) {
throw new \Exception("You have no right on this action.");
@@ -61,18 +61,18 @@ public function init(ContextInterface $ctx, $options = [])
}
/**
+ * @param ContextInterface $ctx
* @param string $path
* @return bool
*/
- protected function excludeFromSync($path){
+ protected function excludeFromSync($ctx, $path){
$excludedExtensions = ["dlpart"];
- $ctx = AJXP_Node::contextFromUrl($path);
$ext = pathinfo($path, PATHINFO_EXTENSION);
if(!empty($ext) && in_array($ext, $excludedExtensions)){
return true;
}
try{
- $this->accessDriver->filterUserSelectionToHidden($ctx, [$path]);
+ $ctx->getRepository()->getDriverInstance()->filterUserSelectionToHidden($ctx, [$path]);
}catch(\Exception $e){
return true;
}
@@ -156,7 +156,7 @@ protected function indexIsSync(ContextInterface $ctx){
// Ignore dirs modified time
// if(is_dir($nodeUrl) && $mod_data["path"] != "/") continue;
if(!isSet($currentChildren[$f])){
- if($this->excludeFromSync($nodeUrl)){
+ if($this->excludeFromSync($ctx, $nodeUrl)){
$this->logDebug(__FUNCTION__, "Excluding item detected on storage: ".$nodeUrl);
continue;
}
@@ -167,7 +167,7 @@ protected function indexIsSync(ContextInterface $ctx){
}else {
if(is_dir($nodeUrl)) continue; // Make sure to not trigger a recursive indexation here.
if(filemtime($nodeUrl) > $currentChildren[$f]){
- if($this->excludeFromSync($nodeUrl)){
+ if($this->excludeFromSync($ctx, $nodeUrl)){
$this->logDebug(__FUNCTION__, "Excluding item changed on storage: ".$nodeUrl);
continue;
}
@@ -180,7 +180,7 @@ protected function indexIsSync(ContextInterface $ctx){
foreach($currentChildren as $cPath => $mtime){
$this->logDebug(__FUNCTION__, "Existing children ".$cPath);
if(!in_array($cPath, $files)){
- if($this->excludeFromSync($url."/".$cPath)){
+ if($this->excludeFromSync($ctx, $url."/".$cPath)){
$this->logDebug(__FUNCTION__, "Excluding item deleted on storage: ".$url."/".$cPath);
continue;
}
@@ -246,7 +246,7 @@ public function switchActions($actionName, $httpVars, $fileVars, \Pydio\Core\Mod
}
$filter = null;
$masks = [];
- $currentRepo = $this->accessDriver->repository;
+ $currentRepo = $contextInterface->getRepository();
Controller::applyHook("role.masks", [$contextInterface, &$masks, AJXP_Permission::READ]);
if(count($masks) == 1 && $masks[0] == "/"){
$masks = [];
@@ -86,7 +86,7 @@ public function initMeta(ContextInterface $ctx, AbstractAccessDriver $accessDriv
else $visibilities = explode(",", $this->options["meta_visibility"]);
$editButton = '';
$u = $ctx->getUser();
- if($u != null && $u->canWrite($this->accessDriver->repository->getId())){
+ if($u != null && $u->canWrite($ctx->getRepositoryId())){
$editButton = '<span class="icon-edit" data-ajxpAction="edit_user_meta" title="AJXP_MESSAGE[meta.user.1]"></span><span class="user_meta_change" style="display: none;" data-ajxpAction="edit_user_meta" title="AJXP_MESSAGE[meta.user.1]">AJXP_MESSAGE[457]</span>';
}
$cdataHead = '<div>
@@ -253,12 +253,12 @@ protected function getMetaDefinition()
*/
public function editMeta(\Psr\Http\Message\ServerRequestInterface &$requestInterface, \Psr\Http\Message\ResponseInterface &$responseInterface)
{
+ /** @var ContextInterface $ctx */
+ $ctx = $requestInterface->getAttribute("ctx");
$httpVars = $requestInterface->getParsedBody();
- if ($this->accessDriver instanceof \Pydio\Access\Driver\StreamProvider\FS\DemoAccessDriver) {
+ if ($ctx->getRepository()->getDriverInstance() instanceof \Pydio\Access\Driver\StreamProvider\FS\DemoAccessDriver) {
throw new \Exception("Write actions are disabled in demo mode!");
}
- /** @var ContextInterface $ctx */
- $ctx = $requestInterface->getAttribute("ctx");
$user = $ctx->getUser();
if (!UsersService::usersEnabled() && $user!=null && !$user->canWrite($ctx->getRepositoryId())) {
@@ -43,7 +43,7 @@ class S3MetaStore extends AbstractMetaSource implements IMetaStoreProvider
public function initMeta(ContextInterface $ctx, AbstractAccessDriver $accessDriver)
{
parent::initMeta($ctx, $accessDriver);
- $this->bucketName = $this->accessDriver->repository->getContextOption($ctx, "CONTAINER");
+ $this->bucketName = $ctx->getRepository()->getContextOption($ctx, "CONTAINER");
}
/**
@@ -68,10 +68,10 @@ protected function getUserId($node)
/**
* @return \aws\S3\S3Client
*/
- protected function getAwsService()
+ protected function getAwsService(ContextInterface $ctx)
{
- if(method_exists($this->accessDriver, "getS3Service")){
- return $this->accessDriver->getS3Service();
+ if(method_exists($ctx->getRepository()->getDriverInstance(), "getS3Service")){
+ return $ctx->getRepository()->getDriverInstance()->getS3Service();
}
return null;
}
@@ -106,7 +106,7 @@ private function updateNodeMetaPath($ajxpNode, $create = false){
*/
public function setMetadata($ajxpNode, $nameSpace, $metaData, $private = false, $scope=AJXP_METADATA_SCOPE_REPOSITORY)
{
- $aws = $this->getAwsService();
+ $aws = $this->getAwsService($ajxpNode->getContext());
if($aws == null) return;
$user = ($private?$this->getUserId($ajxpNode):AJXP_METADATA_SHAREDUSER);
$pathName = $this->updateNodeMetaPath($ajxpNode, true);
@@ -130,7 +130,7 @@ public function setMetadata($ajxpNode, $nameSpace, $metaData, $private = false,
*/
public function removeMetadata($ajxpNode, $nameSpace, $private = false, $scope=AJXP_METADATA_SCOPE_REPOSITORY)
{
- $aws = $this->getAwsService();
+ $aws = $this->getAwsService($ajxpNode->getContext());
if($aws == null) return;
$user = ($private?$this->getUserId($ajxpNode):AJXP_METADATA_SHAREDUSER);
$pathName = $this->updateNodeMetaPath($ajxpNode, false);
@@ -156,7 +156,7 @@ public function removeMetadata($ajxpNode, $nameSpace, $private = false, $scope=A
*/
public function retrieveMetadata($ajxpNode, $nameSpace, $private = false, $scope=AJXP_METADATA_SCOPE_REPOSITORY)
{
- $aws = $this->getAwsService();
+ $aws = $this->getAwsService($ajxpNode->getContext());
if($aws == null) return array();
if (isSet(self::$metaCache[$ajxpNode->getPath()])) {
@@ -216,7 +216,7 @@ private function getMetaKey($namespace, $scope, $user)
public function enrichNode(&$ajxpNode)
{
// Try both
- $aws = $this->getAwsService();
+ $aws = $this->getAwsService($ajxpNode->getContext());
if($aws == null) return;
if (isSet(self::$metaCache[$ajxpNode->getPath()])) {
@@ -286,9 +286,10 @@ protected function saveMetaFileData($ajxpNode, $scope, $userId)
$metaFile = $this->updateSecurityScope($metaFile, $ajxpNode->getContext());
}
$metFileNode = new AJXP_Node($metaFile);
+ $driver = $metFileNode->getDriver();
if($scope==AJXP_METADATA_SCOPE_REPOSITORY
- || (@is_file($metaFile) && call_user_func(array($this->accessDriver, "isWriteable"), $metFileNode))
- || call_user_func(array($this->accessDriver, "isWriteable"), $metFileNode->getParent()) ){
+ || (@is_file($metaFile) && call_user_func(array($driver, "isWriteable"), $metFileNode))
+ || call_user_func(array($driver, "isWriteable"), $metFileNode->getParent()) ){
if (is_array(self::$metaCache) && count(self::$metaCache)) {
if (!isset(self::$fullMetaCache[$metaFile])) {
self::$fullMetaCache[$metaFile] = array();

0 comments on commit d6d2462

Please sign in to comment.