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

Commit 46e117b

Browse files
committed
Introduce an AJXP_METADATA_ALLUSERS metadata users scope to gather meta from all users. Used in eventForwarding for ShareCenter.
1 parent 1164429 commit 46e117b

File tree

5 files changed

+85
-34
lines changed

5 files changed

+85
-34
lines changed

core/src/plugins/action.share/class.ShareCenter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ private function findMirrorNodesInShares($node, $direction){
581581
$result = array();
582582
if($direction !== "UP"){
583583
$upmetas = array();
584-
$node->collectMetadataInParents("ajxp_shared", true, AJXP_METADATA_SCOPE_REPOSITORY, false, $upmetas);
584+
$node->collectMetadataInParents("ajxp_shared", AJXP_METADATA_ALLUSERS, AJXP_METADATA_SCOPE_REPOSITORY, false, $upmetas);
585585
foreach($upmetas as $metadata){
586586
if (is_array($metadata) && !empty($metadata["shares"])) {
587587
foreach($metadata["shares"] as $sId => $sData){
@@ -596,6 +596,7 @@ private function findMirrorNodesInShares($node, $direction){
596596
$sharedPath = substr($node->getPath(), strlen($sharedNode->getPath()));
597597
$sharedNodeUrl = $node->getScheme() . "://".$wsId.$sharedPath;
598598
$result[$wsId] = array(new AJXP_Node($sharedNodeUrl), "DOWN");
599+
$this->logDebug('MIRROR NODES', 'Found shared in parent - register node '.$sharedNodeUrl);
599600
}
600601
}
601602
}

core/src/plugins/core.metastore/interface.MetaStoreProvider.php

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121

2222
defined('AJXP_EXEC') or die( 'Access not allowed');
2323
define('AJXP_METADATA_SHAREDUSER', 'AJXP_METADATA_SHAREDUSER');
24+
define('AJXP_METADATA_ALLUSERS', 'AJXP_METADATA_ALLUSERS');
2425

2526
define('AJXP_METADATA_SCOPE_GLOBAL', 1);
2627
define('AJXP_METADATA_SCOPE_REPOSITORY', 2);
2728
/**
28-
* Simple metadata implementation, stored in hidden files inside the
29-
* folders
29+
* Metadata interface, must be implemented by Metastore plugins.
30+
*
3031
* @package AjaXplorer_Plugins
3132
* @subpackage Core
3233
*/
@@ -43,34 +44,42 @@ public function inherentMetaMove();
4344

4445
/**
4546
* @abstract
46-
* @param AJXP_Node $ajxpNode
47-
* @param String $nameSpace
48-
* @param array $metaData
49-
* @param bool $private
47+
* @param AJXP_Node $ajxpNode The node where to set metadata
48+
* @param String $nameSpace The metadata namespace (generally depending on the plugin)
49+
* @param array $metaData Metadata to store
50+
* @param bool $private Either false (will store under a shared user name) or true (will store under the node user name).
5051
* @param int $scope
52+
* Either AJXP_METADATA_SCOPE_REPOSITORY (this metadata is available only inside the current repository)
53+
* or AJXP_METADATA_SCOPE_GLOBAL (metadata available globally).
5154
*/
5255

5356
public function setMetadata($ajxpNode, $nameSpace, $metaData, $private = false, $scope=AJXP_METADATA_SCOPE_REPOSITORY);
5457
/**
58+
*
5559
* @abstract
56-
* @param AJXP_Node $ajxpNode
57-
* @param String $nameSpace
58-
* @param bool $private
60+
* @param AJXP_Node $ajxpNode The node to inspect
61+
* @param String $nameSpace The metadata namespace (generally depending on the plugin)
62+
* @param bool $private Either false (will store under a shared user name) or true (will store under the node user name).
5963
* @param int $scope
64+
* Either AJXP_METADATA_SCOPE_REPOSITORY (this metadata is available only inside the current repository)
65+
* or AJXP_METADATA_SCOPE_GLOBAL (metadata available globally).
66+
* @return Array Metadata or empty array.
6067
*/
6168
public function removeMetadata($ajxpNode, $nameSpace, $private = false, $scope=AJXP_METADATA_SCOPE_REPOSITORY);
6269

6370
/**
6471
* @abstract
6572
* @param AJXP_Node $ajxpNode
6673
* @param String $nameSpace
67-
* @param bool $private
74+
* @param bool|String $private
75+
* Either false (will store under a shared user name), true (will store under the node user name),
76+
* or AJXP_METADATA_ALL_USERS (will retrieve and merge all metadata from all users).
6877
* @param int $scope
6978
*/
7079
public function retrieveMetadata($ajxpNode, $nameSpace, $private = false, $scope=AJXP_METADATA_SCOPE_REPOSITORY);
7180

7281
/**
73-
* @param AJXP_Node $ajxpNode
82+
* @param AJXP_Node $ajxpNode Load all metadatas on this node, merging the global, shared and private ones.
7483
* @return void
7584
*/
7685
public function enrichNode(&$ajxpNode);

core/src/plugins/metastore.s3/class.s3MetaStore.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ public function removeMetadata($ajxpNode, $nameSpace, $private = false, $scope=A
142142
public function retrieveMetadata($ajxpNode, $nameSpace, $private = false, $scope=AJXP_METADATA_SCOPE_REPOSITORY)
143143
{
144144
$aws = $this->getAwsService();
145-
if($aws == null) return;
146-
$user = ($private?$this->getUserId($ajxpNode):AJXP_METADATA_SHAREDUSER);
145+
if($aws == null) return array();
147146

148147
if (isSet(self::$metaCache[$ajxpNode->getPath()])) {
149148
$data = self::$metaCache[$ajxpNode->getPath()];
@@ -162,11 +161,25 @@ public function retrieveMetadata($ajxpNode, $nameSpace, $private = false, $scope
162161
self::$metaCache[$ajxpNode->getPath()] = $metadata;
163162
$data = self::$metaCache[$ajxpNode->getPath()];
164163
}
165-
$mKey = $this->getMetaKey($nameSpace,$scope,$user);
166-
if (isSet($data[$mKey])) {
167-
$arrMeta = unserialize(base64_decode($data[$mKey]));
168-
if(is_array($arrMeta)) return $arrMeta;
164+
if($private === AJXP_METADATA_ALLUSERS){
165+
$startKey = $this->getMetaKey($nameSpace, $scope, "");
166+
$arrMeta = array();
167+
foreach($data as $k => $mData){
168+
if(strpos($k, $startKey) === 0){
169+
$decData = unserialize(base64_decode($mData));
170+
if(is_array($decData)) $arrMeta = array_merge_recursive($arrMeta, $decData);
171+
}
172+
}
173+
return $arrMeta;
174+
}else{
175+
$user = ($private?$this->getUserId($ajxpNode):AJXP_METADATA_SHAREDUSER);
176+
$mKey = $this->getMetaKey($nameSpace,$scope,$user);
177+
if (isSet($data[$mKey])) {
178+
$arrMeta = unserialize(base64_decode($data[$mKey]));
179+
if(is_array($arrMeta)) return $arrMeta;
180+
}
169181
}
182+
return array();
170183
}
171184

172185
private function getMetaKey($namespace, $scope, $user)

core/src/plugins/metastore.serial/class.SerialMetaStore.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,17 @@ public function removeMetadata($ajxpNode, $nameSpace, $private = false, $scope=A
9999

100100
public function retrieveMetadata($ajxpNode, $nameSpace, $private = false, $scope=AJXP_METADATA_SCOPE_REPOSITORY)
101101
{
102+
if($private == AJXP_METADATA_ALLUSERS){
103+
$userScope = AJXP_METADATA_ALLUSERS;
104+
}else if($private === true){
105+
$userScope = $this->getUserId($ajxpNode);
106+
}else{
107+
$userScope = AJXP_METADATA_SHAREDUSER;
108+
}
102109
$this->loadMetaFileData(
103110
$ajxpNode,
104111
$scope,
105-
($private?$this->getUserId($ajxpNode):AJXP_METADATA_SHAREDUSER)
112+
$userScope
106113
);
107114
if(!isSet(self::$metaCache[$nameSpace])) return array();
108115
else return self::$metaCache[$nameSpace];
@@ -206,16 +213,22 @@ protected function loadMetaFileData($ajxpNode, $scope, $userId)
206213
}
207214
}
208215
if (isSet(self::$fullMetaCache[$metaFile]) && is_array(self::$fullMetaCache[$metaFile])) {
209-
if (isSet(self::$fullMetaCache[$metaFile][$fileKey][$userId])) {
210-
self::$metaCache = self::$fullMetaCache[$metaFile][$fileKey][$userId];
211-
} else {
212-
if ($this->options["UPGRADE_FROM_METASERIAL"] == true && count(self::$fullMetaCache[$metaFile]) && !isSet(self::$fullMetaCache[$metaFile]["AJXP_METASTORE_UPGRADED"])) {
213-
self::$fullMetaCache[$metaFile] = $this->upgradeDataFromMetaSerial(self::$fullMetaCache[$metaFile]);
214-
if (isSet(self::$fullMetaCache[$metaFile][$fileKey][$userId])) {
215-
self::$metaCache = self::$fullMetaCache[$metaFile][$fileKey][$userId];
216+
if($userId == AJXP_METADATA_ALLUSERS && is_array(self::$fullMetaCache[$metaFile][$fileKey])){
217+
foreach(self::$fullMetaCache[$metaFile][$fileKey] as $uId => $data){
218+
self::$metaCache = array_merge_recursive(self::$metaCache, $data);
219+
}
220+
}else{
221+
if (isSet(self::$fullMetaCache[$metaFile][$fileKey][$userId])) {
222+
self::$metaCache = self::$fullMetaCache[$metaFile][$fileKey][$userId];
223+
} else {
224+
if ($this->options["UPGRADE_FROM_METASERIAL"] == true && count(self::$fullMetaCache[$metaFile]) && !isSet(self::$fullMetaCache[$metaFile]["AJXP_METASTORE_UPGRADED"])) {
225+
self::$fullMetaCache[$metaFile] = $this->upgradeDataFromMetaSerial(self::$fullMetaCache[$metaFile]);
226+
if (isSet(self::$fullMetaCache[$metaFile][$fileKey][$userId])) {
227+
self::$metaCache = self::$fullMetaCache[$metaFile][$fileKey][$userId];
228+
}
229+
// Save upgraded version
230+
file_put_contents($metaFile, serialize(self::$fullMetaCache[$metaFile]));
216231
}
217-
// Save upgraded version
218-
file_put_contents($metaFile, serialize(self::$fullMetaCache[$metaFile]));
219232
}
220233
}
221234
} else {

core/src/plugins/metastore.xattr/class.xAttrMetaStore.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,37 @@ public function removeMetadata($ajxpNode, $nameSpace, $private = false, $scope=A
107107
* @abstract
108108
* @param AJXP_Node $ajxpNode
109109
* @param String $nameSpace
110-
* @param bool $private
110+
* @param bool|String $private
111111
* @param int $scope
112+
* @return array()
112113
*/
113114
public function retrieveMetadata($ajxpNode, $nameSpace, $private = false, $scope=AJXP_METADATA_SCOPE_REPOSITORY)
114115
{
115116
$path = $ajxpNode->getRealFile();
116117
if(!file_exists($path)) return array();
117-
$key = $this->getMetaKey($nameSpace, $scope, $this->getUserId($private, $ajxpNode));
118118
if (!xattr_supported($path)) {
119119
//throw new Exception("Filesystem does not support Extended Attributes!");
120120
return array();
121121
}
122-
$data = xattr_get($path, $key);
123-
$data = unserialize(base64_decode($data));
124-
if( empty($data) || !is_array($data)) return array();
125-
return $data;
122+
if($private == AJXP_METADATA_ALLUSERS){
123+
$startKey = $this->getMetaKey($nameSpace, $scope, "");
124+
$arrMeta = array();
125+
$keyList = xattr_list($path);
126+
foreach($keyList as $k){
127+
if(strpos($k, $startKey) === 0){
128+
$mData = xattr_get($path, $k);
129+
$decData = unserialize(base64_decode($mData));
130+
if(is_array($decData)) $arrMeta = array_merge_recursive($arrMeta, $decData);
131+
}
132+
}
133+
return $arrMeta;
134+
}else{
135+
$key = $this->getMetaKey($nameSpace, $scope, $this->getUserId($private, $ajxpNode));
136+
$data = xattr_get($path, $key);
137+
$data = unserialize(base64_decode($data));
138+
if( empty($data) || !is_array($data)) return array();
139+
return $data;
140+
}
126141
}
127142

128143
/**

0 commit comments

Comments
 (0)