15
15
use PHPCR \Shell \Serializer \YamlEncoder ;
16
16
use Symfony \Component \Console \Input \InputOption ;
17
17
use PHPCR \PathNotFoundException ;
18
+ use PHPCR \Util \UUIDHelper ;
18
19
19
20
class NodeEditCommand extends Command
20
21
{
@@ -25,29 +26,45 @@ protected function configure()
25
26
$ this ->addArgument ('path ' , InputArgument::REQUIRED , 'Path of node ' );
26
27
$ this ->addOption ('type ' , null , InputOption::VALUE_REQUIRED , 'Optional type to use when creating new nodes ' , 'nt:unstructured ' );
27
28
$ 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.
29
37
HERE
30
38
);
31
39
}
32
40
33
41
public function execute (InputInterface $ input , OutputInterface $ output )
34
42
{
35
43
$ 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 ' );
43
55
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
+ }
49
64
}
50
65
66
+ $ editor = $ this ->getHelper ('editor ' );
67
+ $ dialog = $ this ->getHelper ('dialog ' );
51
68
52
69
$ skipBinary = true ;
53
70
$ noRecurse = true ;
0 commit comments