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

Commit

Permalink
Fix typo's in elasticsearch plugin.
Browse files Browse the repository at this point in the history
Add startUpdatingMetadata / finishedUpdatingMetadata to avoid multiple calls of node.meta_change hook. Shall we introduce a deduplication of events when they are deferred?
  • Loading branch information
cdujeu committed Jun 16, 2016
1 parent 090f0c0 commit 7ff41a8
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 48 deletions.
6 changes: 5 additions & 1 deletion core/src/plugins/action.share/src/ShareCenter.php
Expand Up @@ -640,6 +640,7 @@ public function switchAction(ServerRequestInterface &$requestInterface, Response

$results = $this->shareNode($ctx, $ajxpNode, $httpVars, $isUpdate);
if(is_array($results) && $ajxpNode->hasMetaStore() && !$ajxpNode->isRoot()){
$ajxpNode->startUpdatingMetadata();
foreach($results as $shareObject){
if($shareObject instanceof \Pydio\OCS\Model\TargettedLink){
$hash = $shareObject->getHash();
Expand Down Expand Up @@ -669,7 +670,7 @@ public function switchAction(ServerRequestInterface &$requestInterface, Response
);
}
}

$ajxpNode->finishedUpdatingMetadata();
}
}

Expand Down Expand Up @@ -833,6 +834,7 @@ public function switchAction(ServerRequestInterface &$requestInterface, Response
}
if(count($shares)){
$res = true;
$ajxpNode->startUpdatingMetadata();
foreach($shares as $shareId => $share){
$t = isSet($share["type"]) ? $share["type"] : "file";
try{
Expand All @@ -841,12 +843,14 @@ public function switchAction(ServerRequestInterface &$requestInterface, Response
if($e->getMessage() == "repo-not-found"){
$result = true;
}else{
$ajxpNode->finishedUpdatingMetadata();
throw $e;
}
}
$this->getShareStore()->getMetaManager()->removeShareFromMeta($ajxpNode, $shareId);
$res = $result && $res;
}
$ajxpNode->finishedUpdatingMetadata();
if($res !== false){

$x = new SerializableResponseStream([new UserMessage($mess["share_center.216"])]);
Expand Down
Expand Up @@ -65,6 +65,7 @@ public function setNodeMeta($node, $meta, $private = true){
if(count($otherScopeMeta)){
$node->removeMetadata(AJXP_SHARED_META_NAMESPACE, $otherScope, AJXP_METADATA_SCOPE_REPOSITORY, true);
}
$node->ajxp_shared = "true";
$node->setMetadata(AJXP_SHARED_META_NAMESPACE, $meta, $private, AJXP_METADATA_SCOPE_REPOSITORY, true);
}

Expand Down Expand Up @@ -114,7 +115,6 @@ public function removeShareFromMeta($node, $shareId){
$this->clearNodeMeta($node);
}
}

}

/**
Expand Down
117 changes: 74 additions & 43 deletions core/src/plugins/core.access/src/Model/AJXP_Node.php
Expand Up @@ -53,15 +53,15 @@ class AJXP_Node implements \JsonSerializable, ContextProviderInterface
/**
* @var array The node metadata
*/
protected $_metadata = array();
protected $_metadata = [];
/**
* @var string Associated wrapper
*/
protected $_wrapperClassName;
/**
* @var array Parsed url fragments
*/
protected $urlParts = array();
protected $urlParts = [];
/**
* @var string A local representation of a real file, if possible
*/
Expand Down Expand Up @@ -95,21 +95,29 @@ class AJXP_Node implements \JsonSerializable, ContextProviderInterface
/**
* @var array
*/
private $_indexableMetaKeys = array();
private $_indexableMetaKeys = [];

/**
* @var bool
*/
private $_metadataBulkUpdate = false;

/**
* @param string $url URL of the node in the form ajxp.protocol://repository_id/path/to/node
* @param array $metadata Node metadata
*/
public function __construct($url, $metadata = array())
public function __construct($url, $metadata = [])
{
$this->setUrl($url);
$this->_metadata = $metadata;
}

/**
* @return array
*/
public function __sleep()
{
$t = array_diff(array_keys(get_class_vars("AJXP_Node")), array("_accessDriver", "_repository", "_metaStore"));
$t = array_diff(array_keys(get_class_vars("AJXP_Node")), ["_accessDriver", "_repository", "_metaStore"]);
return $t;
}

Expand Down Expand Up @@ -209,9 +217,29 @@ protected function getMetaStore()
return $this->_metaStore;
}

/**
* Check if there is currently a MetaStore provider set
* @return bool
*/
public function hasMetaStore()
{
return ($this->getMetaStore() != false);
return ($this->getMetaStore() !== false);
}

/**
* Start a session of set / remove Metadata calls without applying the node.meta_change hook
*/
public function startUpdatingMetadata(){
$this->_metadataBulkUpdate = true;
}

/**
* Finish updating the metadata and trigger the node.meta_change event
* @throws \Exception
*/
public function finishedUpdatingMetadata(){
$this->_metadataBulkUpdate = false;
Controller::applyHook("node.meta_change", [&$this]);
}

