Skip to content

Commit 5ab30c9

Browse files
committed
Enable node:edit by UUID
1 parent 9515c6f commit 5ab30c9

File tree

2 files changed

+59
-13
lines changed

2 files changed

+59
-13
lines changed

features/phpcr_node_edit.feature

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,32 @@ Feature: Edit a node
142142
"""
143143
And I execute the "node:edit cms/products/product2 --no-interaction --type=nt:resource" command
144144
Then the command should fail
145+
146+
Scenario: Edit a node by UUID
147+
Given I have an editor which produces the following:
148+
""""
149+
title:
150+
type: String
151+
value: 'Article 1'
152+
'jcr:uuid':
153+
type: String
154+
value: 66666fc6-1abf-4708-bfcc-e49511754b40
155+
tag:
156+
type: String
157+
value: [Planes]
158+
'jcr:primaryType':
159+
type: Name
160+
value: 'nt:unstructured'
161+
'jcr:mixinTypes':
162+
type: Name
163+
value: ['mix:referenceable']
164+
tags:
165+
type: String
166+
value: [Planes, Trains, Automobiles]
167+
foobar: FOOOOOOO
168+
"""
169+
And I execute the "node:edit 66666fc6-1abf-4708-bfcc-e49511754b40 --no-interaction" command
170+
Then the command should not fail
171+
And I save the session
172+
Then the command should not fail
173+
And the property "/cms/articles/article1/foobar" should have type "String" and value "FOOOOOOO"

src/PHPCR/Shell/Console/Command/Phpcr/NodeEditCommand.php

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPCR\Shell\Serializer\YamlEncoder;
1616
use Symfony\Component\Console\Input\InputOption;
1717
use PHPCR\PathNotFoundException;
18+
use PHPCR\Util\UUIDHelper;
1819

1920
class NodeEditCommand extends Command
2021
{
@@ -25,29 +26,45 @@ protected function configure()
2526
$this->addArgument('path', InputArgument::REQUIRED, 'Path of node');
2627
$this->addOption('type', null, InputOption::VALUE_REQUIRED, 'Optional type to use when creating new nodes', 'nt:unstructured');
2728
$this->setHelp(<<<HERE
28-
Edit the given node
29+
Edit or create a node at the given path using the default editor as defined by the EDITOR environment variable.
30+
31+
When you invoke the command a temporary file in YAML format will be created on the filesystem. This file will
32+
contain all the properties of the nodes (including system properties). You can change, add or delete properties in
33+
the text editor and save, where upon the changes will be registered in the session and you will be returned to the
34+
shell.
35+
36+
When creating a new node you can also optionally specify the type of node which should be created.
2937
HERE
3038
);
3139
}
3240

3341
public function execute(InputInterface $input, OutputInterface $output)
3442
{
3543
$session = $this->getHelper('phpcr')->getSession();
36-
$path = $session->getAbsPath($input->getArgument('path'));
37-
$parentPath = $this->getHelper('path')->getParentPath($path);
38-
$nodeName = $this->getHelper('path')->getNodeName($path);
39-
$type = $input->getOption('type');
40-
41-
$editor = $this->getHelper('editor');
42-
$dialog = $this->getHelper('dialog');
44+
$path = $input->getArgument('path');
45+
46+
if (UUIDHelper::isUUID($path)) {
47+
// If the node is a UUID, then just get it
48+
$node = $session->getNodeByIdentifier($path);
49+
} else {
50+
$path = $session->getAbsPath($path);
51+
// Otherwise it is a path which may or may not exist
52+
$parentPath = $this->getHelper('path')->getParentPath($path);
53+
$nodeName = $this->getHelper('path')->getNodeName($path);
54+
$type = $input->getOption('type');
4355

44-
try {
45-
$node = $session->getNode($path);
46-
} catch (PathNotFoundException $e) {
47-
$parentNode = $session->getNode($parentPath);
48-
$node = $parentNode->addNode($nodeName, $type);
56+
try {
57+
// if it exists, then great
58+
$node = $session->getNodeByPathOrIdentifier($path);
59+
} catch (PathNotFoundException $e) {
60+
// if it doesn't exist then we create it
61+
$parentNode = $session->getNode($parentPath);
62+
$node = $parentNode->addNode($nodeName, $type);
63+
}
4964
}
5065

66+
$editor = $this->getHelper('editor');
67+
$dialog = $this->getHelper('dialog');
5168

5269
$skipBinary = true;
5370
$noRecurse = true;

0 commit comments

Comments
 (0)