Skip to content

Commit a7876a9

Browse files
committed
Merge pull request #124 from phpcr/reference_by_path
Allow referencing by path
2 parents 1818f3a + 2a16682 commit a7876a9

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dev-master
1212

1313
- [cli] Specify workspace with first argument
1414
- [global] Refactored to use DI container and various general improvements
15+
- [node:property:set] Allow setting reference property type by path
1516
- [references] Show UUIDs when listing reference properties
1617
- [import/export] Renamed session import and export to `session:import` &
1718
`session:export`

features/all/phpcr_node_property_set.feature

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ Feature: Set a node property
1212
Given I execute the "<command>" command
1313
Then the command should not fail
1414
And I save the session
15+
Then the node at "/properties" should have the property "<name>" with value "<value>"
1516
Examples:
16-
| command | name | type |
17-
| node:property:set uri http://foobar | uri | http://foobar |
18-
| node:property:set double 12.12 --type=double | double | 12.12 |
19-
| node:property:set long 123 | long | 123 |
20-
| node:property:set thisisnew foobar --type=string | /properties/thisisnew | foobar |
17+
| command | name | type | value |
18+
| node:property:set uri http://foobar | uri | uri | http://foobar |
19+
| node:property:set double 12.12 --type=double | double | double | 12.12 |
20+
| node:property:set long 123 | long | long | 123 |
21+
| node:property:set thisisnew foobar --type=string | thisisnew | string | foobar |
22+
| node:property:set fooref /properties/reference_target --type=reference | fooref | string | 13543fc6-1abf-4708-bfcc-e49511754b40 |
23+
| node:property:set fooref /properties/reference_target --type=weakreference | fooref | string | 13543fc6-1abf-4708-bfcc-e49511754b40 |
24+
| node:property:set fooref 13543fc6-1abf-4708-bfcc-e49511754b40 --type=weakreference | fooref | string | 13543fc6-1abf-4708-bfcc-e49511754b40 |
2125

2226
Scenario: Update a property but do not specify the type
2327
Given I execute the "node:property:set /properties/decimal 1234" command

src/PHPCR/Shell/Console/Command/Phpcr/NodePropertySetCommand.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Symfony\Component\Console\Input\InputOption;
1010
use PHPCR\PropertyType;
1111
use PHPCR\PathNotFoundException;
12+
use PHPCR\Util\UUIDHelper;
1213

1314
class NodePropertySetCommand extends BasePhpcrCommand
1415
{
@@ -77,6 +78,26 @@ public function execute(InputInterface $input, OutputInterface $output)
7778

7879
if ($type) {
7980
$intType = PropertyType::valueFromName($type);
81+
82+
if ($intType === PropertyType::REFERENCE || $intType === PropertyType::WEAKREFERENCE) {
83+
84+
// convert path to UUID
85+
if (false === UUIDHelper::isUuid($value)) {
86+
$path = $value;
87+
try {
88+
$targetNode = $session->getNode($path);
89+
$value = $targetNode->getIdentifier();
90+
} catch (PathNotFoundException $e) {
91+
}
92+
93+
if (null === $value) {
94+
throw new \InvalidArgumentException(sprintf(
95+
'Node at path "%s" specified for reference is not referenceable',
96+
$path
97+
));
98+
}
99+
}
100+
}
80101
} else {
81102
try {
82103
$property = $node->getProperty($propName);

src/PHPCR/Shell/Test/ContextBase.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PHPCR\PropertyType;
1313
use Behat\Behat\Context\SnippetAcceptingContext;
1414
use Behat\Behat\Context\Context;
15+
use PHPCR\NodeInterface;
1516

1617
use Behat\Behat\Context\ClosuredContextInterface,
1718
Behat\Behat\Context\TranslatedContextInterface,
@@ -718,8 +719,13 @@ public function theNodeAtShouldHaveThePropertyWithValue($arg1, $arg2, $arg3)
718719
$session = $this->getSession();
719720
$node = $session->getNode($arg1);
720721
$property = $node->getProperty($arg2);
721-
$propertyType = $property->getValue();
722-
\PHPUnit_Framework_Assert::assertEquals($arg3, $propertyType);
722+
$propertyValue = $property->getValue();
723+
724+
if ($propertyValue instanceof NodeInterface) {
725+
$propertyValue = $propertyValue->getIdentifier();
726+
}
727+
728+
\PHPUnit_Framework_Assert::assertEquals($arg3, $propertyValue);
723729
}
724730

725731
/**

0 commit comments

Comments
 (0)