Skip to content

Commit 556d745

Browse files
committed
Finished NodeType commands
1 parent 66939f6 commit 556d745

File tree

8 files changed

+223
-4
lines changed

8 files changed

+223
-4
lines changed

features/bootstrap/FeatureContext.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,23 @@ public function thereShouldExistANodeTypeCalled($arg1)
501501
$nodeTypeManager->getNodeType($arg1);
502502
}
503503

504+
/**
505+
* @Given /^there should not exist a node type named "([^"]*)"$/
506+
*/
507+
public function thereShouldNotExistANodeTypeNamed($arg1)
508+
{
509+
$session = $this->getSession();
510+
$workspace = $session->getWorkspace();
511+
$nodeTypeManager = $workspace->getNodeTypeManager();
512+
try {
513+
$nodeTypeManager->getNodeType($arg1);
514+
} catch (\Exception $e) {
515+
var_dump(get_class($e));die();
516+
}
517+
518+
throw new \Exception('Node type ' . $arg1 . ' exists');
519+
}
520+
504521
/**
505522
* @Given /^I have an editor which produces the following:$/
506523
*/

features/node_type_list.feature

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Feature: List registered node types
2+
In order to list all of the registered node types
3+
As a user that is logged into the shell
4+
I need to be able to execute a command which does that
5+
6+
Background:
7+
Given that I am logged in as "testuser"
8+
9+
Scenario: List node types
10+
Given I execute the "node-type:list" command
11+
Then the command should not fail
12+
And I should see a table containing the following rows:
13+
| Name | Primary Item Name | Abstract? | Mixin? | Queryable? |
14+
| nt:folder | no | no | yes | yes |

features/node_type_load.feature

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Feature: Load a CND file
2+
In order to load a node type definition from a CND file
3+
As a user that is logged into the shell
4+
I need to be able to execute a command which does that
5+
6+
Background:
7+
Given that I am logged in as "testuser"
8+
And the file "NodeType.cnd" contains the contents of "example.cnd"
9+
10+
Scenario: Attempt to load a non-existing file
11+
Given I execute the "node-type:load notexists.cnd" command
12+
Then the command should fail
13+
And I should see the following:
14+
"""
15+
The CND file "notexists.cnd" does not exist
16+
"""
17+
18+
Scenario: Load the given node type from a file and allow updating
19+
Given I execute the "node-type:load NodeType.cnd --update" command
20+
Then the command should not fail
21+
And there should exist a node type called "ns:NodeType"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Feature: Unregister a node type
2+
In order to unregister a node type
3+
As a user that is logged into the shell
4+
I need to be able to do that
5+
6+
Background:
7+
Given that I am logged in as "testuser"
8+
9+
Scenario: Unregister a node type
10+
Given the "example.cnd" node type is loaded
11+
And I execute the "node-type:unregister ns:NodeType" command
12+
Then the command should fail
13+
And I should see the following:
14+
"""
15+
NodeType not found
16+
"""
17+
18+
Scenario: Attempt to unregister a non-registered node type
19+
Given the "example.cnd" node type is loaded
20+
And I execute the "node-type:unregister ns:NodeTypefoobar" command
21+
Then the command should fail
22+
And I should see the following:
23+
"""
24+
NodeType not found
25+
"""

src/PHPCR/Shell/Console/Application/ShellApplication.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use PHPCR\Util\Console\Command\NodeMoveCommand;
1717
use PHPCR\Util\Console\Command\NodeRemoveCommand;
1818
use PHPCR\Util\Console\Command\NodeTouchCommand;
19-
use PHPCR\Util\Console\Command\NodeTypeListCommand;
2019
use PHPCR\Util\Console\Command\NodeTypeRegisterCommand;
2120
use PHPCR\Util\Console\Command\NodesUpdateCommand;
2221
use PHPCR\Util\Console\Command\WorkspacePurgeCommand;
@@ -58,6 +57,9 @@
5857
use PHPCR\Shell\Console\Command\NodeTypeShowCommand;
5958
use PHPCR\Shell\Console\Helper\EditorHelper;
6059
use PHPCR\Shell\Console\Command\NodeTypeEditCommand;
60+
use PHPCR\Shell\Console\Command\NodeTypeUnregisterCommand;
61+
use PHPCR\Shell\Console\Command\NodeTypeListCommand;
62+
use PHPCR\Shell\Console\Command\NodeTypeLoadCommand;
6163

