Permalink
Browse files

Add node_repository_id to metadata when sending NodesDiff, to avoid e…

…vents on the wrong repo.

Remove legacy calls to XMLWriter::nodesDiff() and use message object instead.
  • Loading branch information...
1 parent fedc7fb commit 3e8328d0414e0e823baed5b5676a1ddbb073d234 @cdujeu cdujeu committed Sep 29, 2016
@@ -239,7 +239,7 @@ public static function renderAjxpNode($ajxpNode, $close = true, $print = true)
$ajxpNode->getPath(),
$ajxpNode->getLabel(),
$ajxpNode->isLeaf(),
- $ajxpNode->metadata,
+ $ajxpNode->getNodeInfoMeta(),
$close,
$print);
}
@@ -321,57 +321,6 @@ public static function reloadDataNode($nodePath="", $pendingSelection="", $print
return XMLWriter::write("<reload_instruction object=\"data\" node=\"$nodePath\" file=\"$pendingSelection\"/>", $print);
}
-
- /**
- * Send a <reload> XML instruction for refreshing the list
- * @static
- * @param $diffNodes
- * @param bool $print
- * @return string
- */
- public static function writeNodesDiff($diffNodes, $print = false)
- {
- /**
- * @var $ajxpNode \Pydio\Access\Core\Model\AJXP_Node
- */
- $mess = LocaleService::getMessages();
- $buffer = "<nodes_diff>";
- if (isSet($diffNodes["REMOVE"]) && count($diffNodes["REMOVE"])) {
- $buffer .= "<remove>";
- foreach ($diffNodes["REMOVE"] as $nodePath) {
- $nodePath = StringHelper::xmlEntities($nodePath, true);
- $buffer .= "<tree filename=\"$nodePath\" ajxp_im_time=\"".time()."\"/>";
- }
- $buffer .= "</remove>";
- }
- if (isSet($diffNodes["ADD"]) && count($diffNodes["ADD"])) {
- $buffer .= "<add>";
- foreach ($diffNodes["ADD"] as $ajxpNode) {
- $ajxpNode->loadNodeInfo(false, false, "all");
- if (!empty($ajxpNode->metaData["mimestring_id"]) && array_key_exists($ajxpNode->metaData["mimestring_id"], $mess)) {
- $ajxpNode->mergeMetadata(array("mimestring" => $mess[$ajxpNode->metaData["mimestring_id"]]));
- }
- $buffer .= self::renderAjxpNode($ajxpNode, true, false);
- }
- $buffer .= "</add>";
- }
- if (isSet($diffNodes["UPDATE"]) && count($diffNodes["UPDATE"])) {
- $buffer .= "<update>";
- foreach ($diffNodes["UPDATE"] as $originalPath => $ajxpNode) {
- $ajxpNode->loadNodeInfo(false, false, "all");
- if (!empty($ajxpNode->metaData["mimestring_id"]) && array_key_exists($ajxpNode->metaData["mimestring_id"], $mess)) {
- $ajxpNode->mergeMetadata(array("mimestring" => $mess[$ajxpNode->metaData["mimestring_id"]]));
- }
- $ajxpNode->original_path = $originalPath;
- $buffer .= self::renderAjxpNode($ajxpNode, true, false);
- }
- $buffer .= "</update>";
- }
- $buffer .= "</nodes_diff>";
- return XMLWriter::write($buffer, $print);
- }
-
-
/**
* Send a <reload> XML instruction for refreshing the repositories list
* @static
@@ -28,6 +28,7 @@
use Pydio\Access\Core\AbstractAccessDriver;
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\Filter\ContentFilter;
+use Pydio\Access\Core\Model\NodesDiff;
use Pydio\Access\Core\Model\NodesList;
use Pydio\Access\Core\Model\Repository;
use Pydio\Access\Core\Model\UserSelection;
@@ -751,7 +752,9 @@ public function switchAction(ServerRequestInterface &$requestInterface, Response
*/
if($shareScope == "public"){
$ajxpNode->loadNodeInfo();
- $content = XMLWriter::writeNodesDiff(["UPDATE" => array($ajxpNode->getPath() => $ajxpNode)]);
+ $diff = new NodesDiff();
+ $diff->update($ajxpNode);
+ $content = $diff->toXML();
Controller::applyHook("msg.instant", array($ajxpNode->getContext(), $content, null, null, [$ajxpNode->getPath()]));
}
@@ -930,7 +933,9 @@ public function switchAction(ServerRequestInterface &$requestInterface, Response
if(isSet($httpVars["share_scope"]) && $httpVars["share_scope"] == "public"){
$ajxpNode->loadNodeInfo();
- $content = XMLWriter::writeNodesDiff(["UPDATE" => [$ajxpNode->getPath() => $ajxpNode]]);
+ $diff = new NodesDiff();
+ $diff->update($ajxpNode);
+ $content = $diff->toXML();
Controller::applyHook("msg.instant", array($ajxpNode->getContext(), $content, null, null, [$ajxpNode->getPath()]));
}
@@ -113,6 +113,8 @@ protected function forceLoadNodeInfo(&$ajxpNode){
if (!empty($ajxpNode->metaData["mimestring_id"]) && array_key_exists($ajxpNode->metaData["mimestring_id"], $mess)) {
$ajxpNode->mergeMetadata(array("mimestring" => $mess[$ajxpNode->metaData["mimestring_id"]]));
}
+ // Add Repository to the metadata
+ $ajxpNode->mergeMetadata(array("node_repository_id" => $ajxpNode->getRepositoryId()));
}
/**
@@ -26,6 +26,7 @@
use Psr\Http\Message\ServerRequestInterface;
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\Filter\AJXP_Permission;
+use Pydio\Access\Core\Model\NodesDiff;
use Pydio\Core\Controller\Controller;
use Pydio\Core\Exception\AuthRequiredException;
use Pydio\Core\Exception\PydioException;
@@ -168,28 +169,29 @@ public function publishNodeChange($origNode = null, $newNode = null, $copy = fal
$content = "";$targetUserId=null; $nodePaths = array();
$update = false;
$ctx = null;
+ $diff = new NodesDiff();
if ($newNode != null) {
$ctx = $newNode->getContext();
//$targetUserId = $newNode->getUserId();
$targetUserId = null;
$nodePaths[] = $newNode->getPath();
$update = false;
- $data = array();
if ($origNode != null && !$copy) {
$update = true;
- $data[$origNode->getPath()] = $newNode;
+ $diff->update($newNode, $origNode->getPath());
} else {
- $data[] = $newNode;
+ $diff->add($newNode);
}
- $content = XMLWriter::writeNodesDiff(array(($update?"UPDATE":"ADD") => $data));
+ $content = $diff->toXML();
}
if ($origNode != null && ! $update && !$copy) {
$ctx = $origNode->getContext();
//$targetUserId = $origNode->getUserId();
$targetUserId = null;
$nodePaths[] = $origNode->getPath();
- $content = XMLWriter::writeNodesDiff(array("REMOVE" => array($origNode->getPath())));
+ $diff->remove([$origNode->getPath()]);
+ $content = $diff->toXML();
}
if (!empty($content) && !empty($ctx)) {
@@ -456,7 +456,7 @@ class PydioApi{
} else if(childs[i].nodeName == 'nodes_diff') {
var dm = this._pydioObject.getContextHolder();
if(dm.getAjxpNodeProvider().parseAjxpNodesDiffs){
- dm.getAjxpNodeProvider().parseAjxpNodesDiffs(childs[i], dm, !window.currentLightBox);
+ dm.getAjxpNodeProvider().parseAjxpNodesDiffs(childs[i], dm, this._pydioObject.user.activeRepository, !window.currentLightBox);
}
}
else if(childs[i].tagName == "logging_result")
@@ -261,28 +261,37 @@ class RemoteNodeProvider{
}
}
- parseAjxpNodesDiffs(xmlElement, targetDataModel, setContextChildrenSelected=false){
+ parseAjxpNodesDiffs(xmlElement, targetDataModel, targetRepositoryId, setContextChildrenSelected=false){
let removes = XMLUtils.XPathSelectNodes(xmlElement, "remove/tree");
let adds = XMLUtils.XPathSelectNodes(xmlElement, "add/tree");
let updates = XMLUtils.XPathSelectNodes(xmlElement, "update/tree");
let notifyServerChange = [];
if(removes && removes.length){
removes.forEach(function(r){
var p = r.getAttribute("filename");
+ if(r.getAttribute("node_repository_id") && r.getAttribute("node_repository_id") !== targetRepositoryId){
+ return;
+ }
var imTime = parseInt(r.getAttribute("ajxp_im_time"));
targetDataModel.removeNodeByPath(p, imTime);
notifyServerChange.push(p);
});
}
if(adds && adds.length && targetDataModel.getAjxpNodeProvider().parseAjxpNode){
adds.forEach(function(tree){
+ if(tree.getAttribute("node_repository_id") && tree.getAttribute("node_repository_id") !== targetRepositoryId){
+ return;
+ }
var newNode = targetDataModel.getAjxpNodeProvider().parseAjxpNode(tree);
targetDataModel.addNode(newNode, setContextChildrenSelected);
notifyServerChange.push(newNode.getPath());
});
}
if(updates && updates.length && targetDataModel.getAjxpNodeProvider().parseAjxpNode){
updates.forEach(function(tree){
+ if(tree.getAttribute("node_repository_id") && tree.getAttribute("node_repository_id") !== targetRepositoryId){
+ return;
+ }
var newNode = targetDataModel.getAjxpNodeProvider().parseAjxpNode(tree);
let original = newNode.getMetadata().get("original_path");
targetDataModel.updateNode(newNode, setContextChildrenSelected);
@@ -21,6 +21,7 @@
namespace Pydio\Uploader\Processor;
use Pydio\Access\Core\Model\AJXP_Node;
+use Pydio\Access\Core\Model\NodesDiff;
use Pydio\Access\Core\Model\UserSelection;
use Pydio\Core\Controller\Controller;
use Pydio\Core\Exception\AuthRequiredException;
@@ -197,6 +198,13 @@ public function postProcess(\Psr\Http\Message\ServerRequestInterface &$request,
// Ignore
return;
}
+ $nodesDiff = new NodesDiff();
+ if(isSet($result["CREATED_NODE"])){
+ $nodesDiff->add($result["CREATED_NODE"]);
+ }
+ if(isSet($result["UPDATED_NODE"])){
+ $nodesDiff->update($result["UPDATED_NODE"]);
+ }
if (isSet($httpVars["simple_uploader"])) {
$response = $response->withHeader("Content-type", "text/html; charset=UTF-8");
@@ -207,9 +215,7 @@ public function postProcess(\Psr\Http\Message\ServerRequestInterface &$request,
} else {
print("\n if(parent.pydio.getController().multi_selector) parent.pydio.getController().multi_selector.submitNext();");
if (isSet($result["CREATED_NODE"]) || isSet($result["UPDATED_NODE"])) {
- $s = '<tree>';
- $s .= XMLWriter::writeNodesDiff(array((isSet($result["UPDATED_NODE"])?"UPDATE":"ADD")=> array($result[(isSet($result["UPDATED_NODE"])?"UPDATED":"CREATED")."_NODE"])), false);
- $s.= '</tree>';
+ $s = '<tree>' . $nodesDiff->toXML() . '</tree>';
$response->getBody()->write("\n var resultString = '".str_replace("'", "\'", $s)."'; var resultXML = parent.parseXml(resultString);");
$response->getBody()->write("\n parent.PydioApi.getClient().parseXmlMessage(resultXML);");
}
@@ -222,12 +228,12 @@ public function postProcess(\Psr\Http\Message\ServerRequestInterface &$request,
$response->getBody()->write($message);
} else {
- $nodesDiff = "";
+ $nodesDiffXML = "";
if (isSet($result["CREATED_NODE"]) || isSet($result["UPDATED_NODE"])) {
- $nodesDiff = XMLWriter::writeNodesDiff(array((isSet($result["UPDATED_NODE"])?"UPDATE":"ADD") => array($result[(isSet($result["UPDATED_NODE"])?"UPDATED":"CREATED")."_NODE"])), false);
+ $nodesDiffXML = $nodesDiff->toXML();
}
$response = $response->withHeader("Content-type", "text/xml; charset=UTF-8");
- $response->getBody()->write(XMLWriter::wrapDocument($nodesDiff));
+ $response->getBody()->write(XMLWriter::wrapDocument($nodesDiffXML));
/* for further implementation */
if (!isSet($result["PREVENT_NOTIF"])) {

0 comments on commit 3e8328d

Please sign in to comment.