Skip to content

Commit 9d3aee9

Browse files
committed
Merge pull request #153 from phpcr/various_fixes
Various fixes
2 parents 0f42bea + e804276 commit 9d3aee9

16 files changed

+102
-88
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ dev-master
1616
- [embedded] No exit code returned
1717
- [profile] Profile configuration overwritten by session parameters
1818
- [node:list] Incorrect node count
19+
- [node:list] Single references not showing path
20+
- [node:edit] Multivalue references encoded as arrays when editing
21+
- [node:edit] Fixed undefined variable
22+
- [version] Versioning commands can use relative paths
23+
- [node:property:show] Text fields are truncated
24+
- [profile] Workspace given from CLI does not override profile workspace
1925

2026
beta1
2127
-----

features/all/phpcr_version_history.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ Feature: Node Version History
77
Given that I am logged in as "testuser"
88
And the "versionable.xml" fixtures are loaded
99

10-
Scenario: Checkout a a given node
11-
Given I execute the "version:history /tests_version_base/versioned" command
10+
Scenario: Show history for a node
11+
When I execute the "version:history /tests_version_base/versioned" command
1212
Then the command should not fail
1313
And I should see a table containing the following rows:
1414
| Name | Created |
1515

1616
Scenario: History on a non versionable node
17-
Given I execute the "version:history /tests_version_base" command
17+
When I execute the "version:history /tests_version_base" command
1818
Then the command should fail
1919
And I should see the following:
2020
"""

features/all/phpcr_version_remove.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Feature: Remove node version
88
And the "versionable.xml" fixtures are loaded
99

1010
Scenario: Checkout a a given node
11-
Given I execute the following commands:
11+
When I execute the following commands:
1212
| cd /tests_version_base/versioned |
1313
| version:checkout /tests_version_base/versioned |
1414
| node:property:set foo baz |
@@ -21,7 +21,7 @@ Feature: Remove node version
2121
And I execute the "version:remove /tests_version_base/versioned 1.0" command
2222
Then the command should not fail
2323
And I execute the "version:history /tests_version_base/versioned" command
24-
Then I should not see the following:
24+
And I should not see the following:
2525
"""
2626
| 1.0 |
2727
"""

features/all/phpcr_version_restore.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Feature: Restore a version
88
And the "versionable.xml" fixtures are loaded
99

1010
Scenario: Restore node version
11-
Given I execute the following commands:
11+
When I execute the following commands:
1212
| cd /tests_version_base/versioned |
1313
| node:property:set foo initalbar |
1414
| session:save |

spec/PHPCR/Shell/Config/ProfileLoaderSpec.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function it_should_load_data_into_a_given_profile(
4545
Filesystem $filesystem
4646
)
4747
{
48+
$profile->get('phpcr', 'workspace')->willReturn('default');
4849
$profile->getName()->willReturn('one');
4950
$profile->set('transport', array(
5051
'name' => 'foobar',

src/PHPCR/Shell/Config/ProfileLoader.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,15 @@ public function loadProfile(Profile $profile)
8080
$profile->set('transport', $data['transport']);
8181
}
8282

83+
$profileWorkspace = $profile->get('phpcr', 'workspace');
8384
if (isset($data['phpcr'])) {
8485
$profile->set('phpcr', $data['phpcr']);
8586
}
87+
88+
// workspace argument overrides profile workspace
89+
if ($profileWorkspace && $profileWorkspace !== 'default') {
90+
$profile->set('phpcr', 'workspace', $profileWorkspace);
91+
}
8692
}
8793

8894
public function saveProfile(Profile $profile, $overwrite = false)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public function execute(InputInterface $input, OutputInterface $output)
4545
$srcWorkspace = $input->getArgument('srcWorkspace');
4646

4747
$workspace = $session->getWorkspace();
48-
4948
$workspace->copy($srcAbsPath, $destAbsPath, $srcWorkspace);
5049
}
5150
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ public function execute(InputInterface $input, OutputInterface $output)
5858

5959
foreach ($properties as $property) {
6060
$output->writeln(sprintf(
61-
'<path>%s/</path><localname>%s</localname>: %s',
62-
$pathHelper->getParentPath($property->getPath()),
61+
'<path>%s%s</path><localname>%s</localname>: %s',
62+
$parentPath = $pathHelper->getParentPath($property->getPath()),
63+
$parentPath != '/' ? '/' : '',
6364
$pathHelper->getNodeName($property->getPath()),
64-
$resultFormatHelper->formatValue($property, true)
65+
$resultFormatHelper->formatValue($property, true, false)
6566
));
6667
}
6768
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function execute(InputInterface $input, OutputInterface $output)
6868
$node = $session->getNodeByPathOrIdentifier($path);
6969
$nodeHelper->assertNodeIsVersionable($node);
7070

71-
$version = $versionManager->checkin($path);
71+
$version = $versionManager->checkin($node->getPath());
7272

7373
$output->writeln('Version: ' . $version->getName());
7474
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ public function execute(InputInterface $input, OutputInterface $output)
5454
$nodeHelper->assertNodeIsVersionable($node);
5555

5656
$versionManager = $workspace->getVersionManager();
57-
$version = $versionManager->checkout($absPath);
57+
$version = $versionManager->checkout($node->getPath());
5858
}
5959
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function execute(InputInterface $input, OutputInterface $output)
4343
$node = $session->getNodeByPathOrIdentifier($path);
4444
$nodeHelper->assertNodeIsVersionable($node);
4545
$versionManager = $workspace->getVersionManager();
46-
$version = $versionManager->checkpoint($path);
46+
$version = $versionManager->checkpoint($node->getPath());
4747

4848
$output->writeln('Version: ' . $version->getName());
4949
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ public function execute(InputInterface $input, OutputInterface $output)
4040
$workspace = $session->getWorkspace();
4141

4242
$node = $session->getNodeByPathOrIdentifier($path);
43+
4344
$nodeHelper->assertNodeIsVersionable($node);
4445
$versionManager = $workspace->getVersionManager();
45-
$history = $versionManager->getVersionHistory($path);
46+
$history = $versionManager->getVersionHistory($node->getPath());
4647

4748
$versions = $history->getAllVersions();
4849

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,17 @@ protected function configure()
4848
public function execute(InputInterface $input, OutputInterface $output)
4949
{
5050
$session = $this->get('phpcr.session');
51+
$nodeHelper = $this->get('helper.node');
52+
$path = $input->getArgument('path');
5153

5254
$versionName = $input->getArgument('versionName');
53-
$path = $session->getAbsPath($input->getArgument('path'));
55+
$node = $session->getNodeByPathOrIdentifier($path);
56+
$nodeHelper->assertNodeIsVersionable($node);
57+
5458
$workspace = $session->getWorkspace();
5559
$versionManager = $workspace->getVersionManager();
5660

57-
$history = $versionManager->getVersionHistory($path);
61+
$history = $versionManager->getVersionHistory($node->getPath());
5862
$history->removeVersion($versionName);
5963
}
6064
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@ protected function configure()
4242
public function execute(InputInterface $input, OutputInterface $output)
4343
{
4444
$session = $this->get('phpcr.session');
45+
$nodeHelper = $this->get('helper.node');
46+
$path = $input->getArgument('path');
47+
48+
$node = $session->getNodeByPathOrIdentifier($path);
49+
$nodeHelper->assertNodeIsVersionable($node);
4550

46-
$path = $session->getAbsPath($input->getArgument('path'));
4751
$versionName = $input->getArgument('versionName');
4852
$removeExisting = $input->getOption('remove-existing');
4953
$workspace = $session->getWorkspace();
5054
$versionManager = $workspace->getVersionManager();
51-
$versionManager->restore($removeExisting, $versionName, $path);
55+
$versionManager->restore($removeExisting, $versionName, $node->getPath());
5256
}
5357
}

src/PHPCR/Shell/Console/Helper/ResultFormatterHelper.php

Lines changed: 57 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function formatQueryResult(QueryResultInterface $result, OutputInterface
7979
), $row->getValues());
8080

8181
foreach ($values as &$value) {
82-
$value = $this->normalizeValue($value);
82+
$value = $this->textHelper->truncate($value, 255);
8383
}
8484

8585
$table->addRow($values);
@@ -96,81 +96,69 @@ public function formatQueryResult(QueryResultInterface $result, OutputInterface
9696
}
9797
}
9898

99-
public function normalizeValue($value)
99+
public function formatValue(PropertyInterface $property, $showBinary = false, $truncate = true)
100100
{
101-
if (is_array($value)) {
102-
if (empty($value)) {
103-
return '';
104-
}
105-
$array = $value;
106-
$values = array();
107-
108-
foreach ($array as $i => $value) {
109-
if ($value instanceof NodeInterface) {
110-
$uuid = $value->getIdentifier();
111-
$value = $value->getPath();
112-
if ($uuid) {
113-
$value .= ' (' . $uuid . ')';
114-
}
115-
} elseif (is_object($value)) {
116-
$value = '<UNKNOWN OBJECT>';
117-
} else {
118-
$value = $value;
119-
}
120-
$value = '[' . $i . '] ' . $this->textHelper->truncate($value, 255);
121-
$values[] = $value;
122-
}
123-
124-
return implode("\n", $values);
101+
$values = $property->getValue();
102+
if (false === $property->isMultiple()) {
103+
$values = array($values);
125104
}
105+
$return = array();
106+
107+
foreach ($values as $value) {
108+
switch (intval($property->getType())) {
109+
case PropertyType::UNDEFINED :
110+
$return[] = '#UNDEFINED#';
111+
case PropertyType::BINARY :
112+
if ($showBinary) {
113+
$lines = array();
114+
$pointer = $value;
115+
while (($line = fgets($pointer)) !== false) {
116+
$lines[] = $line;
117+
}
118+
119+
$return[] = implode('', $lines);
120+
break;
121+
}
126122

127-
if ($value instanceof \DateTime) {
128-
return $value->format('c');
123+
return '(binary data)';
124+
case PropertyType::BOOLEAN :
125+
$return[] = $value ? 'true' : 'false';
126+
break;
127+
case PropertyType::DATE :
128+
$return[] = $value->format('c');
129+
break;
130+
case PropertyType::REFERENCE :
131+
case PropertyType::WEAKREFERENCE :
132+
$return[] = sprintf(
133+
'%s (%s)',
134+
$this->textHelper->truncate($value->getPath(), 255),
135+
$value->getIdentifier()
136+
);
137+
break;
138+
case PropertyType::URI :
139+
case PropertyType::STRING :
140+
$return[] = $truncate ? $this->textHelper->truncate($value) : $value;
141+
break;
142+
case PropertyType::NAME :
143+
case PropertyType::LONG :
144+
case PropertyType::DOUBLE :
145+
case PropertyType::DECIMAL :
146+
case PropertyType::PATH :
147+
$return[] = $value;
148+
break;
149+
default:
150+
throw new \RuntimeException('Unknown type ' . $property->getType());
151+
}
129152
}
130153

131-
return $this->textHelper->truncate($value);
132-
}
133-
134-
public function formatValue(PropertyInterface $value, $showBinary = false)
135-
{
136-
if (is_array($value->getValue())) {
137-
return $this->normalizeValue($value->getValue());
154+
if ($property->isMultiple()) {
155+
return implode("\n", array_map(function ($value) {
156+
static $index = 0;
157+
return sprintf('<comment>[%d]</comment> %s', $index++, $value);
158+
}, $return));
138159
}
139160

140-
switch (intval($value->getType())) {
141-
case PropertyType::UNDEFINED :
142-
return '#UNDEFINED#';
143-
case PropertyType::BINARY :
144-
if ($showBinary) {
145-
$lines = array();
146-
$pointer = $value->getValue();
147-
while (($line = fgets($pointer)) !== false) {
148-
$lines[] = $line;
149-
}
150-
151-
return implode('', $lines);
152-
}
153-
154-
return '(binary data)';
155-
case PropertyType::BOOLEAN :
156-
return $value->getValue() ? 'true' : 'false';
157-
case PropertyType::DATE :
158-
return $value->getValue()->format('c');
159-
case PropertyType::REFERENCE :
160-
case PropertyType::WEAKREFERENCE :
161-
return $value->getValue()->getIdentifier();
162-
case PropertyType::URI :
163-
case PropertyType::STRING :
164-
return $this->textHelper->truncate($value->getValue());
165-
case PropertyType::NAME :
166-
case PropertyType::LONG :
167-
case PropertyType::DOUBLE :
168-
case PropertyType::DECIMAL :
169-
case PropertyType::PATH :
170-
return $value->getValue();
171-
default:
172-
throw new \RuntimeException('Unknown type ' . $value->getType());
173-
}
161+
return implode("\n", $return);
174162
}
175163

176164
public function formatNodePropertiesInline(NodeInterface $node)

src/PHPCR/Shell/Serializer/NodeNormalizer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function normalize($node, $format = null, array $context = array())
5656
$propertyName = $property->getName();
5757

5858
if (in_array($property->getType(), array(PropertyType::REFERENCE, PropertyType::WEAKREFERENCE))) {
59-
$nodesUuids = array();
59+
$nodeUuids = array();
6060

6161
if (false === is_array($propertyValue)) {
6262
$propertyValue = array($propertyValue);
@@ -66,6 +66,10 @@ public function normalize($node, $format = null, array $context = array())
6666
$nodeUuids[] = $node->getIdentifier();
6767
}
6868
$propertyValue = $nodeUuids;
69+
70+
if (false === $property->isMultiple()) {
71+
$propertyValue = reset($propertyValue);
72+
}
6973
}
7074

7175
$res[$propertyName] = array(

0 commit comments

Comments
 (0)