diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f9eeb3c..956cabc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ alpha-4 - [node] copy,move and clone - Target paths automatically append basename if target is a node. - [query] Always show path next to resultset -- [node] `node:list` Enable listing nodes by UUID +- [node|shell] Most commands which accept a node path can also accept a UUID ### Bugs Fixes diff --git a/features/shell_path_change.feature b/features/shell_path_change.feature new file mode 100644 index 00000000..cf698066 --- /dev/null +++ b/features/shell_path_change.feature @@ -0,0 +1,26 @@ +Feature: Change the shells current working path + In order to change the current working path of the shell + As a user that is logged into the shell + I should be able to run a command which does that + + Background: + Given that I am logged in as "testuser" + And the "session_data.xml" fixtures are loaded + + Scenario: Change the current working path to root + Given the current node is "/tests_general_base" + And I execute the "shell:path:change /" command + Then the command should not fail + And the current node should be "/" + + Scenario: Change the current working path + Given the current node is "/" + And I execute the "shell:path:change /tests_general_base" command + Then the command should not fail + And the current node should be "/tests_general_base" + + Scenario: Change the current working path with a UUID + Given the current node is "/" + And I execute the "shell:path:change 842e61c0-09ab-42a9-87c0-308ccc90e6f4" command + Then the command should not fail + And the current node should be "/tests_general_base/idExample" diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodeCorrespondingCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodeCorrespondingCommand.php index f92a4d01..5b4e1d93 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodeCorrespondingCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodeCorrespondingCommand.php @@ -25,9 +25,9 @@ protected function configure() public function execute(InputInterface $input, OutputInterface $output) { $session = $this->getHelper('phpcr')->getSession(); - $path = $session->getAbsPath($input->getArgument('path')); + $path = $input->getArgument('path'); $workspaceName = $input->getArgument('workspaceName'); - $currentNode = $session->getNode($path); + $currentNode = $session->getNodeByPathOrIdentifier($path); $correspondingPath = $currentNode->getCorrespondingNodePath($workspaceName); $output->writeln($correspondingPath); } diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodeDefinitionCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodeDefinitionCommand.php index 0ccc34c0..f6265c4d 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodeDefinitionCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodeDefinitionCommand.php @@ -12,7 +12,7 @@ class NodeDefinitionCommand extends PhpcrShellCommand protected function configure() { $this->setName('node:definition'); - $this->setDescription('Show the CND Definition of current node'); + $this->setDescription('Show the CND Definition of specified node'); $this->addArgument('path', InputArgument::REQUIRED, 'Path of node'); $this->setHelp(<<getHelper('phpcr')->getSession(); - $path = $session->getAbsPath($input->getArgument('path')); - $currentNode = $session->getNode($path); + $path = $input->getArgument('path'); + $currentNode = $session->getNodeByPathOrIdentifier($path); $workspace = $session->getWorkspace(); $namespaceRegistry = $workspace->getNamespaceRegistry(); diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodeEditCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodeEditCommand.php new file mode 100644 index 00000000..16c13237 --- /dev/null +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodeEditCommand.php @@ -0,0 +1,44 @@ +setName('node:edit'); + $this->setDescription('Edit the given node in the EDITOR configured by the system'); + $this->addArgument('path', InputArgument::REQUIRED, 'Path of node'); + $this->setHelp(<<getHelper('phpcr')->getSession(); + $formatter = $this->getHelper('result_formatter'); + $path = $session->getAbsPath($input->getArgument('path')); + + $editor = $this->getHelper('editor'); + + $skipBinary = true; + $noRecurse = true; + + ob_start(); + $stream = fopen('php://output', 'w+', false); + $session->exportSystemView($path, $stream, $skipBinary, $noRecurse); + $out = ob_get_clean(); + fclose($stream); + $out = $formatter->formatXml($out); + + $in = $editor->fromString($out); + } +} + diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodeInfoCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodeInfoCommand.php index 4946c686..d8860908 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodeInfoCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodeInfoCommand.php @@ -23,9 +23,9 @@ protected function configure() public function execute(InputInterface $input, OutputInterface $output) { $session = $this->getHelper('phpcr')->getSession(); - $path = $session->getAbsPath($input->getArgument('path')); + $path = $input->getArgument('path'); $nodeHelper = $this->getHelper('node'); - $currentNode = $session->getNode($path); + $currentNode = $session->getNodeByPathOrIdentifier($path); $formatter = $this->getHelper('result_formatter'); $mixins = $currentNode->getMixinNodeTypes(); diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodeLifecycleFollowCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodeLifecycleFollowCommand.php index babad405..158567f0 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodeLifecycleFollowCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodeLifecycleFollowCommand.php @@ -35,8 +35,8 @@ protected function configure() public function execute(InputInterface $input, OutputInterface $output) { $session = $this->getHelper('phpcr')->getSession(); - $path = $session->getAbsPath($input->getArgument('path')); - $currentNode = $session->getNode($path); + $path = $input->getArgument('path'); + $currentNode = $session->getNodeByPathOrIdentifier($path); $transition = $input->getArgument('transition'); $currentNode->followLifecycleTransition($transition); } diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodeLifecycleListCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodeLifecycleListCommand.php index e88f4390..d9371127 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodeLifecycleListCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodeLifecycleListCommand.php @@ -26,8 +26,8 @@ protected function configure() public function execute(InputInterface $input, OutputInterface $output) { $session = $this->getHelper('phpcr')->getSession(); - $path = $session->getAbsPath($input->getArgument('path')); - $currentNode = $session->getNode($path); + $path = $input->getArgument('path'); + $currentNode = $session->getNodeByPathOrIdentifier($path); $transitions = $currentNode->getAllowedLifecycleTransitions(); foreach ($transitions as $transition) { diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodeListCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodeListCommand.php index 3f9eb4c9..1252e3a3 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodeListCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodeListCommand.php @@ -8,7 +8,6 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use PHPCR\PropertyType; -use PHPCR\Util\UUIDHelper; class NodeListCommand extends Command { @@ -55,15 +54,9 @@ public function execute(InputInterface $input, OutputInterface $output) $this->showTemplate = $input->getOption('template'); $session = $this->getHelper('phpcr')->getSession(); - $path = $input->getArgument('path'); - if (true === UUIDHelper::isUUID($path)) { - $currentNode = $session->getNodeByIdentifier($path); - } else { - $path = $session->getAbsPath($path); - $currentNode = $session->getNode($path); - } + $currentNode = $session->getNodeByPathOrIdentifier($path); if (!$this->showChildren && !$this->showProperties) { $this->showChildren = true; diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodeMixinAddCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodeMixinAddCommand.php index 642f1fe7..bcd2ccf3 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodeMixinAddCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodeMixinAddCommand.php @@ -44,9 +44,9 @@ protected function configure() public function execute(InputInterface $input, OutputInterface $output) { $session = $this->getHelper('phpcr')->getSession(); - $path = $session->getAbsPath($input->getArgument('path')); + $path = $input->getArgument('path'); $mixinName = $input->getArgument('mixinName'); - $currentNode = $session->getNode($path); + $currentNode = $session->getNodeByPathOrIdentifier($path); $currentNode->addMixin($mixinName); } } diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodeOrderBeforeCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodeOrderBeforeCommand.php index 772fb219..62649fb3 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodeOrderBeforeCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodeOrderBeforeCommand.php @@ -40,10 +40,10 @@ protected function configure() public function execute(InputInterface $input, OutputInterface $output) { $session = $this->getHelper('phpcr')->getSession(); - $path = $session->getAbsPath($input->getArgument('path')); + $path = $input->getArgument('path'); $srcChildRelPath = $input->getArgument('srcChildRelPath'); $destChildRelPath = $input->getArgument('destChildRelPath'); - $node = $session->getNode($path); + $node = $session->getNodeByPathOrIdentifier($path); $node->orderBefore($srcChildRelPath, $destChildRelPath); } } diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodeReferencesCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodeReferencesCommand.php index 517abe6e..265eb6df 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodeReferencesCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodeReferencesCommand.php @@ -40,8 +40,8 @@ protected function configure() public function execute(InputInterface $input, OutputInterface $output) { $session = $this->getHelper('phpcr')->getSession(); - $path = $session->getAbsPath($input->getArgument('path')); - $currentNode = $session->getNode($path); + $path = $input->getArgument('path'); + $currentNode = $session->getNodeByPathOrIdentifier($path); $name = $input->getArgument('name'); $references = array( diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodeRemoveCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodeRemoveCommand.php index f71ae15d..25e6ac19 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodeRemoveCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodeRemoveCommand.php @@ -23,13 +23,13 @@ protected function configure() public function execute(InputInterface $input, OutputInterface $output) { $session = $this->getHelper('phpcr')->getSession(); - $targetPath = $session->getAbsPath($input->getArgument('path')); + $targetPath = $input->getArgument('path'); $currentPath = $session->getCwd(); // verify that node exists by trying to get it.. - $targetNode = $session->getNode($targetPath); + $targetNode = $session->getNodeByPathOrIdentifier($targetPath); - if ($targetPath == '/') { + if ($targetNode->getPath() == '/') { throw new \InvalidArgumentException( 'You cannot delete the root node!' ); @@ -38,8 +38,7 @@ public function execute(InputInterface $input, OutputInterface $output) $session->removeItem($targetPath); // if we deleted the current path, switch back to the parent node - if ($currentPath == $targetPath) { - echo $currentPath . ' vs. ' . $targetPath; + if ($currentPath == $session->getAbsPath($targetPath)) { $session->chdir('..'); } } diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodeRenameCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodeRenameCommand.php index bf3f4ff8..3628b283 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodeRenameCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodeRenameCommand.php @@ -57,9 +57,9 @@ protected function configure() public function execute(InputInterface $input, OutputInterface $output) { $session = $this->getHelper('phpcr')->getSession(); - $path = $session->getAbsPath($input->getArgument('path')); + $path = $input->getArgument('path'); $newName = $input->getArgument('newName'); - $currentNode = $session->getNode($path); + $currentNode = $session->getNodeByPathOrIdentifier($path); $currentNode->rename($newName); } } diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodeSetPrimaryTypeCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodeSetPrimaryTypeCommand.php index c426fa0d..1eb1c222 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodeSetPrimaryTypeCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodeSetPrimaryTypeCommand.php @@ -31,10 +31,10 @@ protected function configure() public function execute(InputInterface $input, OutputInterface $output) { $session = $this->getHelper('phpcr')->getSession(); - $path = $session->getAbsPath($input->getArgument('path')); + $path = $input->getArgument('path'); $nodeTypeName = $input->getArgument('nodeTypeName'); - $currentNode = $session->getNode($path); + $currentNode = $session->getNodeByPathOrIdentifier($path); $currentNode->setPrimaryType($nodeTypeName); } } diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodeSharedRemoveCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodeSharedRemoveCommand.php index 8615bd20..e7add2a6 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodeSharedRemoveCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodeSharedRemoveCommand.php @@ -32,8 +32,8 @@ protected function configure() public function execute(InputInterface $input, OutputInterface $output) { $session = $this->getHelper('phpcr')->getSession(); - $path = $session->getAbsPath($input->getArgument('path')); - $currentNode = $session->getNode($path); + $path = $input->getArgument('path'); + $currentNode = $session->getNodeByPathOrIdentifier($path); $sharedSet = $currentNode->removeSharedSet(); } } diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodeSharedShowCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodeSharedShowCommand.php index e406fc24..db4e9874 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodeSharedShowCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodeSharedShowCommand.php @@ -31,8 +31,8 @@ protected function configure() public function execute(InputInterface $input, OutputInterface $output) { $session = $this->getHelper('phpcr')->getSession(); - $path = $session->getAbsPath($input->getArgument('path')); - $currentNode = $session->getNode($path); + $path = $input->getArgument('path'); + $currentNode = $session->getNodeByPathOrIdentifier($path); $sharedSet = $currentNode->getSharedSet(); foreach ($sharedSet as $sharedNode) { diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodeTreeCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodeTreeCommand.php index 2662d4e4..1281e5a6 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodeTreeCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodeTreeCommand.php @@ -42,8 +42,8 @@ public function execute(InputInterface $input, OutputInterface $output) $this->showChildren = $input->getOption('children'); $this->showProperties = $input->getOption('properties'); - $path = $session->getAbsPath($input->getArgument('path')); - $currentNode = $session->getNode($path); + $path = $input->getArgument('path'); + $currentNode = $session->getNodeByPathOrIdentifier($path); if (!$showChildren && !$showProperties) { $this->showChildren = true; diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodeUpdateCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodeUpdateCommand.php index b62982f8..ca84f609 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodeUpdateCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodeUpdateCommand.php @@ -37,9 +37,9 @@ protected function configure() public function execute(InputInterface $input, OutputInterface $output) { $session = $this->getHelper('phpcr')->getSession(); - $path = $session->getAbsPath($input->getArgument('path')); + $path = $input->getArgument('path'); $srcWorkspace = $input->getArgument('srcWorkspace'); - $currentNode = $session->getNode($path); + $currentNode = $session->getNodeByPathOrIdentifier($path); $currentNode->update($srcWorkspace); } } diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/VersionCheckinCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/VersionCheckinCommand.php index 8dc9994c..8fa4ef85 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/VersionCheckinCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/VersionCheckinCommand.php @@ -49,12 +49,12 @@ public function execute(InputInterface $input, OutputInterface $output) { $session = $this->getHelper('phpcr')->getSession(); $nodeHelper = $this->getHelper('node'); - $path = $session->getAbsPath($input->getArgument('path')); + $path = $input->getArgument('path'); $workspace = $session->getWorkspace(); $versionManager = $workspace->getVersionManager(); - $node = $session->getNode($path); + $node = $session->getNodeByPathOrIdentifier($path); $nodeHelper->assertNodeIsVersionable($node); $version = $versionManager->checkin($path); diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/VersionCheckoutCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/VersionCheckoutCommand.php index f844576b..050d315b 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/VersionCheckoutCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/VersionCheckoutCommand.php @@ -37,10 +37,10 @@ public function execute(InputInterface $input, OutputInterface $output) { $session = $this->getHelper('phpcr')->getSession(); $nodeHelper = $this->getHelper('node'); - $absPath = $session->getAbsPath($input->getArgument('path')); + $absPath = $input->getArgument('path'); $workspace = $session->getWorkspace(); - $node = $session->getNode($absPath); + $node = $session->getNodeByPathOrIdentifier($absPath); $nodeHelper->assertNodeIsVersionable($node); $versionManager = $workspace->getVersionManager(); diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/VersionCheckpointCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/VersionCheckpointCommand.php index bb3efacf..09123263 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/VersionCheckpointCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/VersionCheckpointCommand.php @@ -27,10 +27,10 @@ public function execute(InputInterface $input, OutputInterface $output) { $session = $this->getHelper('phpcr')->getSession(); $nodeHelper = $this->getHelper('node'); - $path = $session->getAbsPath($input->getArgument('path')); + $path = $input->getArgument('path'); $workspace = $session->getWorkspace(); - $node = $session->getNode($path); + $node = $session->getNodeByPathOrIdentifier($path); $nodeHelper->assertNodeIsVersionable($node); $versionManager = $workspace->getVersionManager(); $version = $versionManager->checkpoint($path); diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/VersionHistoryCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/VersionHistoryCommand.php index c02657a1..6622a06e 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/VersionHistoryCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/VersionHistoryCommand.php @@ -26,10 +26,10 @@ public function execute(InputInterface $input, OutputInterface $output) $nodeHelper = $this->getHelper('node'); $table = $this->getHelper('table')->create(); - $path = $session->getAbsPath($input->getArgument('path')); + $path = $input->getArgument('path'); $workspace = $session->getWorkspace(); - $node = $session->getNode($path); + $node = $session->getNodeByPathOrIdentifier($path); $nodeHelper->assertNodeIsVersionable($node); $versionManager = $workspace->getVersionManager(); $history = $versionManager->getVersionHistory($path); diff --git a/src/PHPCR/Shell/PhpcrSession.php b/src/PHPCR/Shell/PhpcrSession.php index ae1a2227..2e3f75e4 100644 --- a/src/PHPCR/Shell/PhpcrSession.php +++ b/src/PHPCR/Shell/PhpcrSession.php @@ -5,6 +5,7 @@ use PHPCR\SessionInterface; use PHPCR\CredentialsInterface; use PHPCR\Util\PathHelper; +use PHPCR\Util\UUIDHelper; use PHPCR\PathNotFoundException; class PhpcrSession implements SessionInterface @@ -67,22 +68,27 @@ public function chdir($path) { $cwd = $this->getCwd(); - // absolute path - if (substr($path, 0, 1) == '/') { - $newPath = $path; - } elseif ($path == '..') { - $newPath = dirname($cwd); + if (UUIDHelper::isUUID($path)) { + $node = $this->getNodeByIdentifier($path); + $newPath = $node->getPath(); } else { - if ($this->cwd == '/') { - $newPath = sprintf('/%s', $path); + // absolute path + if (substr($path, 0, 1) == '/') { + $newPath = $path; + } elseif ($path == '..') { + $newPath = dirname($cwd); } else { - $newPath = sprintf('%s/%s', $cwd, $path); + if ($this->cwd == '/') { + $newPath = sprintf('/%s', $path); + } else { + $newPath = sprintf('%s/%s', $cwd, $path); + } } - } - - // check that path is valid - $this->getNode($newPath); + // check that path is valid + $this->getNode($newPath); + } + $this->setCwd($newPath); } @@ -141,6 +147,31 @@ public function getAbsPaths($paths) return $newPaths; } + + /** + * If the given parameter looks like a UUID retrieve + * by Identifier, otherwise by path. + * + * @param string $pathOrId + * + * @return NodeInterface + * + * @throws PathNotFoundException if no accessible node is found at the specified path. + * @throws ItemNotFoundException if no node with the specified + * identifier exists or if this Session does not have read access to + * the node with the specified identifier. + */ + public function getNodeByPathOrIdentifier($pathOrId) + { + if (true === UUIDHelper::isUUID($pathOrId)) { + return $this->getNodeByIdentifier($pathOrId); + } + + $path = $this->getAbsPath($pathOrId); + return $this->getNode($pathOrId); + } + + public function getRepository() { return $this->session->getRepository();