Skip to content

Commit 3d24de1

Browse files
committed
Finalizing wildcard support
1 parent 00613ee commit 3d24de1

19 files changed

+217
-203
lines changed

features/phpcr_node_property_show.feature

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,23 @@ hello world
4141
Then the command should fail
4242
And I should see the following:
4343
"""
44-
Item at "/tests_general_base" is not a property
44+
Could not find property(s) at path
4545
"""
4646

4747
Scenario: Try to show non-existing property
4848
Given I execute the "node:property:show /this/path/does/not/exist" command
4949
Then the command should fail
5050
And I should see the following:
5151
"""
52-
There is no property at the path "/this/path/does/not/exist"
52+
Could not find property(s) at path
53+
"""
54+
55+
Scenario: Show properties using wildcard
56+
Given I execute the "node:property:show /tests_general_base/idExample/jcr:*" command
57+
Then the command should not fail
58+
And I should see the following:
59+
"""
60+
/tests_general_base/idExample/jcr:primaryType: nt:file
61+
/tests_general_base/idExample/jcr:createdBy: admin
62+
/tests_general_base/idExample/jcr:mixinTypes: [0] mix:referenceable
5363
"""

features/phpcr_node_remove.feature

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@ Feature: Remove a node
3232
You cannot delete the root node
3333
"""
3434

35+
Scenario: Delete root node by wildcard
36+
Given I execute the "node:remove /tests_general_base/*" command
37+
Then the command should not fail
38+
And I save the session
39+
And there should not exist a node at "/tests_general_base/daniel"

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ protected function registerEventListeners()
260260
*/
261261
private function configureFormatter(OutputFormatter $formatter)
262262
{
263+
$style = new OutputFormatterStyle('yellow', null, array('bold'));
264+
$formatter->setStyle('path', $style);
265+
266+
$style = new OutputFormatterStyle('green');
267+
$formatter->setStyle('localname', $style);
268+
263269
$style = new OutputFormatterStyle(null, null, array('bold'));
264270
$formatter->setStyle('node', $style);
265271

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ public function execute(InputInterface $input, OutputInterface $output)
3333
$workspace = $session->getWorkspace();
3434
$lockManager = $workspace->getLockManager();
3535

36-
$path = $session->getAbsPath($input->getArgument('path'));
36+
$path = $input->getArgument('path');
37+
$nodes = $session->findNodes($path);
3738

38-
$lock = $lockManager->getLock($path);
39-
$lock->refresh();
39+
foreach ($nodes as $node) {
40+
41+
$lock = $lockManager->getLock($node->getPath());
42+
$lock->refresh();
43+
}
4044
}
4145
}

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

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ protected function configure()
1515
$this->setDescription('Show information about the current node');
1616
$this->addArgument('path', InputArgument::REQUIRED, 'Path of node');
1717
$this->setHelp(<<<HERE
18-
Show information about the current node
18+
Show information about the node(s) at the given path:
19+
20+
PHPCRSH> node:info path/to/node
21+
22+
The path can include wildcards.
1923
HERE
2024
);
2125
}
@@ -25,48 +29,51 @@ public function execute(InputInterface $input, OutputInterface $output)
2529
$session = $this->getHelper('phpcr')->getSession();
2630
$path = $input->getArgument('path');
2731
$nodeHelper = $this->getHelper('node');
28-
$currentNode = $session->getNodeByPathOrIdentifier($path);
2932
$formatter = $this->getHelper('result_formatter');
3033

31-
$mixins = $currentNode->getMixinNodeTypes();
32-
$mixinNodeTypeNames = array();
34+
$nodes = $session->findNodes($path);
3335

34-
foreach ($mixins as $name => $mixin) {
35-
$mixinNodeTypeNames[] = $mixin->getName();
36-
}
36+
foreach ($nodes as $node) {
37+
$mixins = $node->getMixinNodeTypes();
38+
$mixinNodeTypeNames = array();
39+
40+
foreach ($mixins as $mixin) {
41+
$mixinNodeTypeNames[] = $mixin->getName();
42+
}
43+
44+
if ($nodeHelper->nodeHasMixinType($node, 'mix:versionable')) {
45+
try {
46+
$isCheckedOut = $node->isCheckedOut() ? 'yes' : 'no';
47+
} catch (\Exception $e) {
48+
$isCheckedOut = $formatter->formatException($e);
49+
}
50+
} else {
51+
$isCheckedOut = 'N/A';
52+
}
3753

38-
if ($nodeHelper->nodeHasMixinType($currentNode, 'mix:versionable')) {
3954
try {
40-
$isCheckedOut = $currentNode->isCheckedOut() ? 'yes' : 'no';
55+
$isLocked = $node->isLocked() ? 'yes' : 'no';
4156
} catch (\Exception $e) {
42-
$isCheckedOut = $formatter->formatException($e);
57+
$isLocked = $formatter->formatException($e);
4358
}
44-
} else {
45-
$isCheckedOut = 'N/A';
46-
}
4759

48-
try {
49-
$isLocked = $currentNode->isLocked() ? 'yes' : 'no';
50-
} catch (\Exception $e) {
51-
$isLocked = $formatter->formatException($e);
52-
}
60+
$info = array(
61+
'UUID' => $node->hasProperty('jcr:uuid') ? $node->getProperty('jcr:uuid')->getValue() : 'N/A',
62+
'Index' => $node->getIndex(),
63+
'Primary node type' => $node->getPrimaryNodeType()->getName(),
64+
'Mixin node types' => implode(', ', $mixinNodeTypeNames),
65+
'Checked out?' => $isCheckedOut,
66+
'Locked?' => $isLocked,
67+
);
5368

54-
$info = array(
55-
'Path' => $currentNode->getPath(),
56-
'UUID' => $currentNode->hasProperty('jcr:uuid') ? $currentNode->getProperty('jcr:uuid')->getValue() : 'N/A',
57-
'Index' => $currentNode->getIndex(),
58-
'Primary node type' => $currentNode->getPrimaryNodeType()->getName(),
59-
'Mixin node types' => implode(', ', $mixinNodeTypeNames),
60-
'Checked out?' => $isCheckedOut,
61-
'Locked?' => $isLocked,
62-
);
69+
$output->writeln('<path>' . $node->getPath() . '</path>');
70+
$table = $this->getHelper('table')->create();
6371

64-
$table = $this->getHelper('table')->create();
72+
foreach ($info as $label => $value) {
73+
$table->addRow(array($label, $value));
74+
}
6575

66-
foreach ($info as $label => $value) {
67-
$table->addRow(array($label, $value));
76+
$table->render($output);
6877
}
69-
70-
$table->render($output);
7178
}
7279
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ public function execute(InputInterface $input, OutputInterface $output)
5757

5858
$session = $this->getHelper('phpcr')->getSession();
5959
$path = $input->getArgument('path');
60-
$filter = null;
6160

6261
try {
6362
$nodes = array($session->getNodeByPathOrIdentifier($path));
63+
$filter = null;
6464
} catch (\Exception $e) {
6565
$parentPath = $this->getHelper('path')->getParentPath($path);
6666

@@ -83,7 +83,7 @@ public function execute(InputInterface $input, OutputInterface $output)
8383
$this->renderNode($node, $table, array(), $filter);
8484

8585
if ($table->getNumberOfRows() > 0) {
86-
$output->writeln('<info>' . $node->getPath() . '</info>');
86+
$output->writeln('<path>' . $node->getPath() . '</path>');
8787
$table->render($output);
8888
}
8989
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ class NodeMixinAddCommand extends Command
1212
protected function configure()
1313
{
1414
$this->setName('node:mixin:add');
15-
$this->setDescription('Add the named mixin to the node');
15+
$this->setDescription('Add the named mixin to the node (can include wildcards)');
1616
$this->addArgument('path', InputArgument::REQUIRED, 'Path of node');
1717
$this->addArgument('mixinName', InputArgument::REQUIRED, 'The name of the mixin node type to be added');
1818
$this->setHelp(<<<HERE
19-
Adds the mixin node type named <info>mixinName</info> to this node.
19+
Adds the mixin node type named <info>mixinName</info> to the node(s) inferred by the path.
2020
2121
If this node is already of type <info>mixinName</info> (either due to a previously
2222
added mixin or due to its primary type, through inheritance) then this
@@ -46,7 +46,11 @@ public function execute(InputInterface $input, OutputInterface $output)
4646
$session = $this->getHelper('phpcr')->getSession();
4747
$path = $input->getArgument('path');
4848
$mixinName = $input->getArgument('mixinName');
49-
$currentNode = $session->getNodeByPathOrIdentifier($path);
50-
$currentNode->addMixin($mixinName);
49+
50+
$nodes = $session->findNodes($path);
51+
52+
foreach ($nodes as $node) {
53+
$node->addMixin($mixinName);
54+
}
5155
}
5256
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ protected function configure()
1313
{
1414
$this->setName('node:mixin:remove');
1515
$this->setDescription('Remove the named mixin to the current node');
16-
$this->addArgument('path', InputArgument::REQUIRED, 'Path of node');
16+
$this->addArgument('path', InputArgument::REQUIRED, 'Path of node (can include wildcards)');
1717
$this->addArgument('mixinName', InputArgument::REQUIRED, 'The name of the mixin node type to be removeed');
1818
$this->setHelp(<<<HERE
1919
Removes the specified mixin node type from this node and removes
@@ -30,7 +30,11 @@ public function execute(InputInterface $input, OutputInterface $output)
3030
$session = $this->getHelper('phpcr')->getSession();
3131
$mixinName = $input->getArgument('mixinName');
3232
$path = $input->getArgument('path');
33-
$currentNode = $session->getNodeByPathOrIdentifier($path);
34-
$currentNode->removeMixin($mixinName);
33+
34+
$nodes = $session->findNodes($path);
35+
36+
foreach ($nodes as $node) {
37+
$node->removeMixin($mixinName);
38+
}
3539
}
3640
}

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ protected function configure()
1616
{
1717
$this->setName('node:property:set');
1818
$this->setDescription('Rename the node at the current path');
19-
$this->addArgument('path', InputArgument::REQUIRED, 'Path of property - can include the node name');
19+
$this->addArgument('path', InputArgument::REQUIRED, 'Path of property - parent path can include wildcards');
2020
$this->addArgument('value', InputArgument::OPTIONAL, 'Value for named property');
2121
$this->addOption('type', null, InputOption::VALUE_REQUIRED, 'Type of named property');
2222
$this->setHelp(<<<HERE
@@ -69,22 +69,25 @@ public function execute(InputInterface $input, OutputInterface $output)
6969

7070
$nodePath = $pathHelper->getParentPath($path);
7171
$propName = $pathHelper->getNodeName($path);
72-
$node = $session->getNode($nodePath);
73-
74-
$intType = null;
75-
76-
if ($type) {
77-
$intType = PropertyType::valueFromName($type);
78-
} else {
79-
try {
80-
$property = $node->getProperty($propName);
81-
$intType = $property->getType();
82-
} catch (PathNotFoundException $e) {
83-
// property doesn't exist and no type specified, default to string
84-
$intType = PropertyType::STRING;
72+
73+
$nodes = $session->findNodes($nodePath);
74+
75+
foreach ($nodes as $node) {
76+
$intType = null;
77+
78+
if ($type) {
79+
$intType = PropertyType::valueFromName($type);
80+
} else {
81+
try {
82+
$property = $node->getProperty($propName);
83+
$intType = $property->getType();
84+
} catch (PathNotFoundException $e) {
85+
// property doesn't exist and no type specified, default to string
86+
$intType = PropertyType::STRING;
87+
}
8588
}
86-
}
8789

88-
$node->setProperty($propName, $value, $intType);
90+
$node->setProperty($propName, $value, $intType);
91+
}
8992
}
9093
}

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

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class NodePropertyShowCommand extends Command
1414
protected function configure()
1515
{
1616
$this->setName('node:property:show');
17-
$this->setDescription('Show the property at the given absolute path');
18-
$this->addArgument('absPath', InputArgument::REQUIRED, 'Absolute path to property');
17+
$this->setDescription('Show the property at the given path');
18+
$this->addArgument('path', InputArgument::REQUIRED, 'Path to property (can include wildcards)');
1919
$this->setHelp(<<<HERE
2020
Show the property at the given absolute path
2121
HERE
@@ -25,25 +25,37 @@ protected function configure()
2525
public function execute(InputInterface $input, OutputInterface $output)
2626
{
2727
$session = $this->getHelper('phpcr')->getSession();
28-
$absPath = $session->getAbsPath($input->getArgument('absPath'));
28+
$path = $session->getAbsPath($input->getArgument('path'));
29+
$pathHelper = $this->getHelper('path');
2930
$resultFormatHelper = $this->getHelper('result_formatter');
3031

31-
try {
32-
$property = $session->getItem($absPath);
33-
} catch (PathNotFoundException $e) {
34-
throw new \Exception(sprintf(
35-
'There is no property at the path "%s"', $absPath
36-
));
37-
}
38-
39-
if (!$property instanceof PropertyInterface) {
40-
throw new \Exception(sprintf(
41-
'Item at "%s" is not a property.',
42-
$absPath
43-
));
32+
$parentPath = $pathHelper->getParentPath($path);
33+
$filter = $pathHelper->getNodeName($path);
34+
$nodes = $session->findNodes($parentPath);
4435

36+
if (0 === count($nodes)) {
37+
throw new \Exception('Could not find property(s) at path ' . $path);
4538
}
4639

47-
$output->writeln($resultFormatHelper->formatValue($property, true));
40+
foreach ($nodes as $node) {
41+
try {
42+
$properties = array($node->getProperty($filter));
43+
} catch (PathNotFoundException $e) {
44+
$properties = $node->getProperties($filter);
45+
}
46+
47+
if (0 === count($properties)) {
48+
throw new \Exception('Could not find property(s) at path ' . $path);
49+
}
50+
51+
foreach ($properties as $property) {
52+
$output->writeln(sprintf(
53+
'<path>%s/</path><localname>%s</localname>: %s',
54+
$pathHelper->getParentPath($property->getPath()),
55+
$pathHelper->getNodeName($property->getPath()),
56+
$resultFormatHelper->formatValue($property, true)
57+
));
58+
}
59+
}
4860
}
4961
}

0 commit comments

Comments
 (0)