Skip to content

Commit e72689d

Browse files
committed
node:remove, shared:show and shared:remove command
1 parent 9d99b56 commit e72689d

File tree

8 files changed

+169
-16
lines changed

8 files changed

+169
-16
lines changed

features/bootstrap/FeatureContext.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ public function thereShouldNotExistANodeAt($arg1)
411411

412412
try {
413413
$session->getNode($arg1);
414-
throw new \Exception('Node does at path ' . $arg1 . ' exists.');
414+
throw new \Exception('Node at path ' . $arg1 . ' exists.');
415415
} catch (PathNotFoundException $e) {
416416
// good.. not does not exist
417417
}
@@ -636,4 +636,14 @@ public function theNodeAtHasTheMixin($arg1, $arg2)
636636
$node->addMixin($arg2);
637637
$session->save();
638638
}
639+
640+
/**
641+
* @Given /^I clone node "([^"]*)" from "([^"]*)" to "([^"]*)"$/
642+
*/
643+
public function iCloneNodeFromTo($arg1, $arg2, $arg3)
644+
{
645+
$session = $this->getSession();
646+
$workspace = $session->getWorkspace();
647+
$workspace->cloneFrom($arg2, $arg1, $arg3, false);
648+
}
639649
}

features/fixtures/session_data.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
sv:name="tests_general_base">
1818
<sv:property sv:name="jcr:primaryType" sv:type="Name">
19-
<sv:value>nt:folder</sv:value>
19+
<sv:value>nt:unstructured</sv:value>
2020
</sv:property>
2121
<sv:property sv:name="jcr:created" sv:type="Date">
2222
<sv:value>2011-03-21T14:34:20.431+01:00</sv:value>
@@ -25,6 +25,17 @@
2525
<sv:value>admin</sv:value>
2626
</sv:property>
2727

28+
<sv:node sv:name="daniel">
29+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
30+
<sv:value>nt:unstructured</sv:value>
31+
</sv:property>
32+
<sv:node sv:name="leech">
33+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
34+
<sv:value>nt:unstructured</sv:value>
35+
</sv:property>
36+
</sv:node>
37+
</sv:node>
38+
2839
<sv:node sv:name="index.txt">
2940
<sv:property sv:name="jcr:primaryType" sv:type="Name">
3041
<sv:value>nt:file</sv:value>

features/node_shared_remove.feature

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ Feature: Remove the current node from any shared set to which it belongs
55

66
Background:
77
Given that I am logged in as "testuser"
8-
And the "session_data.xml" fixtures are loaded into workspace "workspace_a"
9-
And the "session_data.xml" fixtures are loaded into workspace "workspace_b"
10-
And the node at "/tests_general_base" in "workspace_a" is cloned to "/foobar" in "workspace_b"
8+
And the "session_data.xml" fixtures are loaded
9+
And the node at "/tests_general_base/daniel/leech" has the mixin "mix:shareable"
10+
And I clone node "/tests_general_base/daniel/leech" from "default" to "/tests_general_base/bar"
1111

12-
Scenario: Rename a node
13-
Given the current node is "/tests_general_base"
14-
And I execute the "node:shared:show" command
15-
Then the command should not fail
12+
Scenario: Remove the current node and all of its shared paths
13+
Given the current node is "/tests_general_base/daniel"
14+
And I execute the "node:shared:remove" command
15+
Then the command should fail
16+
And I should see the following:
17+
"""
18+
Not implemented
19+
"""

features/node_shared_show.feature

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ Feature: Show the current nodes shared set
55

66
Background:
77
Given that I am logged in as "testuser"
8-
And the "session_data.xml" fixtures are loaded into workspace "workspace_a"
9-
And the "session_data.xml" fixtures are loaded into workspace "default"
10-
And the node at "/tests_general_base" in "workspace_a" is cloned to "/foobar" in "default"
8+
And the "session_data.xml" fixtures are loaded
9+
And the node at "/tests_general_base/daniel/leech" has the mixin "mix:shareable"
10+
And I clone node "/tests_general_base/daniel/leech" from "default" to "/tests_general_base/bar"
1111

