Skip to content

Commit d5a3d4b

Browse files
committed
Merge pull request #110 from phpcr/remove-node-check-references
Always check for references when running node:remove
2 parents a7876a9 + ed9b95b commit d5a3d4b

File tree

7 files changed

+90
-10
lines changed

7 files changed

+90
-10
lines changed

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ dev-master
77
### Bug fixes
88

99
- [config] Do not override CLI options with profile options
10+
- [node:remove] Cannot `node:remove` by UUID
11+
- [node:edit] Serialization of single value references doesn't work
1012

1113
### Features
1214

15+
- [node:remove] Immediately fail when trying to delete a node which has a
16+
(hard) referrer
1317
- [cli] Specify workspace with first argument
1418
- [global] Refactored to use DI container and various general improvements
1519
- [node:property:set] Allow setting reference property type by path

Diff for: features/all/phpcr_node_edit.feature

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ Feature: Edit a node
2828
articles:
2929
type: Reference
3030
value: [ 66666fc6-1abf-4708-bfcc-e49511754b40, 77777777-1abf-4708-bfcc-e49511754b40 ]
31+
article-weak:
32+
type: WeakReference
33+
value: 99999999-1abf-4708-bfcc-e49511754b40
3134
'jcr:primaryType':
3235
type: Name
3336
value: 'nt:unstructured'

Diff for: features/all/phpcr_node_remove.feature

+25-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 "/"
@@ -37,3 +37,20 @@ Feature: Remove a node
3737
Then the command should not fail
3838
And I save the session
3939
And there should not exist a node at "/tests_general_base/daniel"
40+
41+
Scenario: Delete node by UUID
42+
Given the current node is "/"
43+
And I execute the "node:remove 88888888-1abf-4708-bfcc-e49511754b40" command
44+
Then the command should not fail
45+
46+
Scenario: Delete referenced node
47+
Given I execute the "node:remove /cms/articles/article1" command
48+
Then the command should fail
49+
And I should see the following:
50+
"""
51+
The node "/cms/articles/article1" is referenced by the following properties
52+
"""
53+
54+
Scenario: Delete weak referenced node
55+
Given I execute the "node:remove /cms/articles/article3" command
56+
Then the command should not fail

Diff for: features/fixtures/cms.xml

+34
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,26 @@
5454
<sv:value>66666fc6-1abf-4708-bfcc-e49511754b40</sv:value>
5555
<sv:value>77777777-1abf-4708-bfcc-e49511754b40</sv:value>
5656
</sv:property>
57+
<sv:property sv:name="article-weak" sv:type="WeakReference">
58+
<sv:value>99999999-1abf-4708-bfcc-e49511754b40</sv:value>
59+
</sv:property>
60+
</sv:node>
61+
</sv:node>
62+
63+
<sv:node sv:name="users">
64+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
65+
<sv:value>nt:unstructured</sv:value>
66+
</sv:property>
67+
<sv:node sv:name="daniel">
68+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
69+
<sv:value>nt:unstructured</sv:value>
70+
</sv:property>
71+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
72+
<sv:value>mix:referenceable</sv:value>
73+
</sv:property>
74+
<sv:property sv:name="jcr:uuid" sv:type="String">
75+
<sv:value>88888888-1abf-4708-bfcc-e49511754b40</sv:value>
76+
</sv:property>
5777
</sv:node>
5878
</sv:node>
5979

@@ -113,6 +133,20 @@
113133
<sv:value>Planes</sv:value>
114134
</sv:property>
115135
</sv:node>
136+
<sv:node sv:name="article3">
137+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
138+
<sv:value>nt:unstructured</sv:value>
139+
</sv:property>
140+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
141+
<sv:value>mix:referenceable</sv:value>
142+
</sv:property>
143+
<sv:property sv:name="jcr:uuid" sv:type="String">
144+
<sv:value>99999999-1abf-4708-bfcc-e49511754b40</sv:value>
145+
</sv:property>
146+
<sv:property sv:name="title" sv:type="String">
147+
<sv:value>Article 3</sv:value>
148+
</sv:property>
149+
</sv:node>
116150
</sv:node>
117151
</sv:node>
118152

Binary file not shown.

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

+18-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function execute(InputInterface $input, OutputInterface $output)
2525
$session = $this->get('phpcr.session');
2626
$path = $input->getArgument('path');
2727
$currentPath = $session->getCwd();
28+
$nodePaths = array();
2829

2930
// verify that node exists by trying to get it..
3031
$nodes = $session->findNodes($path);
@@ -36,11 +37,27 @@ public function execute(InputInterface $input, OutputInterface $output)
3637
);
3738
}
3839

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

4259
// if we deleted the current path, switch back to the parent node
43-
if ($currentPath == $session->getAbsPath($path)) {
60+
if (in_array($currentPath, $nodePaths)) {
4461
$session->chdir('..');
4562
}
4663
}

Diff for: src/PHPCR/Shell/Serializer/NodeNormalizer.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ public function normalize($node, $format = null, array $context = array())
4848

4949
if (in_array($property->getType(), array(PropertyType::REFERENCE, PropertyType::WEAKREFERENCE))) {
5050
$nodesUuids = array();
51-
foreach ((array) $propertyValue as $node) {
51+
52+
if (false === is_array($propertyValue)) {
53+
$propertyValue = array($propertyValue);
54+
}
55+
56+
foreach ($propertyValue as $node) {
5257
$nodeUuids[] = $node->getIdentifier();
5358
}
5459
$propertyValue = $nodeUuids;

0 commit comments

Comments
 (0)