From 5ab30c97ae929afc5cf7c0e601860bdfcef127c2 Mon Sep 17 00:00:00 2001 From: dantleech Date: Thu, 21 Aug 2014 22:55:46 +0200 Subject: [PATCH] Enable node:edit by UUID --- features/phpcr_node_edit.feature | 29 +++++++++++++ .../Console/Command/Phpcr/NodeEditCommand.php | 43 +++++++++++++------ 2 files changed, 59 insertions(+), 13 deletions(-) diff --git a/features/phpcr_node_edit.feature b/features/phpcr_node_edit.feature index f3b94ec9..6821193f 100644 --- a/features/phpcr_node_edit.feature +++ b/features/phpcr_node_edit.feature @@ -142,3 +142,32 @@ Feature: Edit a node """ And I execute the "node:edit cms/products/product2 --no-interaction --type=nt:resource" command Then the command should fail + + Scenario: Edit a node by UUID + Given I have an editor which produces the following: + """" + title: + type: String + value: 'Article 1' + 'jcr:uuid': + type: String + value: 66666fc6-1abf-4708-bfcc-e49511754b40 + tag: + type: String + value: [Planes] + 'jcr:primaryType': + type: Name + value: 'nt:unstructured' + 'jcr:mixinTypes': + type: Name + value: ['mix:referenceable'] + tags: + type: String + value: [Planes, Trains, Automobiles] + foobar: FOOOOOOO + """ + And I execute the "node:edit 66666fc6-1abf-4708-bfcc-e49511754b40 --no-interaction" command + Then the command should not fail + And I save the session + Then the command should not fail + And the property "/cms/articles/article1/foobar" should have type "String" and value "FOOOOOOO" diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodeEditCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodeEditCommand.php index cda8971e..a435060e 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodeEditCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodeEditCommand.php @@ -15,6 +15,7 @@ use PHPCR\Shell\Serializer\YamlEncoder; use Symfony\Component\Console\Input\InputOption; use PHPCR\PathNotFoundException; +use PHPCR\Util\UUIDHelper; class NodeEditCommand extends Command { @@ -25,7 +26,14 @@ protected function configure() $this->addArgument('path', InputArgument::REQUIRED, 'Path of node'); $this->addOption('type', null, InputOption::VALUE_REQUIRED, 'Optional type to use when creating new nodes', 'nt:unstructured'); $this->setHelp(<<getHelper('phpcr')->getSession(); - $path = $session->getAbsPath($input->getArgument('path')); - $parentPath = $this->getHelper('path')->getParentPath($path); - $nodeName = $this->getHelper('path')->getNodeName($path); - $type = $input->getOption('type'); - - $editor = $this->getHelper('editor'); - $dialog = $this->getHelper('dialog'); + $path = $input->getArgument('path'); + + if (UUIDHelper::isUUID($path)) { + // If the node is a UUID, then just get it + $node = $session->getNodeByIdentifier($path); + } else { + $path = $session->getAbsPath($path); + // Otherwise it is a path which may or may not exist + $parentPath = $this->getHelper('path')->getParentPath($path); + $nodeName = $this->getHelper('path')->getNodeName($path); + $type = $input->getOption('type'); - try { - $node = $session->getNode($path); - } catch (PathNotFoundException $e) { - $parentNode = $session->getNode($parentPath); - $node = $parentNode->addNode($nodeName, $type); + try { + // if it exists, then great + $node = $session->getNodeByPathOrIdentifier($path); + } catch (PathNotFoundException $e) { + // if it doesn't exist then we create it + $parentNode = $session->getNode($parentPath); + $node = $parentNode->addNode($nodeName, $type); + } } + $editor = $this->getHelper('editor'); + $dialog = $this->getHelper('dialog'); $skipBinary = true; $noRecurse = true;