1212
Scenario: Show the current nodes shared set
13-
Given the current node is "/tests_general_base"
13+
Given the current node is "/tests_general_base/daniel/leech"
1414
And I execute the "node:shared:show" command
15-
Then the command should not fai
15+
Then the command should fail
1616
And I should see the following:
1717
"""
18-
workspace_a: /tests_general_base
18+
Not implemented
1919
"""

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use PHPCR\SimpleCredentials;
1616
use PHPCR\Util\Console\Command\NodeDumpCommand;
1717
use PHPCR\Util\Console\Command\NodeMoveCommand;
18-
use PHPCR\Util\Console\Command\NodeRemoveCommand;
1918
use PHPCR\Util\Console\Command\NodeTouchCommand;
2019
use PHPCR\Util\Console\Command\NodeTypeRegisterCommand;
2120
use PHPCR\Util\Console\Command\NodesUpdateCommand;
@@ -81,6 +80,10 @@
8180
use PHPCR\Shell\Console\Command\NodeLifecycleListCommand;
8281
use PHPCR\Shell\Console\Command\NodeListCommand;
8382
use PHPCR\Shell\Console\Command\NodeReferencesCommand;
83+
use PHPCR\Shell\Console\Command\NodeSharedShowCommand;
84+
use PHPCR\Shell\Console\Command\NodeSharedRemoveCommand;
85+
use PHPCR\Shell\Console\Command\NodeRemoveCommand;
86+
8487
use Jackalope\NotImplementedException;
8588
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
8689
use Symfony\Component\Console\Formatter\OutputFormatter;
@@ -175,6 +178,9 @@ public function init()
175178
$this->add(new NodeLifecycleListCommand());
176179
$this->add(new NodeListCommand());
177180
$this->add(new NodeReferencesCommand());
181+
$this->add(new NodeSharedShowCommand());
182+
$this->add(new NodeSharedRemoveCommand());
183+
$this->add(new NodeRemoveCommand());
178184

179185
// add shell-specific commands
180186
$this->add(new ChangePathCommand());
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 NodeRemoveCommand extends Command
15+
{
16+
protected function configure()
17+
{
18+
$this->setName('node:remove');
19+
$this->setDescription('Remove the node at the current path');
20+
$this->setHelp(<<<HERE
21+
Remove 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+
$currentPath = $currentNode->getPath();
31+
32+
if ($currentPath == '/') {
33+
throw new \InvalidArgumentException(
34+
'Cannot delete root node!'
35+
);
36+
}
37+
38+
$session->removeItem($currentPath);
39+
$session->chdir('..');
40+
}
41+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 NodeSharedRemoveCommand extends Command
16+
{
17+
protected function configure()
18+
{
19+
$this->setName('node:shared:remove');
20+
$this->setDescription('Removes this node and every other node in the shared set of this node');
21+
$this->setHelp(<<<HERE
22+
Removes this node and every other node in the shared set of this node.
23+
24+
This removal must be done atomically, i.e., if one of the nodes cannot
25+
be removed, the method throws the exception <info>node:remove</info>
26+
would have thrown in that case, and none of the nodes are removed.
27+
28+
If this node is not shared this method removes only this node.
29+
HERE
30+
);
31+
}
32+
33+
public function execute(InputInterface $input, OutputInterface $output)
34+
{
35+
$session = $this->getHelper('phpcr')->getSession();
36+
$currentNode = $session->getCurrentNode();
37+
$sharedSet = $currentNode->removeSharedSet();
38+
}
39+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 NodeSharedShowCommand extends Command
16+
{
17+
protected function configure()
18+
{
19+
$this->setName('node:shared:show');
20+
$this->setDescription('Show all the nodes are in the shared set of this node');
21+
$this->setHelp(<<<HERE
22+
Lists all nodes that are in the shared set of this node.
23+
24+
Shareable nodes are analagous to symbolic links in a linux filesystem and can
25+
be created by cloning a node within the same workspace.
26+
27+
If this node is not shared then only this node is shown.
28+
HERE
29+
);
30+
}
31+
32+
public function execute(InputInterface $input, OutputInterface $output)
33+
{
34+
$session = $this->getHelper('phpcr')->getSession();
35+
$currentNode = $session->getCurrentNode();
36+
$sharedSet = $currentNode->getSharedSet();
37+
38+
foreach ($sharedSet as $sharedNode) {
39+
$output->writeln($sharedNode->getPath());
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)