From e53b868a880bb4c270896e7b9f6cfcffa87f4490 Mon Sep 17 00:00:00 2001 From: dantleech Date: Thu, 25 Apr 2013 20:53:46 +0100 Subject: [PATCH 1/2] Added move command --- bin/phpcr | 1 + .../Util/Console/Command/MoveCommand.php | 75 +++++++++++++++++++ src/PHPCR/Util/PathHelper.php | 6 +- 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 src/PHPCR/Util/Console/Command/MoveCommand.php diff --git a/bin/phpcr b/bin/phpcr index 2a5db2e..8dc44a4 100755 --- a/bin/phpcr +++ b/bin/phpcr @@ -46,6 +46,7 @@ $cli->addCommands(array( new \PHPCR\Util\Console\Command\PurgeCommand(), new \PHPCR\Util\Console\Command\RegisterNodeTypesCommand(), new \PHPCR\Util\Console\Command\QueryCommand(), + new \PHPCR\Util\Console\Command\MoveCommand(), )); $cli->run(); diff --git a/src/PHPCR/Util/Console/Command/MoveCommand.php b/src/PHPCR/Util/Console/Command/MoveCommand.php new file mode 100644 index 0000000..5feea91 --- /dev/null +++ b/src/PHPCR/Util/Console/Command/MoveCommand.php @@ -0,0 +1,75 @@ + + */ +class MoveCommand extends Command +{ + /** + * {@inheritDoc} + */ + protected function configure() + { + $this + ->setName('phpcr:move') + ->addArgument('source', InputArgument::REQUIRED, 'Path of node to move') + ->addArgument('destination', InputArgument::REQUIRED, 'Destination for node') + ->setDescription('Moves a node from one path to another') + ->setHelp(<<getHelper('phpcr')->getSession(); + + $sourcePath = $input->getArgument('source'); + $destPath = $input->getArgument('destination'); + + $output->writeln(sprintf( + 'Moving %s to %s', + $sourcePath, $destPath + )); + + $session->move($sourcePath, $destPath); + $session->save(); + } + +} diff --git a/src/PHPCR/Util/PathHelper.php b/src/PHPCR/Util/PathHelper.php index 71473ef..63c34f2 100644 --- a/src/PHPCR/Util/PathHelper.php +++ b/src/PHPCR/Util/PathHelper.php @@ -140,10 +140,14 @@ public static function assertValidLocalName($name, $throw = true) */ public static function normalizePath($path, $destination = false, $throw = true) { - if (! is_string($path) || strlen($path) === 0) { + if (!is_string($path)) { throw new RepositoryException('Expected string but got ' . gettype($path)); } + if (strlen($path) === 0) { + throw new RepositoryException('Path must not be of zero length'); + } + if ('/' === $path) { return '/'; From 7b2a4dca34e36ad5c361218290150602f3d079c5 Mon Sep 17 00:00:00 2001 From: dantleech Date: Sun, 28 Apr 2013 19:42:12 +0100 Subject: [PATCH 2/2] Updated docs --- src/PHPCR/Util/Console/Command/MoveCommand.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/PHPCR/Util/Console/Command/MoveCommand.php b/src/PHPCR/Util/Console/Command/MoveCommand.php index 5feea91..ca77948 100644 --- a/src/PHPCR/Util/Console/Command/MoveCommand.php +++ b/src/PHPCR/Util/Console/Command/MoveCommand.php @@ -44,10 +44,13 @@ protected function configure() ->addArgument('destination', InputArgument::REQUIRED, 'Destination for node') ->setDescription('Moves a node from one path to another') ->setHelp(<<