Skip to content

Commit 436db04

Browse files
committed
Always check for references when running node:remove
- Help prevent transaction failure when calling save - Also allow the removal of node by UUID
1 parent e040c53 commit 436db04

File tree

4 files changed

+64
-9
lines changed

4 files changed

+64
-9
lines changed

Diff for: CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
Changelog
22
=========
33

4+
dev-master
5+
----------
6+
7+
### Features
8+
9+
- Immediately fail when trying to delete a node which is referenced
10+
11+
### Bug Fixes
12+
13+
- Cannot `node:remove` by UUID
14+
415
alpha-6
516
-------
617

Diff for: features/fixtures/cms.xml

+17
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@
5757
</sv:node>
5858
</sv:node>
5959

60+
<sv:node sv:name="users">
61+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
62+
<sv:value>nt:unstructured</sv:value>
63+
</sv:property>
64+
<sv:node sv:name="daniel">
65+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
66+
<sv:value>nt:unstructured</sv:value>
67+
</sv:property>
68+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
69+
<sv:value>mix:referenceable</sv:value>
70+
</sv:property>
71+
<sv:property sv:name="jcr:uuid" sv:type="String">
72+
<sv:value>88888888-1abf-4708-bfcc-e49511754b40</sv:value>
73+
</sv:property>
74+
</sv:node>
75+
</sv:node>
76+
6077
<sv:node sv:name="articles">
6178
<sv:property sv:name="jcr:primaryType" sv:type="Name">
6279
<sv:value>nt:unstructured</sv:value>

Diff for: features/phpcr_node_remove.feature

+20-8
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ Feature: Remove a node
55

66
Background:
77
Given that I am logged in as "testuser"
8-
And the "session_data.xml" fixtures are loaded
8+
And the "cms.xml" fixtures are loaded
99

1010
Scenario: Remove the current node
11-
Given the current node is "/tests_general_base"
11+
Given the current node is "/cms/test"
1212
And I execute the "node:remove ." command
1313
Then the command should not fail
1414
And I save the session
15-
And there should not exist a node at "/tests_general_base"
16-
And the current node should be "/"
15+
And there should not exist a node at "/cms/test"
16+
And the current node should be "/cms"
1717

1818
Scenario: Remove a non-current node
19-
Given the current node is "/tests_general_base"
20-
And I execute the "node:remove daniel" command
19+
Given the current node is "/cms"
20+
And I execute the "node:remove /cms/users/daniel" command
2121
Then the command should not fail
2222
And I save the session
23-
And there should not exist a node at "/tests_general_base/daniel"
24-
And the current node should be "/tests_general_base"
23+
And there should not exist a node at "/cms/users/daniel"
24+
And the current node should be "/cms"
2525

2626
Scenario: Delete root node
2727
Given the current node is "/"
@@ -32,3 +32,15 @@ Feature: Remove a node
3232
You cannot delete the root node
3333
"""
3434

35+
Scenario: Delete node by UUID
36+
Given the current node is "/"
37+
And I execute the "node:remove 88888888-1abf-4708-bfcc-e49511754b40" command
38+
Then the command should not fail
39+
40+
Scenario: Delete referenced node
41+
Given I execute the "node:remove /cms/articles/article1" command
42+
Then the command should fail
43+
And I should see the following:
44+
"""
45+
The node "/cms/articles/article1" is referenced by the following properties
46+
"""

Diff for: src/PHPCR/Shell/Console/Command/Phpcr/NodeRemoveCommand.php

+16-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,22 @@ public function execute(InputInterface $input, OutputInterface $output)
3535
);
3636
}
3737

38-
$session->removeItem($targetPath);
38+
$references = $targetNode->getReferences();
39+
40+
if (count($references) > 0) {
41+
$paths = array();
42+
foreach ($references as $reference) {
43+
$paths[] = $reference->getPath();
44+
}
45+
46+
throw new \InvalidArgumentException(sprintf(
47+
'The node "%s" is referenced by the following properties: "%s"',
48+
$targetNode->getPath(),
49+
implode('", "', $paths)
50+
));
51+
}
52+
53+
$targetNode->remove();
3954

4055
// if we deleted the current path, switch back to the parent node
4156
if ($currentPath == $session->getAbsPath($targetPath)) {

0 commit comments

Comments
 (0)