Skip to content

Commit b36ad45

Browse files
committed
[query] Full support for manipulating multivalue properties
1 parent 2c3b3c5 commit b36ad45

File tree

6 files changed

+338
-47
lines changed

6 files changed

+338
-47
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ dev-master
66

77
### Features
88

9+
- [query] Full support for manipulating multivalue properties
10+
11+
alpha-5
12+
-------
13+
14+
### Features
15+
916
- [shell] Added "shell:clear" command to support clearing the console output
1017
- [general] The shell supports being embedded as a dependency
1118
- [node:edit] New command `node:edit` enables editing of entire node

features/phpcr_query_update.feature

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,99 @@ Feature: Execute a a raw UPDATE query in JCR_SQL2
2424
| UPDATE nt:unstructured AS a SET title = 'DTL' WHERE localname() = 'article1' | /cms/articles/article1 | title | DTL |
2525
| UPDATE nt:unstructured AS a SET title = 'DTL', foobar='barfoo' WHERE localname() = 'article1' | /cms/articles/article1 | foobar | barfoo |
2626

27-
Scenario: Update multivalue index by value
27+
Scenario: Replace a multivalue index by value
2828
Given I execute the "UPDATE [nt:unstructured] AS a SET a.tags = 'Rockets' WHERE a.tags = 'Trains'" command
2929
And I save the session
3030
Then the command should not fail
31+
And the node at "/cms/articles/article1" should have the property "tags" with value "Rockets" at index "1"
32+
33+
Scenario: Set a multivalue value
34+
Given I execute the "UPDATE [nt:unstructured] AS a SET a.tags = ['Rockets', 'Dragons'] WHERE a.tags = 'Trains'" command
35+
And I save the session
36+
Then the command should not fail
37+
And the node at "/cms/articles/article1" should have the property "tags" with value "Rockets" at index "0"
38+
And the node at "/cms/articles/article1" should have the property "tags" with value "Dragons" at index "1"
39+
40+
Scenario: Update single multivalue
41+
Given I execute the "UPDATE [nt:unstructured] AS a SET a.tags = 'Rockets' WHERE a.tags = 'Planes'" command
42+
And I save the session
43+
Then the command should not fail
3144
And I should see the following:
3245
"""
33-
Cannot update property "tags". Updating multi-value nodes with more than one element not currently supported
46+
1 row(s) affected
3447
"""
48+
And the node at "/cms/articles/article1" should have the property "tags" with value "Rockets" at index "0"
49+
And the node at "/cms/articles/article1" should have the property "tags" with value "Automobiles" at index "2"
3550

36-
Scenario: Update single multivalue
37-
Given I execute the "UPDATE [nt:unstructured] AS a SET a.tag = 'Rockets' WHERE a.tags = 'Planes'" command
51+
Scenario: Update single multivalue without selector
52+
Given I execute the "UPDATE [nt:unstructured] SET tags = 'Rockets' WHERE tags = 'Planes'" command
53+
And I save the session
54+
Then the command should not fail
55+
And I should see the following:
56+
"""
57+
1 row(s) affected
58+
"""
59+
And the node at "/cms/articles/article1" should have the property "tags" with value "Rockets" at index "0"
60+
And the node at "/cms/articles/article1" should have the property "tags" with value "Automobiles" at index "2"
61+
62+
Scenario: Remove single multivalue
63+
Given I execute the "UPDATE [nt:unstructured] AS a SET a.tags = NULL WHERE a.tags = 'Planes'" command
64+
And I save the session
65+
Then the command should not fail
66+
And I should see the following:
67+
"""
68+
1 row(s) affected
69+
"""
70+
And the node at "/cms/articles/article1" should have the property "tags" with value "Trains" at index "0"
71+
And the node at "/cms/articles/article1" should have the property "tags" with value "Automobiles" at index "1"
72+
73+
Scenario: Remove single multivalue by index
74+
Given I execute the "UPDATE [nt:unstructured] AS a SET a.tags[0] = NULL WHERE a.tags = 'Planes'" command
3875
And I save the session
3976
Then the command should not fail
4077
And I should see the following:
4178
"""
4279
1 row(s) affected
4380
"""
44-
And the node at "/cms/articles/article1" should have the property "tag" with value "Rockets" at index "0"
81+
And the node at "/cms/articles/article1" should have the property "tags" with value "Trains" at index "0"
82+
And the node at "/cms/articles/article1" should have the property "tags" with value "Automobiles" at index "1"
83+
84+
Scenario: Add a multivalue property
85+
Given I execute the "UPDATE [nt:unstructured] AS a SET a.tags[] = 'Kite' WHERE a.tags = 'Planes'" command
86+
And I save the session
87+
Then the command should not fail
88+
And I should see the following:
89+
"""
90+
1 row(s) affected
91+
"""
92+
And the node at "/cms/articles/article1" should have the property "tags" with value "Planes" at index "0"
93+
And the node at "/cms/articles/article1" should have the property "tags" with value "Automobiles" at index "2"
94+
And the node at "/cms/articles/article1" should have the property "tags" with value "Kite" at index "3"
95+
96+
Scenario: Replace a multivalue property by index
97+
Given I execute the "UPDATE [nt:unstructured] AS a SET a.tags[1] = 'Kite', a.tags[2] = 'foobar' WHERE a.tags = 'Planes'" command
98+
And I save the session
99+
Then the command should not fail
100+
And I should see the following:
101+
"""
102+
1 row(s) affected
103+
"""
104+
And the node at "/cms/articles/article1" should have the property "tags" with value "Planes" at index "0"
105+
And the node at "/cms/articles/article1" should have the property "tags" with value "Kite" at index "1"
106+
And the node at "/cms/articles/article1" should have the property "tags" with value "foobar" at index "2"
107+
108+
Scenario: Replace a multivalue property by invalid index
109+
Given I execute the "UPDATE [nt:unstructured] AS a SET a.tags[10] = 'Kite' WHERE a.tags = 'Planes'" command
110+
Then the command should fail
111+
And I should see the following:
112+
"""
113+
Multivalue index "10" does not exist
114+
"""
115+
116+
Scenario: Replace a multivalue property by invalid index with array (invalid)
117+
Given I execute the "UPDATE [nt:unstructured] AS a SET a.tags[1] = ['Kite'] WHERE a.tags = 'Planes'" command
118+
Then the command should fail
119+
And I should see the following:
120+
"""
121+
Cannot set index to array value on "tags"
122+
"""

