Skip to content

Wildcard support #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ php:
- 5.4

before_script:
- composer install --dev
- composer require "symfony/symfony" "2.6.*" --no-update
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid the deprecation errors..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- composer install
- bash tests/bin/travis_jackrabbit.sh

script:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ dev-master
----------

- [transport] Added transport layer for experimental Jackalope FS implementation
- [misc] Wildcard (single asterisk) support in paths
- [node] Added wilcard support to applicable node commands, including "node:list", "node:remove" and "node:property:show"
- [global] Refactored to use DI container and various general improvements
- [node:references] Shows the referencing node paths instead of the referrered-to node path(s)

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"symfony/finder": "~2.3",
"symfony/serializer": "~2.3",
"symfony/yaml": "~2.3",
"symfony/dependency-injection": "~2.3"
"symfony/dependency-injection": "~2.3",
"dantleech/glob-finder": "~0.1"
},
"minimum-stability": "dev",
"require-dev": {
Expand Down
1 change: 0 additions & 1 deletion features/all/phpcr_node_info.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Feature: Show information about node
And I should see the following:
"""
+-------------------+--------------------------------------+
| Path | /tests_general_base/daniel |
| UUID | N/A |
| Index | 1 |
| Primary node type | nt:unstructured |
Expand Down
59 changes: 59 additions & 0 deletions features/all/phpcr_node_list.feature
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,62 @@ Feature: List properites and chidren of current nodeA
"""
One or more weak reference targets have not been found
"""

Scenario: Wildcard on name
Given I execute the "node:list /tests_general_base/numberPropertyNode/jcr:con*" command
Then the command should not fail
And I should see the following:
"""
+-------------+-----------------+--+
| jcr:content | nt:unstructured | |
+-------------+-----------------+--+
"""

Scenario: Wildcard on directory
Given I execute the "node:list /tests_general_base/*/jcr:content" command
Then the command should not fail
And I should see the following:
"""
/tests_general_base/index.txt
+-------------+-----------------+--+
| jcr:content | nt:unstructured | |
+-------------+-----------------+--+
/tests_general_base/idExample
+--------------+-----------------+--+
| jcr:content/ | nt:unstructured | |
+--------------+-----------------+--+
/tests_general_base/numberPropertyNode
+-------------+-----------------+--+
| jcr:content | nt:unstructured | |
+-------------+-----------------+--+
/tests_general_base/NumberPropertyNodeToCompare1
+-------------+-----------------+--+
| jcr:content | nt:unstructured | |
+-------------+-----------------+--+
/tests_general_base/NumberPropertyNodeToCompare2
+-------------+-----------------+--+
| jcr:content | nt:unstructured | |
+-------------+-----------------+--+
"""

Scenario: Wildcard from relative path
Given the current node is "/tests_general_base"
And I execute the "node:list numberPropertyNode/jcr:con*" command
Then the command should not fail
And I should see the following:
"""
+-------------+-----------------+--+
| jcr:content | nt:unstructured | |
+-------------+-----------------+--+
"""

Scenario: Wildcard from relative path 2
Given the current node is "/tests_general_base"
And I execute the "node:list num*" command
Then the command should not fail
And I should see the following:
"""
+---------------------+---------+--------------+
| numberPropertyNode/ | nt:file | +jcr:content |
+---------------------+---------+--------------+
"""
12 changes: 10 additions & 2 deletions features/all/phpcr_node_property_show.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,21 @@ hello world
Then the command should fail
And I should see the following:
"""
Item at "/tests_general_base" is not a property
Could not find property(s) at path
"""

Scenario: Try to show non-existing property
Given I execute the "node:property:show /this/path/does/not/exist" command
Then the command should fail
And I should see the following:
"""
There is no property at the path "/this/path/does/not/exist"
Could not find property(s) at path
"""

Scenario: Show properties using wildcard
Given I execute the "node:property:show /tests_general_base/idExample/jcr:*" command
Then the command should not fail
And I should see the following:
"""
/tests_general_base/idExample/jcr:primaryType: nt:file
"""
5 changes: 5 additions & 0 deletions features/all/phpcr_node_remove.feature
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ Feature: Remove a node
You cannot delete the root node
"""

Scenario: Delete root node by wildcard
Given I execute the "node:remove /tests_general_base/*" command
Then the command should not fail
And I save the session
And there should not exist a node at "/tests_general_base/daniel"
10 changes: 8 additions & 2 deletions src/PHPCR/Shell/Console/Application/ShellApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;

use PHPCR\Shell\Console\Command\Phpcr as CommandPhpcr;
use PHPCR\Shell\Console\Command\Shell as CommandShell;
Expand All @@ -18,8 +20,6 @@
use PHPCR\Shell\Event\PhpcrShellEvents;
use PHPCR\Shell\Console\Command\Phpcr\PhpcrShellCommand;
use PHPCR\Shell\Config\Profile;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;

/**
* Main application for PHPCRSH
Expand Down Expand Up @@ -200,6 +200,12 @@ protected function registerShellCommands()
*/
private function configureFormatter(OutputFormatter $formatter)
{
$style = new OutputFormatterStyle('yellow', null, array('bold'));
$formatter->setStyle('path', $style);

$style = new OutputFormatterStyle('green');
$formatter->setStyle('localname', $style);

$style = new OutputFormatterStyle(null, null, array('bold'));
$formatter->setStyle('node', $style);

Expand Down
10 changes: 7 additions & 3 deletions src/PHPCR/Shell/Console/Command/Phpcr/LockRefreshCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ public function execute(InputInterface $input, OutputInterface $output)
$workspace = $session->getWorkspace();
$lockManager = $workspace->getLockManager();

$path = $session->getAbsPath($input->getArgument('path'));
$path = $input->getArgument('path');
$nodes = $session->findNodes($path);

$lock = $lockManager->getLock($path);
$lock->refresh();
foreach ($nodes as $node) {

$lock = $lockManager->getLock($node->getPath());
$lock->refresh();
}
}
}
71 changes: 39 additions & 32 deletions src/PHPCR/Shell/Console/Command/Phpcr/NodeInfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ protected function configure()
$this->setDescription('Show information about the current node');
$this->addArgument('path', InputArgument::REQUIRED, 'Path of node');
$this->setHelp(<<<HERE
Show information about the current node
Show information about the node(s) at the given path:

PHPCRSH> node:info path/to/node

The path can include wildcards.
HERE
);
}
Expand All @@ -24,48 +28,51 @@ public function execute(InputInterface $input, OutputInterface $output)
$session = $this->get('phpcr.session');
$path = $input->getArgument('path');
$nodeHelper = $this->get('helper.node');
$currentNode = $session->getNodeByPathOrIdentifier($path);
$formatter = $this->get('helper.result_formatter');

