|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * This file is part of the PHPCR Utils |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + * |
| 18 | + * @license http://www.apache.org/licenses/LICENSE-2.0 Apache Software License 2.0 |
| 19 | + * @link http://phpcr.github.com/ |
| 20 | + */ |
| 21 | + |
| 22 | +namespace PHPCR\Util\Console\Command; |
| 23 | + |
| 24 | +use Symfony\Component\Console\Command\Command; |
| 25 | +use Symfony\Component\Console\Input\InputArgument; |
| 26 | +use Symfony\Component\Console\Input\InputInterface; |
| 27 | +use Symfony\Component\Console\Output\OutputInterface; |
| 28 | + |
| 29 | +/** |
| 30 | + * Command to move a node from one path to another |
| 31 | + * |
| 32 | + * @author Daniel Leech <daniel@dantleech.com> |
| 33 | + */ |
| 34 | +class MoveCommand extends Command |
| 35 | +{ |
| 36 | + /** |
| 37 | + * {@inheritDoc} |
| 38 | + */ |
| 39 | + protected function configure() |
| 40 | + { |
| 41 | + $this |
| 42 | + ->setName('phpcr:move') |
| 43 | + ->addArgument('source', InputArgument::REQUIRED, 'Path of node to move') |
| 44 | + ->addArgument('destination', InputArgument::REQUIRED, 'Destination for node') |
| 45 | + ->setDescription('Moves a node from one path to another') |
| 46 | + ->setHelp(<<<EOF |
| 47 | +This command simply moves a node from one path (the source path) |
| 48 | +to another (the destination path), it can also be considered |
| 49 | +as a rename command. |
| 50 | +
|
| 51 | + $ php bin/phpcr phpcr:move /foobar /barfoo |
| 52 | +
|
| 53 | +Note that the parent node of the destination path must already exist. |
| 54 | +EOF |
| 55 | + ) |
| 56 | + ; |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * {@inheritDoc} |
| 61 | + */ |
| 62 | + protected function execute(InputInterface $input, OutputInterface $output) |
| 63 | + { |
| 64 | + $session = $this->getHelper('phpcr')->getSession(); |
| 65 | + |
| 66 | + $sourcePath = $input->getArgument('source'); |
| 67 | + $destPath = $input->getArgument('destination'); |
| 68 | + |
| 69 | + $output->writeln(sprintf( |
| 70 | + '<info>Moving </info>%s<info> to </info>%s', |
| 71 | + $sourcePath, $destPath |
| 72 | + )); |
| 73 | + |
| 74 | + $session->move($sourcePath, $destPath); |
| 75 | + $session->save(); |
| 76 | + } |
| 77 | + |
| 78 | +} |
0 commit comments