spec/PHPCR/Shell/Query/UpdateParserSpec.php

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,80 @@ function it_should_provide_a_qom_object_for_selecting(
6666

6767
$res->offsetGet(0)->shouldHaveType('PHPCR\Query\QueryInterface');
6868
$res->offsetGet(1)->shouldReturn(array(
69-
'parent.foo' => array(
69+
array(
70+
'array_op' => null,
7071
'selector' => 'parent',
7172
'name' => 'foo',
7273
'value' => 'PHPCR\\FOO\\Bar',
7374
),
74-
'parent.bar' => array(
75+
array(
76+
'array_op' => null,
7577
'selector' => 'parent',
7678
'name' => 'bar',
7779
'value' => 'foo',
7880
),
7981
));
8082
}
83+
84+
function it_should_parse_array_values (
85+
QueryObjectModelFactoryInterface $qomf,
86+
ChildNodeJoinConditionInterface $joinCondition,
87+
JoinInterface $join,
88+
SourceInterface $source,
89+
PropertyValueInterface $tagsValue,
90+
LiteralInterface $literalValue,
91+
ComparisonInterface $comparison,
92+
QueryInterface $query
93+
)
94+
{
95+
$qomf->selector('a', 'dtl:article')->willReturn($source);
96+
$qomf->createQuery($source, null)->willReturn($query);
97+
98+
99+
$sql = <<<EOT
100+
UPDATE [dtl:article] AS a SET a.tags = ['one', 'two', 'three']
101+
EOT;
102+
$res = $this->parse($sql);
103+
104+
$res->offsetGet(0)->shouldHaveType('PHPCR\Query\QueryInterface');
105+
$res->offsetGet(1)->shouldReturn(array(
106+
array(
107+
'array_op' => null,
108+
'selector' => 'a',
109+
'name' => 'tags',
110+
'value' => array('one', 'two', 'three'),
111+
),
112+
));
113+
}
114+
115+
function it_should_parse_array_addition (
116+
QueryObjectModelFactoryInterface $qomf,
117+
ChildNodeJoinConditionInterface $joinCondition,
118+
JoinInterface $join,
119+
SourceInterface $source,
120+
PropertyValueInterface $tagsValue,
121+
LiteralInterface $literalValue,
122+
ComparisonInterface $comparison,
123+
QueryInterface $query
124+
)
125+
{
126+
$qomf->selector('a', 'dtl:article')->willReturn($source);
127+
$qomf->createQuery($source, null)->willReturn($query);
128+
129+
130+
$sql = <<<EOT
131+
UPDATE [dtl:article] AS a SET a.tags[] = 'asd'
132+
EOT;
133+
$res = $this->parse($sql);
134+
135+
$res->offsetGet(0)->shouldHaveType('PHPCR\Query\QueryInterface');
136+
$res->offsetGet(1)->shouldReturn(array(
137+
array(
138+
'array_op' => 'add',
139+
'selector' => 'a',
140+
'name' => 'tags',
141+
'value' => 'asd',
142+
),
143+
));
144+
}
81145
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class SessionApplication extends BaseApplication
1717
{
1818
const APP_NAME = 'PHPCRSH';
19-
const APP_VERSION = '1.0.0-alpha4';
19+
const APP_VERSION = '1.0.0-alpha5';
2020

2121
protected $shellApplication;
2222

0 commit comments

Comments
 (0)