$mixins = $currentNode->getMixinNodeTypes();
$mixinNodeTypeNames = array();
$nodes = $session->findNodes($path);

foreach ($mixins as $name => $mixin) {
$mixinNodeTypeNames[] = $mixin->getName();
}
foreach ($nodes as $node) {
$mixins = $node->getMixinNodeTypes();
$mixinNodeTypeNames = array();

foreach ($mixins as $mixin) {
$mixinNodeTypeNames[] = $mixin->getName();
}

if ($nodeHelper->nodeHasMixinType($node, 'mix:versionable')) {
try {
$isCheckedOut = $node->isCheckedOut() ? 'yes' : 'no';
} catch (\Exception $e) {
$isCheckedOut = $formatter->formatException($e);
}
} else {
$isCheckedOut = 'N/A';
}

if ($nodeHelper->nodeHasMixinType($currentNode, 'mix:versionable')) {
try {
$isCheckedOut = $currentNode->isCheckedOut() ? 'yes' : 'no';
$isLocked = $node->isLocked() ? 'yes' : 'no';
} catch (\Exception $e) {
$isCheckedOut = $formatter->formatException($e);
$isLocked = $formatter->formatException($e);
}
} else {
$isCheckedOut = 'N/A';
}

try {
$isLocked = $currentNode->isLocked() ? 'yes' : 'no';
} catch (\Exception $e) {
$isLocked = $formatter->formatException($e);
}
$info = array(
'UUID' => $node->hasProperty('jcr:uuid') ? $node->getProperty('jcr:uuid')->getValue() : 'N/A',
'Index' => $node->getIndex(),
'Primary node type' => $node->getPrimaryNodeType()->getName(),
'Mixin node types' => implode(', ', $mixinNodeTypeNames),
'Checked out?' => $isCheckedOut,
'Locked?' => $isLocked,
);

$info = array(
'Path' => $currentNode->getPath(),
'UUID' => $currentNode->hasProperty('jcr:uuid') ? $currentNode->getProperty('jcr:uuid')->getValue() : 'N/A',
'Index' => $currentNode->getIndex(),
'Primary node type' => $currentNode->getPrimaryNodeType()->getName(),
'Mixin node types' => implode(', ', $mixinNodeTypeNames),
'Checked out?' => $isCheckedOut,
'Locked?' => $isLocked,
);
$output->writeln('<path>' . $node->getPath() . '</path>');
$table = $this->get('helper.table')->create();

$table = $this->get('helper.table')->create();
foreach ($info as $label => $value) {
$table->addRow(array($label, $value));
}

foreach ($info as $label => $value) {
$table->addRow(array($label, $value));
$table->render($output);
}

$table->render($output);
}
}
47 changes: 32 additions & 15 deletions src/PHPCR/Shell/Console/Command/Phpcr/NodeListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
class NodeListCommand extends BasePhpcrCommand
{
protected $formatter;
protected $filters;
protected $textHelper;
protected $maxLevel;

Expand All @@ -26,7 +25,6 @@ protected function configure()
$this->addArgument('path', InputArgument::OPTIONAL, 'Path of node', '.');
$this->addOption('children', null, InputOption::VALUE_NONE, 'List only the children of this node');
$this->addOption('properties', null, InputOption::VALUE_NONE, 'List only the properties of this node');
$this->addOption('filter', 'f', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Optional filter to apply');
$this->addOption('level', 'L', InputOption::VALUE_REQUIRED, 'Depth of tree to show');
$this->addOption('template', 't', InputOption::VALUE_NONE, 'Show template nodes and properties');
$this->setHelp(<<<HERE
Expand All @@ -37,10 +35,12 @@ protected function configure()
The <info>node:list</info> command can also shows template nodes and properties as defined a nodes node-type by
using the <info>--template</info> option. Template nodes and properties are prefixed with the "@" symbol.

The command accepts wither a path (relative or absolute) to the node or a UUID.
The command accepts either a path (relative or absolute) to the node, a UUID or a pattern:

PHPCRSH> node:list 842e61c0-09ab-42a9-87c0-308ccc90e6f4
PHPCRSH> node:list /tests/foobar
PHPCRSH> node:list /tests/*/foobar
PHPCRSH> node:list /tests/*/foo*
HERE
);
}
Expand All @@ -49,7 +49,6 @@ public function execute(InputInterface $input, OutputInterface $output)
{
$this->formatter = $this->get('helper.result_formatter');
$this->textHelper = $this->get('helper.text');
$this->filters = $input->getOption('filter');
$this->maxLevel = $input->getOption('level');

$this->showChildren = $input->getOption('children');
Expand All @@ -59,34 +58,52 @@ public function execute(InputInterface $input, OutputInterface $output)
$session = $this->get('phpcr.session');
$path = $input->getArgument('path');

$currentNode = $session->getNodeByPathOrIdentifier($path);
try {
$nodes = array($session->getNodeByPathOrIdentifier($path));
$filter = null;
} catch (\Exception $e) {
$parentPath = $this->get('helper.path')->getParentPath($path);

$filter = substr($path, strlen($parentPath));

if ($filter[0] == '/') {
$filter = substr($filter, 1);
}

$nodes = $session->findNodes($parentPath);
}

if (!$this->showChildren && !$this->showProperties) {
$this->showChildren = true;
$this->showProperties = true;
}

$table = $this->get('helper.table')->create();
foreach ($nodes as $node) {
$table = $this->get('helper.table')->create();
$this->renderNode($node, $table, array(), $filter);

$this->renderNode($currentNode, $table);
if ($table->getNumberOfRows() > 0) {
$output->writeln('<path>' . $node->getPath() . '</path>');
$table->render($output);
}
}

$table->render($output);
}

private function renderNode($currentNode, $table, $spacers = array())
private function renderNode($currentNode, $table, $spacers = array(), $filter = null)
{
if ($this->showChildren) {
$this->renderChildren($currentNode, $table, $spacers);
$this->renderChildren($currentNode, $table, $spacers, $filter);
}

if ($this->showProperties) {
$this->renderProperties($currentNode, $table, $spacers);
$this->renderProperties($currentNode, $table, $spacers, $filter);
}
}

private function renderChildren($currentNode, $table, $spacers)
private function renderChildren($currentNode, $table, $spacers, $filter = null)
{
$children = $currentNode->getNodes($this->filters ? : null);
$children = $currentNode->getNodes($filter ? : null);

$nodeType = $currentNode->getPrimaryNodeType();
$childNodeDefinitions = $nodeType->getDeclaredChildNodeDefinitions();
Expand Down Expand Up @@ -147,9 +164,9 @@ private function renderChildren($currentNode, $table, $spacers)
}
}

private function renderProperties($currentNode, $table, $spacers)
private function renderProperties($currentNode, $table, $spacers, $filter = null)
{
$properties = $currentNode->getProperties($this->filters ? : null);
$properties = $currentNode->getProperties($filter ? : null);

try {
$primaryItem = $currentNode->getPrimaryItem();
Expand Down
Loading