Permalink
Browse files

Fix event on change error when cross-repository copy.

  • Loading branch information...
1 parent d799c8f commit c726b7c6a30b36fae4ee20197628d6a68064d902 @cdujeu cdujeu committed Jun 20, 2016
@@ -109,29 +109,51 @@ public function persistNotificationToAlerts(AJXP_Notification &$notification)
}
+ /**
+ * @param AJXP_Node|null $oldNode
+ * @param AJXP_Node|null $newNode
+ * @param bool $copy
+ * @param string $targetNotif
+ * @throws Exception
+ */
public function persistChangeHookToFeed(AJXP_Node $oldNode = null, AJXP_Node $newNode = null, $copy = false, $targetNotif = "new")
{
if(!$this->eventStore) return;
- $n = ($oldNode == null ? $newNode : $oldNode);
- $ctx = $n->getContext();
- if(!$ctx->hasUser() || !$ctx->hasRepository()){
- return;
+ $nodes = [];
+ if($oldNode !== null && $newNode !== null && $oldNode->getRepositoryId() !== $newNode->getRepositoryId()){
+ $nodes[] = $oldNode;
+ $nodes[] = $newNode;
+ }else{
+ $nodes[] = ($oldNode === null ? $newNode : $oldNode);
+ }
+ /** @var AJXP_Node $n */
+ foreach($nodes as $n){
+ $ctx = $n->getContext();
+ if(!$ctx->hasUser() || !$ctx->hasRepository()){
+ return;
+ }
+ $repository = $n->getContext()->getRepository();
+ $userObject = $n->getContext()->getUser();
+ $repositoryScope = $repository->securityScope();
+ $repositoryScope = ($repositoryScope !== false ? $repositoryScope : "ALL");
+ $repositoryOwner = $repository->hasOwner() ? $repository->getOwner() : null;
+ Controller::applyHook("msg.instant",array(
+ $ctx,
+ "<reload_user_feed/>",
+ $userObject->getId()
+ ));
+ $this->eventStore->persistEvent("node.change", func_get_args(), $repository->getId(), $repositoryScope, $repositoryOwner, $userObject->getId(), $userObject->getGroupPath());
}
- $repository = $n->getContext()->getRepository();
- $userObject = $n->getContext()->getUser();
- $repositoryScope = $repository->securityScope();
- $repositoryScope = ($repositoryScope !== false ? $repositoryScope : "ALL");
- $repositoryOwner = $repository->hasOwner() ? $repository->getOwner() : null;
- Controller::applyHook("msg.instant",array(
- $ctx,
- "<reload_user_feed/>",
- $userObject->getId()
- ));
- $this->eventStore->persistEvent("node.change", func_get_args(), $repository->getId(), $repositoryScope, $repositoryOwner, $userObject->getId(), $userObject->getGroupPath());
}
+
+ /**
+ * @param ContextInterface $ctx
+ * @param $data
+ * @throws \Pydio\Core\Exception\PydioException
+ */
public function loadRepositoryInfo(ContextInterface $ctx, &$data){
$body = [
'format' => 'array',
@@ -78,8 +78,11 @@ public function persistEvent($hookName, $data, $repositoryId, $repositoryScope,
}
try {
$node = null;
- if(is_object($data[1]) && $data[1] instanceof \Pydio\Access\Core\Model\AJXP_Node) $node = $data[1];
- else if(is_object($data[0]) && $data[0] instanceof \Pydio\Access\Core\Model\AJXP_Node) $node = $data[0];
+ if(is_object($data[1]) && $data[1] instanceof \Pydio\Access\Core\Model\AJXP_Node && $data[1]->getContext()->getRepositoryId() === $repositoryId) {
+ $node = $data[1];
+ } else if(is_object($data[0]) && $data[0] instanceof \Pydio\Access\Core\Model\AJXP_Node && $data[0]->getContext()->getRepositoryId() === $repositoryId) {
+ $node = $data[0];
+ }
dibi::query("INSERT INTO [ajxp_feed] ([edate],[etype],[htype],[user_id],[repository_id],[repository_owner],[user_group],[repository_scope],[content],[index_path]) VALUES (%i,%s,%s,%s,%s,%s,%s,%s,%bin,%s)",
time(),
"event",

0 comments on commit c726b7c

Please sign in to comment.