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

Commit

Permalink
Introduce an AJXP_METADATA_ALLUSERS metadata users scope to gather me…
Browse files Browse the repository at this point in the history
…ta from all users. Used in eventForwarding for ShareCenter.
  • Loading branch information
cdujeu committed Feb 20, 2015
1 parent 1164429 commit 46e117b
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 34 deletions.
3 changes: 2 additions & 1 deletion core/src/plugins/action.share/class.ShareCenter.php
Expand Up @@ -581,7 +581,7 @@ private function findMirrorNodesInShares($node, $direction){
$result = array();
if($direction !== "UP"){
$upmetas = array();
$node->collectMetadataInParents("ajxp_shared", true, AJXP_METADATA_SCOPE_REPOSITORY, false, $upmetas);
$node->collectMetadataInParents("ajxp_shared", AJXP_METADATA_ALLUSERS, AJXP_METADATA_SCOPE_REPOSITORY, false, $upmetas);
foreach($upmetas as $metadata){
if (is_array($metadata) && !empty($metadata["shares"])) {
foreach($metadata["shares"] as $sId => $sData){
Expand All @@ -596,6 +596,7 @@ private function findMirrorNodesInShares($node, $direction){
$sharedPath = substr($node->getPath(), strlen($sharedNode->getPath()));
$sharedNodeUrl = $node->getScheme() . "://".$wsId.$sharedPath;
$result[$wsId] = array(new AJXP_Node($sharedNodeUrl), "DOWN");
$this->logDebug('MIRROR NODES', 'Found shared in parent - register node '.$sharedNodeUrl);
}
}
}
Expand Down
31 changes: 20 additions & 11 deletions core/src/plugins/core.metastore/interface.MetaStoreProvider.php
Expand Up @@ -21,12 +21,13 @@

defined('AJXP_EXEC') or die( 'Access not allowed');
define('AJXP_METADATA_SHAREDUSER', 'AJXP_METADATA_SHAREDUSER');
define('AJXP_METADATA_ALLUSERS', 'AJXP_METADATA_ALLUSERS');

define('AJXP_METADATA_SCOPE_GLOBAL', 1);
define('AJXP_METADATA_SCOPE_REPOSITORY', 2);
/**
* Simple metadata implementation, stored in hidden files inside the
* folders
* Metadata interface, must be implemented by Metastore plugins.
*
* @package AjaXplorer_Plugins
* @subpackage Core
*/
Expand All @@ -43,34 +44,42 @@ public function inherentMetaMove();

/**
* @abstract
* @param AJXP_Node $ajxpNode
* @param String $nameSpace
* @param array $metaData
* @param bool $private
* @param AJXP_Node $ajxpNode The node where to set metadata
* @param String $nameSpace The metadata namespace (generally depending on the plugin)
* @param array $metaData Metadata to store
* @param bool $private Either false (will store under a shared user name) or true (will store under the node user name).
* @param int $scope
* Either AJXP_METADATA_SCOPE_REPOSITORY (this metadata is available only inside the current repository)
* or AJXP_METADATA_SCOPE_GLOBAL (metadata available globally).
*/

public function setMetadata($ajxpNode, $nameSpace, $metaData, $private = false, $scope=AJXP_METADATA_SCOPE_REPOSITORY);
/**
*
* @abstract
* @param AJXP_Node $ajxpNode
* @param String $nameSpace
* @param bool $private
* @param AJXP_Node $ajxpNode The node to inspect
* @param String $nameSpace The metadata namespace (generally depending on the plugin)
* @param bool $private Either false (will store under a shared user name) or true (will store under the node user name).
* @param int $scope
* Either AJXP_METADATA_SCOPE_REPOSITORY (this metadata is available only inside the current repository)
* or AJXP_METADATA_SCOPE_GLOBAL (metadata available globally).
* @return Array Metadata or empty array.
*/
public function removeMetadata($ajxpNode, $nameSpace, $private = false, $scope=AJXP_METADATA_SCOPE_REPOSITORY);

/**
* @abstract
* @param AJXP_Node $ajxpNode
* @param String $nameSpace
* @param bool $private
* @param bool|String $private
* Either false (will store under a shared user name), true (will store under the node user name),
* or AJXP_METADATA_ALL_USERS (will retrieve and merge all metadata from all users).
* @param int $scope
*/
public function retrieveMetadata($ajxpNode, $nameSpace, $private = false, $scope=AJXP_METADATA_SCOPE_REPOSITORY);

/**
* @param AJXP_Node $ajxpNode
* @param AJXP_Node $ajxpNode Load all metadatas on this node, merging the global, shared and private ones.
* @return void
*/
public function enrichNode(&$ajxpNode);
Expand Down
25 changes: 19 additions & 6 deletions core/src/plugins/metastore.s3/class.s3MetaStore.php
Expand Up @@ -142,8 +142,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();
if($aws == null) return;
$user = ($private?$this->getUserId($ajxpNode):AJXP_METADATA_SHAREDUSER);
if($aws == null) return array();

if (isSet(self::$metaCache[$ajxpNode->getPath()])) {
$data = self::$metaCache[$ajxpNode->getPath()];
Expand All @@ -162,11 +161,25 @@ public function retrieveMetadata($ajxpNode, $nameSpace, $private = false, $scope
self::$metaCache[$ajxpNode->getPath()] = $metadata;
$data = self::$metaCache[$ajxpNode->getPath()];
}
$mKey = $this->getMetaKey($nameSpace,$scope,$user);
if (isSet($data[$mKey])) {
$arrMeta = unserialize(base64_decode($data[$mKey]));
if(is_array($arrMeta)) return $arrMeta;
if($private === AJXP_METADATA_ALLUSERS){
$startKey = $this->getMetaKey($nameSpace, $scope, "");
$arrMeta = array();
foreach($data as $k => $mData){
if(strpos($k, $startKey) === 0){
$decData = unserialize(base64_decode($mData));
if(is_array($decData)) $arrMeta = array_merge_recursive($arrMeta, $decData);
}
}
return $arrMeta;
}else{
$user = ($private?$this->getUserId($ajxpNode):AJXP_METADATA_SHAREDUSER);
$mKey = $this->getMetaKey($nameSpace,$scope,$user);
if (isSet($data[$mKey])) {
$arrMeta = unserialize(base64_decode($data[$mKey]));
if(is_array($arrMeta)) return $arrMeta;
}
}
return array();
}

private function getMetaKey($namespace, $scope, $user)
Expand Down
33 changes: 23 additions & 10 deletions core/src/plugins/metastore.serial/class.SerialMetaStore.php
Expand Up @@ -99,10 +99,17 @@ public function removeMetadata($ajxpNode, $nameSpace, $private = false, $scope=A

public function retrieveMetadata($ajxpNode, $nameSpace, $private = false, $scope=AJXP_METADATA_SCOPE_REPOSITORY)
{
if($private == AJXP_METADATA_ALLUSERS){
$userScope = AJXP_METADATA_ALLUSERS;
}else if($private === true){
$userScope = $this->getUserId($ajxpNode);
}else{
$userScope = AJXP_METADATA_SHAREDUSER;
}
$this->loadMetaFileData(
$ajxpNode,
$scope,
($private?$this->getUserId($ajxpNode):AJXP_METADATA_SHAREDUSER)
$userScope
);
if(!isSet(self::$metaCache[$nameSpace])) return array();
else return self::$metaCache[$nameSpace];
Expand Down Expand Up @@ -206,16 +213,22 @@ protected function loadMetaFileData($ajxpNode, $scope, $userId)
}
}
if (isSet(self::$fullMetaCache[$metaFile]) && is_array(self::$fullMetaCache[$metaFile])) {
if (isSet(self::$fullMetaCache[$metaFile][$fileKey][$userId])) {
self::$metaCache = self::$fullMetaCache[$metaFile][$fileKey][$userId];
} else {
if ($this->options["UPGRADE_FROM_METASERIAL"] == true && count(self::$fullMetaCache[$metaFile]) && !isSet(self::$fullMetaCache[$metaFile]["AJXP_METASTORE_UPGRADED"])) {
self::$fullMetaCache[$metaFile] = $this->upgradeDataFromMetaSerial(self::$fullMetaCache[$metaFile]);
if (isSet(self::$fullMetaCache[$metaFile][$fileKey][$userId])) {
self::$metaCache = self::$fullMetaCache[$metaFile][$fileKey][$userId];
if($userId == AJXP_METADATA_ALLUSERS && is_array(self::$fullMetaCache[$metaFile][$fileKey])){
foreach(self::$fullMetaCache[$metaFile][$fileKey] as $uId => $data){
self::$metaCache = array_merge_recursive(self::$metaCache, $data);
}
}else{
if (isSet(self::$fullMetaCache[$metaFile][$fileKey][$userId])) {
self::$metaCache = self::$fullMetaCache[$metaFile][$fileKey][$userId];
} else {
if ($this->options["UPGRADE_FROM_METASERIAL"] == true && count(self::$fullMetaCache[$metaFile]) && !isSet(self::$fullMetaCache[$metaFile]["AJXP_METASTORE_UPGRADED"])) {
self::$fullMetaCache[$metaFile] = $this->upgradeDataFromMetaSerial(self::$fullMetaCache[$metaFile]);
if (isSet(self::$fullMetaCache[$metaFile][$fileKey][$userId])) {
self::$metaCache = self::$fullMetaCache[$metaFile][$fileKey][$userId];
}
// Save upgraded version
file_put_contents($metaFile, serialize(self::$fullMetaCache[$metaFile]));
}
// Save upgraded version
file_put_contents($metaFile, serialize(self::$fullMetaCache[$metaFile]));
}
}
} else {
Expand Down
27 changes: 21 additions & 6 deletions core/src/plugins/metastore.xattr/class.xAttrMetaStore.php
Expand Up @@ -107,22 +107,37 @@ public function removeMetadata($ajxpNode, $nameSpace, $private = false, $scope=A
* @abstract
* @param AJXP_Node $ajxpNode
* @param String $nameSpace
* @param bool $private
* @param bool|String $private
* @param int $scope
* @return array()
*/
public function retrieveMetadata($ajxpNode, $nameSpace, $private = false, $scope=AJXP_METADATA_SCOPE_REPOSITORY)
{
$path = $ajxpNode->getRealFile();
if(!file_exists($path)) return array();
$key = $this->getMetaKey($nameSpace, $scope, $this->getUserId($private, $ajxpNode));
if (!xattr_supported($path)) {
//throw new Exception("Filesystem does not support Extended Attributes!");
return array();
}
$data = xattr_get($path, $key);
$data = unserialize(base64_decode($data));
if( empty($data) || !is_array($data)) return array();
return $data;
if($private == AJXP_METADATA_ALLUSERS){
$startKey = $this->getMetaKey($nameSpace, $scope, "");
$arrMeta = array();
$keyList = xattr_list($path);
foreach($keyList as $k){
if(strpos($k, $startKey) === 0){
$mData = xattr_get($path, $k);
$decData = unserialize(base64_decode($mData));
if(is_array($decData)) $arrMeta = array_merge_recursive($arrMeta, $decData);
}
}
return $arrMeta;
}else{
$key = $this->getMetaKey($nameSpace, $scope, $this->getUserId($private, $ajxpNode));
$data = xattr_get($path, $key);
$data = unserialize(base64_decode($data));
if( empty($data) || !is_array($data)) return array();
return $data;
}
}

/**
Expand Down

0 comments on commit 46e117b

Please sign in to comment.