diff --git a/composer.json b/composer.json index 86b30f88..d7436b77 100644 --- a/composer.json +++ b/composer.json @@ -8,8 +8,11 @@ "jackalope/jackalope": "dev-master", "phpcr/phpcr": "dev-master", "phpcr/phpcr-utils": "dev-master", + "dantleech/phpcr-nodetype-serializer": "dev-master", "symfony/finder": "~2.0" }, + "minimum-stability": "dev", + "prefer-stable": true, "require-dev": { "mockery/mockery": "0.9", "symfony/process": "2.3.*", diff --git a/features/phpcr_node_type_show.feature b/features/phpcr_node_type_show.feature index 865df9e7..bcc03a17 100644 --- a/features/phpcr_node_type_show.feature +++ b/features/phpcr_node_type_show.feature @@ -12,15 +12,8 @@ Feature: Show a node type Then the command should not fail And I should see the following: """ -[nt:unstructured] > nt:base - orderable query - - * - multiple jcr.operator.equal.to', 'jcr.operator.not.equal.to', 'jcr.operator.greater.than', 'jcr.operator.greater.than.or.equal.to', 'jcr.operator.less.than', 'jcr.operator.less.than.or.equal.to', 'jcr.operator.like - - * - jcr.operator.equal.to', 'jcr.operator.not.equal.to', 'jcr.operator.greater.than', 'jcr.operator.greater.than.or.equal.to', 'jcr.operator.less.than', 'jcr.operator.less.than.or.equal.to', 'jcr.operator.like - + * (nt:base) - = nt:unstructured - VERSION sns +name: 'nt:unstructured' +declared_supertypes: """ Scenario: Execute the note-type show command diff --git a/features/shell_connect.feature b/features/shell_connect.feature new file mode 100644 index 00000000..6e0877d1 --- /dev/null +++ b/features/shell_connect.feature @@ -0,0 +1,9 @@ +Feature: Launch a new shell session + In order to administer a PHPCR repository + As a user + I need to be able to launch the PHPCRSH + + Scenario: Connect + Given I execute the "shell:config:reload" command + Then the command should not fail + diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodeTypeEditCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodeTypeEditCommand.php index 0ad27ccf..fd4c2711 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodeTypeEditCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodeTypeEditCommand.php @@ -6,9 +6,9 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; -use PHPCR\Util\CND\Writer\CndWriter; use PHPCR\NodeType\NoSuchNodeTypeException; -use PHPCR\Util\CND\Parser\CndParser; +use PHPCR\Util\NodeType\Serializer\YAMLSerializer; +use PHPCR\Util\NodeType\Serializer\YAMLDeserializer; class NodeTypeEditCommand extends Command { @@ -40,10 +40,10 @@ public function execute(InputInterface $input, OutputInterface $output) $namespaceRegistry = $workspace->getNamespaceRegistry(); $nodeTypeManager = $workspace->getNodeTypeManager(); + $serializer = new YAMLSerializer(); + try { $nodeType = $nodeTypeManager->getNodeType($nodeTypeName); - $cndWriter = new CndWriter($namespaceRegistry); - $out = $cndWriter->writeString(array($nodeType)); $message = null; } catch (NoSuchNodeTypeException $e) { $parts = explode(':', $nodeTypeName); @@ -55,24 +55,31 @@ public function execute(InputInterface $input, OutputInterface $output) } list($namespace, $name) = $parts; $uri = $session->getNamespaceURI($namespace); + $nodeType = $nodeTypeManager->createNodeTypeTemplate(); + $propertyTemplate = $nodeTypeManager->createPropertyDefinitionTemplate(); + $propertyTemplate->setName($namespace . ':change-me'); + $childTemplate = $nodeTypeManager->createNodeDefinitionTemplate(); + $childTemplate->setName($namespace . ':change-me'); - // so we will create one .. - $out = << -[$namespace:$name] > nt:unstructured + $nodeType->setName($nodeTypeName); + $nodeType->getNodeDefinitionTemplates()->append($childTemplate); + $nodeType->getPropertyDefinitionTemplates()->append($propertyTemplate); -EOT - ; + // so we will create one .. $message = <<serialize($nodeType); + $valid = false; $prefix = '# '; do { - $res = $editor->fromStringWithMessage($out, $message); + $res = $editor->fromStringWithMessage($out, $message, $prefix, '.yml'); if (empty($res)) { $output->writeln('Editor emptied the CND file, doing nothing. Use node-type:delete to remove node types.'); @@ -81,12 +88,9 @@ public function execute(InputInterface $input, OutputInterface $output) } try { - $cndParser = new CndParser($nodeTypeManager); - $namespacesAndNodeTypes = $cndParser->parseString($res); - - foreach ($namespacesAndNodeTypes['nodeTypes'] as $nodeType) { - $nodeTypeManager->registerNodeType($nodeType, true); - } + $serializer = new YAMLDeserializer($session); + $nodeType = $serializer->deserialize($res); + $nodeTypeManager->registerNodeType($nodeType, true); $valid = true; } catch (\Exception $e) { $output->writeln(''.$e->getMessage().''); diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodeTypeShowCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodeTypeShowCommand.php index 9fe7141b..76e576fe 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodeTypeShowCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodeTypeShowCommand.php @@ -6,18 +6,18 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; -use PHPCR\Util\CND\Writer\CndWriter; use PHPCR\NodeType\NoSuchNodeTypeException; +use PHPCR\Util\NodeType\Serializer\YAMLSerializer; class NodeTypeShowCommand extends Command { protected function configure() { $this->setName('node-type:show'); - $this->setDescription('Show the CND of a node type'); + $this->setDescription('Show the node definition of a given node type'); $this->addArgument('nodeTypeName', null, InputArgument::REQUIRED, 'The name of the node type to show'); $this->setHelp(<<writeString(array($nodeType)); + $cndWriter = new YAMLSerializer(); + $out = $cndWriter->serialize($nodeType); $output->writeln(sprintf('%s', $out)); } } diff --git a/src/PHPCR/Shell/Console/Helper/EditorHelper.php b/src/PHPCR/Shell/Console/Helper/EditorHelper.php index f36913a1..c403e421 100644 --- a/src/PHPCR/Shell/Console/Helper/EditorHelper.php +++ b/src/PHPCR/Shell/Console/Helper/EditorHelper.php @@ -17,10 +17,11 @@ class EditorHelper extends Helper * file containing the given string value. * * @param string $string + * @param string $extension Optional extension for filetype hinting (e.g. .yml) * * @return string */ - public function fromString($string) + public function fromString($string, $extension = null) { $fs = new Filesystem(); $dir = sys_get_temp_dir().DIRECTORY_SEPARATOR.'phpcr-shell'; @@ -30,6 +31,11 @@ public function fromString($string) } $tmpName = tempnam($dir, ''); + + if (null !== $extension) { + $tmpName .= $extension; + } + file_put_contents($tmpName, $string); $editor = getenv('EDITOR'); @@ -45,7 +51,7 @@ public function fromString($string) return $contents; } - public function fromStringWithMessage($string, $message, $messagePrefix = '# ') + public function fromStringWithMessage($string, $message, $messagePrefix = '# ', $extension = null) { if (null !== $message) { $message = explode("\n", $message); @@ -60,7 +66,7 @@ public function fromStringWithMessage($string, $message, $messagePrefix = '# ') $source .= $string; - $res = $this->fromString($source); + $res = $this->fromString($source, $extension); $res = explode("\n", $res); $line = current($res);