Skip to content

Commit e040c53

Browse files
committed
Fixed update
1 parent 71468cb commit e040c53

File tree

2 files changed

+6
-29
lines changed

2 files changed

+6
-29
lines changed

features/phpcr_query_update.feature

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ Feature: Execute a a raw UPDATE query in JCR_SQL2
3232
And the node at "/cms/articles/article1" should have the property "tags" with value "Rockets" at index "1"
3333

3434
Scenario: Set a multivalue value
35-
Given I execute the "UPDATE [nt:unstructured] AS a SET a.tags = array('Rockets', 'Dragons') WHERE a.tags = 'Trains'" command
35+
Given I execute the "UPDATE [nt:unstructured] AS a SET a.tags = array('Rockets', 'Dragons')" command
36+
Then the command should not fail
3637
And I save the session
3738
Then the command should not fail
3839
And the node at "/cms/articles/article1" should have the property "tags" with value "Rockets" at index "0"

src/PHPCR/Shell/Query/UpdateProcessor.php

+4-28
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function __construct()
4444
'array_append' => function ($operand, $v, $x) {
4545
$operand->validateScalarArray($v);
4646
$v[] = $x;
47+
4748
return $v;
4849
},
4950
'array' => function () {
@@ -85,45 +86,20 @@ public function __construct()
8586
public function updateNode(RowInterface $row, $propertyData)
8687
{
8788
$node = $row->getNode($propertyData['selector']);
88-
89-
if ($node->hasProperty($propertyData['name'])) {
90-
$value = $this->handleExisting($row, $node, $propertyData);
91-
} else {
92-
$value = $propertyData['value'];
93-
}
94-
95-
$node->setProperty($propertyData['name'], $value);
96-
}
97-
98-
private function handleExisting($row, $node, $propertyData)
99-
{
100-
$phpcrProperty = $node->getProperty($propertyData['name']);
10189
$value = $propertyData['value'];
10290

10391
if ($value instanceof FunctionOperand) {
104-
return $this->handleFunction($row, $node, $phpcrProperty, $propertyData);
92+
$value = $this->handleFunction($row, $propertyData);
10593
}
10694

107-
return $value;
95+
$node->setProperty($propertyData['name'], $value);
10896
}
10997

110-
private function handleFunction($row, $node, $phpcrProperty, $propertyData)
98+
private function handleFunction($row, $propertyData)
11199
{
112-
$currentValue = $phpcrProperty->getValue();
113100
$value = $propertyData['value'];
114-
115101
$value = $value->execute($this->functionMap, $row);
116102

117-
if ($phpcrProperty->isMultiple()) {
118-
// do not allow updating multivalue with scalar
119-
if (false === is_array($value) && sizeof($currentValue) > 1) {
120-
throw new \InvalidArgumentException(sprintf(
121-
'<error>Cannot update multivalue property "%s" with a scalar value.</error>',
122-
$phpcrProperty->getName()
123-
));
124-
}
125-
}
126-
127103
return $value;
128104
}
129105
}

0 commit comments

Comments
 (0)