Skip to content

Enable node:edit by UUID #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 21, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions features/phpcr_node_edit.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
43 changes: 30 additions & 13 deletions src/PHPCR/Shell/Console/Command/Phpcr/NodeEditCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -25,29 +26,45 @@ 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(<<<HERE
Edit the given node
Edit or create a node at the given path using the default editor as defined by the EDITOR environment variable.

When you invoke the command a temporary file in YAML format will be created on the filesystem. This file will
contain all the properties of the nodes (including system properties). You can change, add or delete properties in
the text editor and save, where upon the changes will be registered in the session and you will be returned to the
shell.

When creating a new node you can also optionally specify the type of node which should be created.
HERE
);
}

public function execute(InputInterface $input, OutputInterface $output)
{
$session = $this->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;
Expand Down