|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace PHPCR\Shell\Console\Command; |
| 4 | + |
| 5 | +use Symfony\Component\Console\Command\Command; |
| 6 | +use Symfony\Component\Console\Input\InputInterface; |
| 7 | +use Symfony\Component\Console\Output\OutputInterface; |
| 8 | +use Symfony\Component\Console\Input\InputArgument; |
| 9 | +use PHPCR\Util\CND\Writer\CndWriter; |
| 10 | +use PHPCR\NodeType\NoSuchNodeTypeException; |
| 11 | +use PHPCR\Util\CND\Parser\CndParser; |
| 12 | +use PHPCR\NamespaceException; |
| 13 | + |
| 14 | +class NodeRenameCommand extends Command |
| 15 | +{ |
| 16 | + protected function configure() |
| 17 | + { |
| 18 | + $this->setName('node:rename'); |
| 19 | + $this->setDescription('Rename the node at the current path'); |
| 20 | + $this->addArgument('newName', null, InputArgument::REQUIRED, 'The name of the node to create'); |
| 21 | + $this->setHelp(<<<HERE |
| 22 | +Renames this node to the specified <info>newName</info>. The ordering (if any) of |
| 23 | +this node among it siblings remains unchanged. |
| 24 | +
|
| 25 | +This is a session-write method, meaning that the name change is |
| 26 | +dispatched upon <comment>session:save</comment>. |
| 27 | +
|
| 28 | +The <info>newName</info> provided must not have an index, otherwise a |
| 29 | +RepositoryException is thrown. |
| 30 | +
|
| 31 | +An ItemExistsException will be thrown either immediately, on dispatch |
| 32 | +(save, whether within or without transactions) or on persist (save |
| 33 | +without transactions, commit within a transaction), if there already |
| 34 | +exists a sibling item of this node with the specified name and |
| 35 | +same-name-siblings are not allowed. Implementations may differ on when |
| 36 | +this validation is performed. |
| 37 | +
|
| 38 | +A ConstraintViolationException will be thrown either immediately, on |
| 39 | +dispatch (save, whether within or without transactions) or on persist |
| 40 | +(save without transactions, commit within a transaction), if changing |
| 41 | +the name would violate a node type or implementation-specific |
| 42 | +constraint. Implementations may differ on when this validation is |
| 43 | +performed. |
| 44 | +
|
| 45 | +A VersionException will be thrown either immediately, on dispatch (save, |
| 46 | +whether within or without transactions) or on persist (save without |
| 47 | +transactions, commit within a transaction), if this node is read-only |
| 48 | +due to a checked-in node. Implementations may differ on when this |
| 49 | +validation is performed. |
| 50 | +
|
| 51 | +A LockException will be thrown either immediately, on dispatch (save, |
| 52 | +whether within or without transactions) or on persist (save without |
| 53 | +transactions, commit within a transaction), if a lock prevents the name |
| 54 | +change of the node. Implementations may differ on when this validation |
| 55 | +is performed. |
| 56 | +HERE |
| 57 | + ); |
| 58 | + } |
| 59 | + |
| 60 | + public function execute(InputInterface $input, OutputInterface $output) |
| 61 | + { |
| 62 | + $session = $this->getHelper('phpcr')->getSession(); |
| 63 | + $newName = $input->getArgument('newName'); |
| 64 | + $currentNode = $session->getCurrentNode(); |
| 65 | + $currentNode->rename($newName); |
| 66 | + } |
| 67 | +} |
0 commit comments