Skip to content

Commit deff679

Browse files
committed
Added info, lifecycle, list and references node commands
1 parent 6c73df3 commit deff679

14 files changed

+430
-30
lines changed

features/bootstrap/FeatureContext.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ public function iShouldSeeATableContainingTheFollowingRows(TableNode $table)
150150
foreach ($output as $line) {
151151
$foundCells = 0;
152152
foreach ($row as $cell) {
153+
if (!$cell) {
154+
$foundCells++;
155+
continue;
156+
}
157+
153158
if (false !== strpos($line, $cell)) {
154159
$foundCells++;
155160
}

features/node_info.feature

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ Feature: Show information about node
1313
Then the command should not fail
1414
And I should see the following:
1515
"""
16-
Identifier: /tests_general_base
17-
Path: /tests_general_base
18-
Index: 0
19-
Primary node type: nt:unstructured
20-
Mixin node types: [ mixin:foobar, mixin:barfoo ]
21-
Checked out: No
16+
+-------------------+--------------------------------------+
17+
| Path | /tests_general_base |
18+
| UUID | N/A |
19+
| Index | 1 |
20+
| Primary node type | nt:folder |
21+
| Mixin node types | |
22+
| Checked out? | [ERROR] Not implemented by jackalope |
23+
| Locked? | [ERROR] Not implemented by jackalope |
24+
+-------------------+--------------------------------------+
2225
"""

features/node_lifecycle_follow_transition.feature

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ Feature: Follow the given lifecycle transition on the current node
99

1010
Scenario: Follow lifecycle transition
1111
Given the current node is "/tests_general_base"
12-
And I execute the "node:lifecycle:follow-transition foo" command
13-
Then the command should not fail
12+
And I execute the "node:lifecycle:follow foo" command
13+
Then the command should fail
14+
And I should see the following:
15+
"""
16+
Not implemented
17+
"""

features/node_lifecycle_list.feature

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ Feature: List the possible lifecycle transitions for the current node
1010
Scenario: List possible lifecycle transitions
1111
Given the current node is "/tests_general_base"
1212
And I execute the "node:lifecycle:list" command
13-
Then the command should not fail
13+
Then the command should fail
14+
And I should see the following:
15+
"""
16+
Not implemented
17+
"""
18+

features/node_list.feature

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,34 @@ Feature: List properites and chidren of current node
1111
Given the current node is "/tests_general_base"
1212
And I execute the "node:list --no-ansi" command
1313
Then the command should not fail
14-
And I should see a table with the following rows
15-
| Node / Prop | Type | Value |
16-
| -jcr:createdBy | STRING | admin |
17-
| -jcr:primaryType | NAME | nt:folder |
18-
| index.txt/ | nt:file | |
14+
And I should see a table containing the following rows:
1915
| idExample/ | nt:file | |
20-
| test:namespacedNode/ | nt:folder | |
21-
| emptyExample/ | nt:folder | |
16+
| test:namespacedNode | nt:folder | |
17+
| emptyExample | nt:folder | |
2218
| multiValueProperty/ | nt:folder | |
2319
| numberPropertyNode/ | nt:file | |
2420
| NumberPropertyNodeToCompare1/ | nt:file | |
2521
| NumberPropertyNodeToCompare2/ | nt:file | |
22+
| jcr:createdBy | STRING | admin |
23+
| jcr:primaryType | NAME | nt:folder |
2624

2725
Scenario: List the properties
2826
Given the current node is "/tests_general_base"
2927
And I execute the "node:list --properties --no-ansi" command
3028
Then the command should not fail
31-
And I should see a table with the following rows
32-
| Property name | Type | Value |
33-
| -jcr:createdBy | STRING | admin |
34-
| -jcr:primaryType | NAME | nt:folder |
29+
And I should see a table containing the following rows:
30+
| jcr:createdBy | STRING | admin |
31+
| jcr:primaryType | NAME | nt:folder |
3532

3633
Scenario: List the children nodes
3734
Given the current node is "/tests_general_base"
3835
And I execute the "node:list --children --no-ansi" command
3936
Then the command should not fail
40-
And I should see a table with the following rows
41-
| Node name | Node Type | Value |
37+
And I should see a table containing the following rows:
4238
| index.txt/ | nt:file | |
4339
| idExample/ | nt:file | |
44-
| test:namespacedNode/ | nt:folder | |
45-
| emptyExample/ | nt:folder | |
40+
| test:namespacedNode | nt:folder | |
41+
| emptyExample | nt:folder | |
4642
| multiValueProperty/ | nt:folder | |
4743
| numberPropertyNode/ | nt:file | |
4844
| NumberPropertyNodeToCompare1/ | nt:file | |

features/node_references.feature

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,28 @@ Feature: Show node references
88
And the "session_data.xml" fixtures are loaded
99

1010
Scenario: List weak references
11-
Given the current node is "/tests_general_base/idExample/jcr:content/weakreference_target""
11+
Given the current node is "/tests_general_base/idExample/jcr:content/weakreference_target"
1212
And I execute the "node:references --no-ansi" command
1313
Then the command should not fail
14-
And I should see table with the following rows::
15-
| Type | Path |
16-
| weak | /foobar |
14+
And I should see a table containing the following rows:
15+
| Type | Property | Node Path |
16+
| weak | ref2 | /tests_general_base/idExample/jcr:content/weakreference_target |
17+
| weak | ref1 | /tests_general_base/idExample/jcr:content/weakreference_target |
18+
19+
Scenario: List named weak references
20+
Given the current node is "/tests_general_base/idExample/jcr:content/weakreference_target"
21+
And I execute the "node:references ref2 --no-ansi" command
22+
Then the command should not fail
23+
And I should see a table containing the following rows:
24+
| Type | Property | Node Path |
25+
| weak | ref2 | /tests_general_base/idExample/jcr:content/weakreference_target |
26+
27+
Scenario: List strong references
28+
Given the current node is "/tests_general_base/idExample"
29+
And I execute the "node:references --no-ansi" command
30+
Then the command should not fail
31+
And I should see a table containing the following rows:
32+
| Type | Property | Node Path |
33+
| strong | ref | /tests_general_base/idExample |
34+
| strong | multiref | /tests_general_base/idExample |
35+
| | | /tests_general_base/multiValueProperty |

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,14 @@
7373
use PHPCR\Shell\Console\Command\NodeRenameCommand;
7474
use PHPCR\Shell\Console\Command\NodeMixinAddCommand;
7575
use PHPCR\Shell\Console\Command\NodeMixinRemoveCommand;
76+
use PHPCR\Shell\Console\Command\NodeInfoCommand;
77+
use PHPCR\Shell\Console\Command\NodeLifecycleFollowCommand;
78+
use PHPCR\Shell\Console\Command\NodeLifecycleListCommand;
79+
use PHPCR\Shell\Console\Command\NodeListCommand;
80+
use PHPCR\Shell\Console\Command\NodeReferencesCommand;
7681
use Jackalope\NotImplementedException;
82+
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
83+
use Symfony\Component\Console\Formatter\OutputFormatter;
7784

7885
class ShellApplication extends Application
7986
{
@@ -157,6 +164,11 @@ public function init()
157164
$this->add(new NodeRenameCommand());
158165
$this->add(new NodeMixinAddCommand());
159166
$this->add(new NodeMixinRemoveCommand());
167+
$this->add(new NodeInfoCommand());
168+
$this->add(new NodeLifecycleFollowCommand());
169+
$this->add(new NodeLifecycleListCommand());
170+
$this->add(new NodeListCommand());
171+
$this->add(new NodeReferencesCommand());
160172

161173
// add shell-specific commands
162174
$this->add(new ChangePathCommand());
@@ -240,9 +252,28 @@ public function wrap(Command $command)
240252
return $command;
241253
}
242254

255+
private function configureFormatter(OutputFormatter $formatter)
256+
{
257+
$style = new OutputFormatterStyle(null, null, array('bold'));
258+
$formatter->setStyle('node', $style);
259+
260+
$style = new OutputFormatterStyle(null, null, array());
261+
$formatter->setStyle('property', $style);
262+
263+
$style = new OutputFormatterStyle('magenta', null, array('bold'));
264+
$formatter->setStyle('node-type', $style);
265+
266+
$style = new OutputFormatterStyle('magenta', null, array());
267+
$formatter->setStyle('property-type', $style);
268+
269+
$style = new OutputFormatterStyle(null, null, array());
270+
$formatter->setStyle('property-value', $style);
271+
}
272+
243273
public function doRun(InputInterface $input, OutputInterface $output)
244274
{
245275
$this->init();
276+
$this->configureFormatter($output->getFormatter());
246277

247278
$name = $this->getCommandName($input);
248279

src/PHPCR/Shell/Console/Command/NodeCreateCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ protected function configure()
1818
{
1919
$this->setName('node:create');
2020
$this->setDescription('Create a node at the current path');
21-
$this->addArgument('relPath', null, InputArgument::REQUIRED, null, 'The name of the node to create');
22-
$this->addArgument('primaryNodeTypeName', null, InputArgument::OPTIONAL, null, 'Optional name of primary node type to use');
21+
$this->addArgument('relPath', InputArgument::REQUIRED, 'The name of the node to create');
22+
$this->addArgument('primaryNodeTypeName', InputArgument::OPTIONAL, 'Optional name of primary node type to use');
2323
$this->setHelp(<<<HERE
2424
Creates a new node at the specified <info>relPath</info>
2525
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
14+
class NodeInfoCommand extends Command
15+
{
16+
protected function configure()
17+
{
18+
$this->setName('node:info');
19+
$this->setDescription('Show information about the current node');
20+
$this->setHelp(<<<HERE
21+
Show information about the current node
22+
HERE
23+
);
24+
}
25+
26+
public function execute(InputInterface $input, OutputInterface $output)
27+
{
28+
$session = $this->getHelper('phpcr')->getSession();
29+
$currentNode = $session->getCurrentNode();
30+
$formatter = $this->getHelper('result_formatter');
31+
32+
$mixins = $currentNode->getMixinNodeTypes();
33+
$mixinNodeTypeNames = array();
34+
35+
foreach ($mixins as $name => $mixin) {
36+
$mixinNodeTypeNames[] = $mixin->getName();
37+
}
38+
39+
try {
40+
$isCheckedOut = $currentNode->isCheckedOut() ? 'yes' : 'no';
41+
} catch (\Exception $e) {
42+
$isCheckedOut = $formatter->formatException($e);
43+
}
44+
45+
try {
46+
$isLocked = $currentNode->isLocked() ? 'yes' : 'no';
47+
} catch (\Exception $e) {
48+
$isLocked = $formatter->formatException($e);
49+
}
50+
51+
$info = array(
52+
'Path' => $currentNode->getPath(),
53+
'UUID' => $currentNode->hasProperty('jcr:uuid') ? $currentNode->getProperty('jcr:uuid')->getValue() : 'N/A',
54+
'Index' => $currentNode->getIndex(),
55+
'Primary node type' => $currentNode->getPrimaryNodeType()->getName(),
56+
'Mixin node types' => implode(', ', $mixinNodeTypeNames),
57+
'Checked out?' => $isCheckedOut,
58+
'Locked?' => $isLocked,
59+
);
60+
61+
$table = clone $this->getHelper('table');
62+
63+
foreach ($info as $label => $value) {
64+
$table->addRow(array($label, $value));
65+
}
66+
67+
$table->render($output);
68+
}
69+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
14+
class NodeLifecycleFollowCommand extends Command
15+
{
16+
protected function configure()
17+
{
18+
$this->setName('node:lifecycle:follow');
19+
$this->setDescription('Causes the lifecycle state of this node to undergo the specified transition. NOT IMPLEMENTED');
20+
$this->addArgument('transition', InputArgument::REQUIRED, 'A state transition');
21+
$this->setHelp(<<<HERE
22+
Causes the lifecycle state of the current node to undergo the specified
23+
transition.
24+
25+
This command may change the value of the jcr:currentLifecycleState
26+
property, in most cases it is expected that the implementation will
27+
change the value to that of the passed transition parameter, though this
28+
is an implementation-specific issue. If the jcr:currentLifecycleState
29+
property is changed the change is persisted immediately, there is no
30+
need to call save.
31+
HERE
32+
);
33+
}
34+
35+
public function execute(InputInterface $input, OutputInterface $output)
36+
{
37+
$session = $this->getHelper('phpcr')->getSession();
38+
$currentNode = $session->getCurrentNode();
39+
$transition = $input->getArgument('transition');
40+
$currentNode->followLifecycleTransition($transition);
41+
}
42+
}
43+

0 commit comments

Comments
 (0)