1515use PHPCR \Shell \Serializer \YamlEncoder ;
1616use Symfony \Component \Console \Input \InputOption ;
1717use PHPCR \PathNotFoundException ;
18+ use PHPCR \Util \UUIDHelper ;
1819
1920class 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.
2937HERE
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