/**
Expand All @@ -223,15 +251,17 @@ public function hasMetaStore()
*/
public function setMetadata($nameSpace, $metaData, $private = false, $scope=AJXP_METADATA_SCOPE_REPOSITORY, $indexable = false)
{
$metaStore = $this->getMetaStore();
if ($metaStore !== false) {
$metaStore->setMetadata($this, $nameSpace, $metaData, $private, $scope);
//$this->mergeMetadata($metaData);
if ($indexable) {
if(!isSet($this->_indexableMetaKeys[$private ? "user":"shared"]))$this->_indexableMetaKeys[$private ? "user":"shared"] = array();
$this->_indexableMetaKeys[$private ? "user":"shared"][$nameSpace] = $nameSpace;
}
Controller::applyHook("node.meta_change", array(&$this));
if(!$this->hasMetaStore()){
return;
}
$this->getMetaStore()->setMetadata($this, $nameSpace, $metaData, $private, $scope);
//$this->mergeMetadata($metaData);
if ($indexable) {
if(!isSet($this->_indexableMetaKeys[$private ? "user":"shared"]))$this->_indexableMetaKeys[$private ? "user":"shared"] = [];
$this->_indexableMetaKeys[$private ? "user":"shared"][$nameSpace] = $nameSpace;
}
if(!$this->_metadataBulkUpdate){
Controller::applyHook("node.meta_change", [&$this]);
}
}

Expand All @@ -243,13 +273,15 @@ public function setMetadata($nameSpace, $metaData, $private = false, $scope=AJXP
*/
public function removeMetadata($nameSpace, $private = false, $scope=AJXP_METADATA_SCOPE_REPOSITORY, $indexable = false)
{
$metaStore = $this->getMetaStore();
if ($metaStore !== false) {
$metaStore->removeMetadata($this, $nameSpace, $private, $scope);
if ($indexable && isSet($this->_indexableMetaKeys[$private ? "user":"shared"]) && isset($this->_indexableMetaKeys[$private ? "user":"shared"][$nameSpace])) {
unset($this->_indexableMetaKeys[$private ? "user":"shared"][$nameSpace]);
}
Controller::applyHook("node.meta_change", array(&$this));
if(!$this->hasMetaStore()){
return;
}
$this->getMetaStore()->removeMetadata($this, $nameSpace, $private, $scope);
if ($indexable && isSet($this->_indexableMetaKeys[$private ? "user":"shared"]) && isset($this->_indexableMetaKeys[$private ? "user":"shared"][$nameSpace])) {
unset($this->_indexableMetaKeys[$private ? "user":"shared"][$nameSpace]);
}
if(!$this->_metadataBulkUpdate) {
Controller::applyHook("node.meta_change", [&$this]);
}
}

Expand All @@ -262,16 +294,15 @@ public function removeMetadata($nameSpace, $private = false, $scope=AJXP_METADAT
*/
public function retrieveMetadata($nameSpace, $private = false, $scope=AJXP_METADATA_SCOPE_REPOSITORY, $indexable = false)
{
$metaStore = $this->getMetaStore();
if ($metaStore !== false) {
$data = $metaStore->retrieveMetadata($this, $nameSpace, $private, $scope);
if (!empty($data) && $indexable) {
if(!isSet($this->_indexableMetaKeys[$private ? "user":"shared"]))$this->_indexableMetaKeys[$private ? "user":"shared"] = array();
$this->_indexableMetaKeys[$private ? "user":"shared"][$nameSpace] = $nameSpace;
}
return $data;
if(!$this->hasMetaStore()){
return [];
}
return array();
$data = $this->getMetaStore()->retrieveMetadata($this, $nameSpace, $private, $scope);
if (!empty($data) && $indexable) {
if(!isSet($this->_indexableMetaKeys[$private ? "user":"shared"]))$this->_indexableMetaKeys[$private ? "user":"shared"] = [];
$this->_indexableMetaKeys[$private ? "user":"shared"][$nameSpace] = $nameSpace;
}
return $data;
}

/**
Expand All @@ -286,7 +317,7 @@ public function retrieveMetadata($nameSpace, $private = false, $scope=AJXP_METAD
public function copyOrMoveMetadataFromNode($originalNode, $nameSpace, $operation="move", $private = false, $scope=AJXP_METADATA_SCOPE_REPOSITORY, $indexable = false){

if($this->getMetaStore() == false || $this->getMetaStore()->inherentMetaMove()){
return array();
return [];
}
$metaData = $originalNode->retrieveMetadata($nameSpace, $private, $scope, $indexable);
if(isSet($metaData) && !empty($metaData)){
Expand All @@ -296,7 +327,7 @@ public function copyOrMoveMetadataFromNode($originalNode, $nameSpace, $operation
}
return $metaData;
}
return array();
return [];

}

Expand Down Expand Up @@ -337,7 +368,7 @@ public function findMetadataInParent($nameSpace, $private = false, $scope=AJXP_M
* @param bool $indexable
* @param array $collect
*/
public function collectMetadataInParents($nameSpace, $private = false, $scope=AJXP_METADATA_SCOPE_REPOSITORY, $indexable = false, &$collect=array()){
public function collectMetadataInParents($nameSpace, $private = false, $scope=AJXP_METADATA_SCOPE_REPOSITORY, $indexable = false, &$collect= []){

$parentNode = $this->getParent();
if($parentNode != null){
Expand All @@ -358,11 +389,11 @@ public function collectMetadataInParents($nameSpace, $private = false, $scope=AJ
* @param bool $indexable
* @param array $collect
*/
public function collectMetadatasInParents($nameSpaces, $private = false, $scope=AJXP_METADATA_SCOPE_REPOSITORY, $indexable = false, &$collect=array()){
public function collectMetadatasInParents($nameSpaces, $private = false, $scope=AJXP_METADATA_SCOPE_REPOSITORY, $indexable = false, &$collect= []){

$parentNode = $this->getParent();
if($parentNode != null){
$nodeMeta = array();
$nodeMeta = [];
foreach($nameSpaces as $nameSpace){
$metadata = $parentNode->retrieveMetadata($nameSpace, $private, $scope,$indexable);
if($metadata != false){
Expand All @@ -379,7 +410,7 @@ public function collectMetadatasInParents($nameSpaces, $private = false, $scope=
}

public function collectRepositoryMetadatasInChildren($nameSpace, $userScope){
$result = array();
$result = [];
$metaStore = $this->getMetaStore();
if($metaStore !== false && method_exists($metaStore, "collectChildrenWithRepositoryMeta")){
$result = $metaStore->collectChildrenWithRepositoryMeta($this, $nameSpace, $userScope);
Expand Down Expand Up @@ -468,14 +499,14 @@ public function loadNodeInfo($forceRefresh = false, $contextNode = false, $detai
if(is_object($driver)) $driver->detectStreamWrapper(true, $this->getContext());
}
}
Controller::applyHook("node.info.start", array(&$this, $contextNode, $details, $forceRefresh));
Controller::applyHook("node.info.start", [&$this, $contextNode, $details, $forceRefresh]);
if($this->nodeInfoLoaded && !$forceRefresh){
Controller::applyHook("node.info.nocache", array(&$this, $contextNode, $details, $forceRefresh));
Controller::applyHook("node.info.nocache", [&$this, $contextNode, $details, $forceRefresh]);
return;
}
Controller::applyHook("node.info", array(&$this, $contextNode, $details, $forceRefresh));
Controller::applyHook("node.info.end", array(&$this, $contextNode, $details, $forceRefresh));
Controller::applyHook("node.info.nocache", array(&$this, $contextNode, $details, $forceRefresh));
Controller::applyHook("node.info", [&$this, $contextNode, $details, $forceRefresh]);
Controller::applyHook("node.info.end", [&$this, $contextNode, $details, $forceRefresh]);
Controller::applyHook("node.info.nocache", [&$this, $contextNode, $details, $forceRefresh]);
$this->nodeInfoLoaded = true;
$this->nodeInfoLevel = $details;
}
Expand Down Expand Up @@ -633,7 +664,7 @@ public function getSizeRecursive(){
return $this->_metadata["bytesize"];
}else{
$result = -1;
Controller::applyHook("node.size.recursive", array(&$this, &$result));
Controller::applyHook("node.size.recursive", [&$this, &$result]);
if($result == -1){
try{
return $this->getDriver()->directoryUsage($this);
Expand Down
Expand Up @@ -135,7 +135,6 @@ public function applyAction(\Psr\Http\Message\ServerRequestInterface $requestInt
$ctxUser = $ctx->getUser();

$messages = LocaleService::getMessages();
$repoId = $this->accessDriver->repository->getId();

$x = new \Pydio\Core\Http\Response\SerializableResponseStream();
$nodesList = new \Pydio\Access\Core\Model\NodesList();
Expand Down Expand Up @@ -323,7 +322,7 @@ public function applyAction(\Psr\Http\Message\ServerRequestInterface $requestInt
$tmpNode->loadNodeInfo();
}
if (!file_exists($tmpNode->getUrl())) {
$this->currentType->deleteById($hit->id);
$this->currentType->deleteById($hit->getId());
continue;
}
$tmpNode->search_score = sprintf("%0.2f", $hit->score);
Expand Down Expand Up @@ -414,7 +413,7 @@ public function updateNodeIndex($oldNode, $newNode = null, $copy = false, $recur
$oldDocId = $this->getIndexedDocumentId($oldNode);
if ($oldDocId != null) {
$this->currentType->deleteById($oldDocId);
$childrenHits = $this->getIndexedChildrenDocuments($newNode);
$childrenHits = $this->getIndexedChildrenDocuments($oldNode);

if ($childrenHits != null) {
$childrenHits = $childrenHits->getResults();
Expand Down

0 comments on commit 7ff41a8

Please sign in to comment.