Skip to content

Commit 73e1a4d

Browse files
committed
also support UUID's in the dump command
1 parent 1bd58ce commit 73e1a4d

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/PHPCR/Util/Console/Command/DumpCommand.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
namespace PHPCR\Util\Console\Command;
44

55
use Symfony\Component\Console\Command\Command;
6+
use PHPCR\ItemNotFoundException;
7+
use PHPCR\RepositoryException;
8+
use PHPCR\PathNotFoundException;
9+
use PHPCR\Util\UUIDHelper;
610
use Symfony\Component\Console\Input\InputArgument;
711
use Symfony\Component\Console\Input\InputOption;
812
use Symfony\Component\Console\Input\InputInterface;
@@ -31,7 +35,7 @@ protected function configure()
3135
->addOption('sys_nodes', null, InputOption::VALUE_OPTIONAL, 'Set to "yes" to dump the system nodes', "no")
3236
->addOption('props', null, InputOption::VALUE_OPTIONAL, 'Set to "yes" to dump the node properties', "no")
3337
->addOption('depth', null, InputOption::VALUE_OPTIONAL, 'Set to a number to limit how deep into the tree to recurse', "-1")
34-
->addArgument('path', InputArgument::OPTIONAL, 'Path of the node to dump', '/')
38+
->addArgument('identifier', InputArgument::OPTIONAL, 'Path or UUID of the node to dump', '/')
3539
->setDescription('Dump the content repository')
3640
->setHelp(<<<EOF
3741
The <info>dump</info> command recursively outputs the name of the node specified
@@ -67,7 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6771
{
6872
$session = $this->getHelper('phpcr')->getSession();
6973

70-
$path = $input->getArgument('path');
74+
$identifier = $input->getArgument('identifier');
7175

7276
$nodeVisitor = new ConsoleDumperNodeVisitor($output);
7377

@@ -84,14 +88,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
8488
$walker->addPropertyFilter($filter);
8589
}
8690

87-
if (!$session->nodeExists($path)) {
88-
$output->writeln("<error>Path '$path' does not exist</error>");
91+
try {
92+
$node = $session->getNodeByIdentifier($identifier);
93+
$walker->traverse($node, $input->getOption('depth'));
94+
} catch (RepositoryException $e) {
95+
if ($e instanceof PathNotFoundException || $e instanceof ItemNotFoundException) {
96+
$output->writeln("<error>Path '$identifier' does not exist</error>");
8997

90-
return 1;
98+
return 1;
99+
}
91100
}
92101

93-
$walker->traverse($session->getNode($path), $input->getOption('depth'));
94-
95102
return 0;
96103
}
97104

0 commit comments

Comments
 (0)