/** * @param AJXP_Node $baseNode * @param bool $delete * @param string $oldPath * @param string $newPath * @param string|null $parentRepositoryPath * @return int Number of nodes modified in different repositories */ public function moveSharesFromMetaRecursive($baseNode, $delete = false, $oldPath, $newPath, $parentRepositoryPath = null) { $modifiedDifferentNodes = 0; // Find shares in children try { $result = $this->getMetaManager()->collectSharesIncludingChildren($baseNode); } catch (Exception $e) { // Error while loading node, ignore return $modifiedDifferentNodes; } $basePath = $baseNode->getPath(); foreach ($result as $relativePath => $metadata) { if ($relativePath == "/") { $relativePath = ""; } $modifiedDifferentNodes++; $changeOldNode = new AJXP_Node("pydio://" . $baseNode->getRepositoryId() . $oldPath . $relativePath); foreach ($metadata as $ownerId => $meta) { if (!isset($meta["shares"])) { continue; } $changeOldNode->setUser($ownerId); /// do something $changeNewNode = null; if (!$delete) { //$newPath = preg_replace('#^'.preg_quote($oldPath, '#').'#', $newPath, $path); $changeNewNode = new AJXP_Node("pydio://" . $baseNode->getRepositoryId() . $newPath . $relativePath); $changeNewNode->setUser($ownerId); } $collectedRepositories = array(); list($privateShares, $publicShares) = $this->moveSharesFromMeta($meta["shares"], $delete ? "delete" : "move", $changeOldNode, $changeNewNode, $collectedRepositories, $parentRepositoryPath); if ($basePath == "/") { // Just update target node! $changeMetaNode = new AJXP_Node("pydio://" . $baseNode->getRepositoryId() . $relativePath); $changeMetaNode->setUser($ownerId); $this->getMetaManager()->clearNodeMeta($changeMetaNode); if (count($privateShares)) { $this->getMetaManager()->setNodeMeta($changeMetaNode, array("shares" => $privateShares), true); } if (count($publicShares)) { $this->getMetaManager()->setNodeMeta($changeMetaNode, array("shares" => $privateShares), false); } } else { $this->getMetaManager()->clearNodeMeta($changeOldNode); if (!$delete) { if (count($privateShares)) { $this->getMetaManager()->setNodeMeta($changeNewNode, array("shares" => $privateShares), true); } if (count($publicShares)) { $this->getMetaManager()->setNodeMeta($changeNewNode, array("shares" => $privateShares), false); } } } foreach ($collectedRepositories as $sharedRepoId => $parentRepositoryPath) { $modifiedDifferentNodes += $this->moveSharesFromMetaRecursive(new AJXP_Node("pydio://" . $sharedRepoId . "/"), $delete, $changeOldNode->getPath(), $changeNewNode->getPath(), $parentRepositoryPath); } } } return $modifiedDifferentNodes; }
/** * @param AJXP_Node $node * @param String|null $direction "UP", "DOWN" * @return array() */ private function findMirrorNodesInShares($node, $direction) { $result = array(); if ($direction !== "UP") { $upmetas = array(); $this->getShareStore()->getMetaManager()->collectSharesInParent($node, $upmetas); foreach ($upmetas as $metadata) { if (is_array($metadata) && !empty($metadata["shares"])) { foreach ($metadata["shares"] as $sId => $sData) { $type = $sData["type"]; if ($type == "file") { continue; } $wsId = $sId; if ($type == "minisite") { $minisiteData = $this->getShareStore()->loadShare($sId); if (empty($minisiteData) || !isset($minisiteData["REPOSITORY"])) { continue; } $wsId = $minisiteData["REPOSITORY"]; } else { if ($type == "ocs_remote") { continue; } } $sharedNode = $metadata["SOURCE_NODE"]; $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); } } } } if ($direction !== "DOWN") { if ($node->getRepository()->hasParent()) { $parentRepoId = $node->getRepository()->getParentId(); $parentRepository = ConfService::getRepositoryById($parentRepoId); if (!empty($parentRepository) && !$parentRepository->isTemplate) { $currentRoot = $node->getRepository()->getOption("PATH"); $owner = $node->getRepository()->getOwner(); $resolveUser = null; if ($owner != null) { $resolveUser = ConfService::getConfStorageImpl()->createUserObject($owner); } $parentRoot = $parentRepository->getOption("PATH", false, $resolveUser); $relative = substr($currentRoot, strlen($parentRoot)); $relative = SystemTextEncoding::toStorageEncoding($relative); $parentNodeURL = $node->getScheme() . "://" . $parentRepoId . $relative . $node->getPath(); $this->logDebug("action.share", "Should trigger on " . $parentNodeURL); $parentNode = new AJXP_Node($parentNodeURL); if ($owner != null) { $parentNode->setUser($owner); } $result[$parentRepoId] = array($parentNode, "UP"); } } } return $result; }