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..ca77948 --- /dev/null +++ b/src/PHPCR/Util/Console/Command/MoveCommand.php @@ -0,0 +1,78 @@ + + */ +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 '/';