6264
class ShellApplication extends Application
6365
{
@@ -126,6 +128,9 @@ public function init()
126128
$this->add(new WorkspaceNodeCopyCommand());
127129
$this->add(new NodeTypeShowCommand());
128130
$this->add(new NodeTypeEditCommand());
131+
$this->add(new NodeTypeUnregisterCommand());
132+
$this->add(new NodeTypeListCommand());
133+
$this->add(new NodeTypeLoadCommand());
129134

130135
// add shell-specific commands
131136
$this->add(new ChangePathCommand());
@@ -154,9 +159,6 @@ public function init()
154159
$this->add($this->wrap(new NodeTouchCommand())
155160
->setName('touch')
156161
);
157-
$this->add($this->wrap(new NodeTypeListCommand())
158-
->setName('nt-list')
159-
);
160162
$this->add($this->wrap(new NodeTypeRegisterCommand())
161163
->setName('nt-register')
162164
);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Console\Command;
4+
5+
use Symfony\Component\Console\Command\Command;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
use Symfony\Component\Console\Input\InputArgument;
9+
use PHPCR\Util\CND\Writer\CndWriter;
10+
use PHPCR\NodeType\NoSuchNodeTypeException;
11+
12+
class NodeTypeListCommand extends Command
13+
{
14+
protected function configure()
15+
{
16+
$this->setName('node-type:list');
17+
$this->setDescription('List registered node types');
18+
$this->setHelp(<<<HERE
19+
List all node types (both primary and mixins)
20+
HERE
21+
);
22+
}
23+
24+
public function execute(InputInterface $input, OutputInterface $output)
25+
{
26+
$session = $this->getHelper('phpcr')->getSession();
27+
$workspace = $session->getWorkspace();
28+
$namespaceRegistry = $workspace->getNamespaceRegistry();
29+
$nodeTypeManager = $workspace->getNodeTypeManager();
30+
31+
$nodeTypes = $nodeTypeManager->getAllNodeTypes();
32+
33+
$table = $this->getHelper('table');
34+
$table->setHeaders(array('Name', 'Primary Item Name', 'Abstract?', 'Mixin?', 'Queryable?'));
35+
36+
foreach ($nodeTypes as $nodeType) {
37+
$table->addRow(array(
38+
$nodeType->getName(),
39+
$nodeType->getPrimaryItemName(),
40+
$nodeType->isAbstract() ? 'yes' : 'no',
41+
$nodeType->isMixin() ? 'yes' : 'no',
42+
$nodeType->isQueryable() ? 'yes': 'no',
43+
));
44+
}
45+
46+
$table->render($output);
47+
}
48+
}
49+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Console\Command;
4+
5+
use Symfony\Component\Console\Command\Command;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
use Symfony\Component\Console\Input\InputArgument;
9+
use PHPCR\Util\CND\Writer\CndWriter;
10+
use PHPCR\NodeType\NoSuchNodeTypeException;
11+
use PHPCR\Util\CND\Parser\CndParser;
12+
use PHPCR\NamespaceException;
13+
use Symfony\Component\Console\Input\InputOption;
14+
15+
class NodeTypeLoadCommand extends Command
16+
{
17+
protected function configure()
18+
{
19+
$this->setName('node-type:load');
20+
$this->setDescription('Load or create a node type');
21+
$this->addOption('update', null, InputOption::VALUE_NONE, 'Update existing node type');
22+
$this->addArgument('cndFile', InputArgument::REQUIRED, 'The name file containing the CND data');
23+
$this->setHelp(<<<HERE
24+
This command allows to register node types in the repository that are defined
25+
in a CND (Compact Namespace and Node Type Definition) file as used by jackrabbit.
26+
27+
Custom node types can be used to define the structure of content repository
28+
nodes, like allowed properties and child nodes together with the namespaces
29+
and their prefix used for the names of node types and properties.
30+
31+
If you use <info>--update</info> existing node type definitions will be overwritten
32+
in the repository.
33+
HERE
34+
);
35+
}
36+
37+
public function execute(InputInterface $input, OutputInterface $output)
38+
{
39+
$session = $this->getHelper('phpcr')->getSession();
40+
$cndFile = $input->getArgument('cndFile');
41+
$update = $input->getOption('update');
42+
$workspace = $session->getWorkspace();
43+
$namespaceRegistry = $workspace->getNamespaceRegistry();
44+
$nodeTypeManager = $workspace->getNodeTypeManager();
45+
46+
if (!file_exists($cndFile)) {
47+
throw new \InvalidArgumentException(sprintf(
48+
'The CND file "%s" does not exist.', $cndFile
49+
));
50+
}
51+
52+
$cndData = file_get_contents($cndFile);
53+
$nodeTypeManager->registerNodeTypesCnd($cndData, $update);
54+
}
55+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Console\Command;
4+
5+
use Symfony\Component\Console\Command\Command;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
use Symfony\Component\Console\Input\InputArgument;
9+
use PHPCR\Util\CND\Writer\CndWriter;
10+
use PHPCR\NodeType\NoSuchNodeTypeException;
11+
12+
class NodeTypeUnregisterCommand extends Command
13+
{
14+
protected function configure()
15+
{
16+
$this->setName('node-type:unregister');
17+
$this->setDescription('Unregister a node type UNSUPPORTED / TODO');
18+
$this->addArgument('nodeTypeName', null, InputArgument::REQUIRED, 'The name of the node type to unregister');
19+
$this->setHelp(<<<HERE
20+
Unregisters the specified node type
21+
HERE
22+
);
23+
}
24+
25+
public function execute(InputInterface $input, OutputInterface $output)
26+
{
27+
$session = $this->getHelper('phpcr')->getSession();
28+
$nodeTypeName = $input->getArgument('nodeTypeName');
29+
$workspace = $session->getWorkspace();
30+
$namespaceRegistry = $workspace->getNamespaceRegistry();
31+
$nodeTypeManager = $workspace->getNodeTypeManager();
32+
33+
$nodeType = $nodeTypeManager->unregisterNodeTypes(array($nodeTypeName));
34+
}
35+
}
36+

0 commit comments

Comments
 (0)