diff --git a/bin/phpcr b/bin/phpcr index 26a7da3..3e29861 100755 --- a/bin/phpcr +++ b/bin/phpcr @@ -40,15 +40,17 @@ $cli = new \Symfony\Component\Console\Application('PHPCR Command Line Interface' $cli->setCatchExceptions(true); $cli->setHelperSet($helperSet); $cli->addCommands(array( - new \PHPCR\Util\Console\Command\CreateWorkspaceCommand(), - new \PHPCR\Util\Console\Command\ImportXmlCommand(), - new \PHPCR\Util\Console\Command\DumpCommand(), - new \PHPCR\Util\Console\Command\PurgeCommand(), - new \PHPCR\Util\Console\Command\RegisterNodeTypesCommand(), - new \PHPCR\Util\Console\Command\ListNodeTypesCommand(), - new \PHPCR\Util\Console\Command\QueryCommand(), - new \PHPCR\Util\Console\Command\MoveCommand(), - new \PHPCR\Util\Console\Command\TouchCommand(), + new \PHPCR\Util\Console\Command\NodeDumpCommand(), + new \PHPCR\Util\Console\Command\NodeMoveCommand(), + new \PHPCR\Util\Console\Command\NodeRemoveCommand(), + new \PHPCR\Util\Console\Command\NodeTouchCommand(), + new \PHPCR\Util\Console\Command\NodeTypeListCommand(), + new \PHPCR\Util\Console\Command\NodeTypeRegisterCommand(), + new \PHPCR\Util\Console\Command\WorkspaceCreateCommand(), + new \PHPCR\Util\Console\Command\WorkspaceExportCommand(), + new \PHPCR\Util\Console\Command\WorkspaceImportCommand(), + new \PHPCR\Util\Console\Command\WorkspacePurgeCommand(), + new \PHPCR\Util\Console\Command\WorkspaceQueryCommand(), )); $cli->run(); diff --git a/src/PHPCR/Util/Console/Command/DumpCommand.php b/src/PHPCR/Util/Console/Command/NodeDumpCommand.php similarity index 98% rename from src/PHPCR/Util/Console/Command/DumpCommand.php rename to src/PHPCR/Util/Console/Command/NodeDumpCommand.php index 72ed67d..2fc8f36 100644 --- a/src/PHPCR/Util/Console/Command/DumpCommand.php +++ b/src/PHPCR/Util/Console/Command/NodeDumpCommand.php @@ -41,7 +41,7 @@ * * @author Daniel Barsotti */ -class DumpCommand extends Command +class NodeDumpCommand extends Command { /** * Limit after which to cut lines when dumping properties @@ -56,7 +56,7 @@ class DumpCommand extends Command protected function configure() { $this - ->setName('phpcr:dump') + ->setName('phpcr:node:dump') ->addOption('sys_nodes', null, InputOption::VALUE_NONE, 'Use to dump the system nodes') ->addOption('props', null, InputOption::VALUE_NONE, 'Use to dump the node properties') ->addOption('depth', null, InputOption::VALUE_OPTIONAL, 'Set to a number to limit how deep into the tree to recurse', "-1") diff --git a/src/PHPCR/Util/Console/Command/MoveCommand.php b/src/PHPCR/Util/Console/Command/NodeMoveCommand.php similarity index 96% rename from src/PHPCR/Util/Console/Command/MoveCommand.php rename to src/PHPCR/Util/Console/Command/NodeMoveCommand.php index ca77948..4db966a 100644 --- a/src/PHPCR/Util/Console/Command/MoveCommand.php +++ b/src/PHPCR/Util/Console/Command/NodeMoveCommand.php @@ -31,7 +31,7 @@ * * @author Daniel Leech */ -class MoveCommand extends Command +class NodeMoveCommand extends Command { /** * {@inheritDoc} @@ -39,7 +39,7 @@ class MoveCommand extends Command protected function configure() { $this - ->setName('phpcr:move') + ->setName('phpcr:node: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') diff --git a/src/PHPCR/Util/Console/Command/PurgeCommand.php b/src/PHPCR/Util/Console/Command/NodeRemoveCommand.php similarity index 84% rename from src/PHPCR/Util/Console/Command/PurgeCommand.php rename to src/PHPCR/Util/Console/Command/NodeRemoveCommand.php index 1f3f300..ffc6288 100644 --- a/src/PHPCR/Util/Console/Command/PurgeCommand.php +++ b/src/PHPCR/Util/Console/Command/NodeRemoveCommand.php @@ -36,7 +36,7 @@ * * @author Daniel Barsotti */ -class PurgeCommand extends Command +class NodeRemoveCommand extends Command { /** * {@inheritDoc} @@ -46,13 +46,22 @@ protected function configure() parent::configure(); $this - ->setName('phpcr:purge') + ->setName('phpcr:node:remove') ->setDescription('Remove content from the repository') ->addArgument('path', InputArgument::OPTIONAL, 'Path of the node to purge', '/') ->addOption('force', null, InputOption::VALUE_NONE, 'Use to bypass the confirmation dialog') ->addOption('only-children', null, InputOption::VALUE_NONE, 'Use to only purge children of specified path') ->setHelp(<<phpcr:purge command remove all the non-standard nodes from the content repository +The phpcr:node:remove command will remove the given node or the +children of the given node according to the options given. + +Remove specified node and its children: + + $ php bin/phpcr phpcr:node:remove /cms/content/blog + +Remove only the children of the specified node + + $ php bin/phpcr phpcr:node:remove /cms/content/blog --only-children EOF ) ; @@ -89,7 +98,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } if ($force) { - $message = '> Purging: %s'; + $message = '> Purging: %s'; if ($onlyChildren) { $baseNode = $session->getNode($path, 0); @@ -102,7 +111,10 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln(sprintf($message, $path)); if ('/' === $path) { - NodeHelper::purgeWorkspace($this->getHelper('phpcr')->getSession()); + throw new \Exception( + 'Will not purge path entire workspace ("/"), use the '. + 'workspace:purge method instead.' + ); } else { $session->removeItem($path); } diff --git a/src/PHPCR/Util/Console/Command/TouchCommand.php b/src/PHPCR/Util/Console/Command/NodeTouchCommand.php similarity index 98% rename from src/PHPCR/Util/Console/Command/TouchCommand.php rename to src/PHPCR/Util/Console/Command/NodeTouchCommand.php index 57d0fc9..b09c0ab 100644 --- a/src/PHPCR/Util/Console/Command/TouchCommand.php +++ b/src/PHPCR/Util/Console/Command/NodeTouchCommand.php @@ -34,7 +34,7 @@ * * @author Daniel Leech */ -class TouchCommand extends Command +class NodeTouchCommand extends Command { /** * {@inheritDoc} @@ -43,7 +43,7 @@ protected function configure() { parent::configure(); - $this->setName('phpcr:touch') + $this->setName('phpcr:node:touch') ->addArgument( 'path', InputArgument::REQUIRED, diff --git a/src/PHPCR/Util/Console/Command/ListNodeTypesCommand.php b/src/PHPCR/Util/Console/Command/NodeTypeListCommand.php similarity index 96% rename from src/PHPCR/Util/Console/Command/ListNodeTypesCommand.php rename to src/PHPCR/Util/Console/Command/NodeTypeListCommand.php index 7c5c090..8bace82 100644 --- a/src/PHPCR/Util/Console/Command/ListNodeTypesCommand.php +++ b/src/PHPCR/Util/Console/Command/NodeTypeListCommand.php @@ -30,7 +30,7 @@ * * @author Daniel Leech */ -class ListNodeTypesCommand extends Command +class NodeTypeListCommand extends Command { /** * {@inheritDoc} @@ -38,7 +38,7 @@ class ListNodeTypesCommand extends Command protected function configure() { $this - ->setName('phpcr:type:list') + ->setName('phpcr:node-type:list') ->setDescription('List all available node types in the repository') ->setHelp(<< */ -class RegisterNodeTypesCommand extends Command +class NodeTypeRegisterCommand extends Command { /** * {@inheritDoc} @@ -47,7 +47,7 @@ class RegisterNodeTypesCommand extends Command protected function configure() { $this - ->setName('phpcr:type:register') + ->setName('phpcr:node-type:register') ->setDescription('Register node types in the PHPCR repository') ->setDefinition(array( new InputArgument( diff --git a/src/PHPCR/Util/Console/Command/CreateWorkspaceCommand.php b/src/PHPCR/Util/Console/Command/WorkspaceCreateCommand.php similarity index 98% rename from src/PHPCR/Util/Console/Command/CreateWorkspaceCommand.php rename to src/PHPCR/Util/Console/Command/WorkspaceCreateCommand.php index 35d2537..d808e68 100644 --- a/src/PHPCR/Util/Console/Command/CreateWorkspaceCommand.php +++ b/src/PHPCR/Util/Console/Command/WorkspaceCreateCommand.php @@ -32,7 +32,7 @@ * @author Lukas Kahwe Smith * @author David Buchmann */ -class CreateWorkspaceCommand extends Command +class WorkspaceCreateCommand extends Command { /** * {@inheritDoc} diff --git a/src/PHPCR/Util/Console/Command/ExportXmlCommand.php b/src/PHPCR/Util/Console/Command/WorkspaceExportCommand.php similarity index 96% rename from src/PHPCR/Util/Console/Command/ExportXmlCommand.php rename to src/PHPCR/Util/Console/Command/WorkspaceExportCommand.php index af14405..450cf61 100644 --- a/src/PHPCR/Util/Console/Command/ExportXmlCommand.php +++ b/src/PHPCR/Util/Console/Command/WorkspaceExportCommand.php @@ -34,7 +34,7 @@ * * @author David Buchmann */ -class ExportXmlCommand extends Command +class WorkspaceExportCommand extends Command { /** * {@inheritDoc} @@ -44,7 +44,7 @@ protected function configure() parent::configure(); $this - ->setName('phpcr:export') + ->setName('phpcr:workspace:export') ->addArgument('filename', InputArgument::REQUIRED, 'The xml file to export to') ->addOption('path', 'p', InputOption::VALUE_OPTIONAL, 'Path of the node to export', '/') ->addOption('skip_binary', null, InputOption::VALUE_OPTIONAL, 'Set to "yes" to skip binaries', "no") diff --git a/src/PHPCR/Util/Console/Command/ImportXmlCommand.php b/src/PHPCR/Util/Console/Command/WorkspaceImportCommand.php similarity index 96% rename from src/PHPCR/Util/Console/Command/ImportXmlCommand.php rename to src/PHPCR/Util/Console/Command/WorkspaceImportCommand.php index cd6a310..1610290 100644 --- a/src/PHPCR/Util/Console/Command/ImportXmlCommand.php +++ b/src/PHPCR/Util/Console/Command/WorkspaceImportCommand.php @@ -34,7 +34,7 @@ * * @author David Buchmann */ -class ImportXmlCommand extends Command +class WorkspaceImportCommand extends Command { /** * {@inheritDoc} @@ -44,7 +44,7 @@ protected function configure() parent::configure(); $this - ->setName('phpcr:import') + ->setName('phpcr:workspace:import') ->addArgument('filename', null, 'The xml file to import') ->addOption('parentpath', 'p', InputOption::VALUE_OPTIONAL, 'Repository path to the parent where to import the file contents', '/') ->setDescription('Import xml data into the repository, either in JCR system view format or arbitrary xml') diff --git a/src/PHPCR/Util/Console/Command/ListWorkspacesCommand.php b/src/PHPCR/Util/Console/Command/WorkspaceListCommand.php similarity index 97% rename from src/PHPCR/Util/Console/Command/ListWorkspacesCommand.php rename to src/PHPCR/Util/Console/Command/WorkspaceListCommand.php index 286f986..e3e16fb 100644 --- a/src/PHPCR/Util/Console/Command/ListWorkspacesCommand.php +++ b/src/PHPCR/Util/Console/Command/WorkspaceListCommand.php @@ -30,7 +30,7 @@ * * @author Lukas Kahwe Smith */ -class ListWorkspacesCommand extends Command +class WorkspaceListCommand extends Command { /** * {@inheritDoc} diff --git a/src/PHPCR/Util/Console/Command/WorkspacePurgeCommand.php b/src/PHPCR/Util/Console/Command/WorkspacePurgeCommand.php new file mode 100644 index 0000000..35e9309 --- /dev/null +++ b/src/PHPCR/Util/Console/Command/WorkspacePurgeCommand.php @@ -0,0 +1,88 @@ + + */ +class WorkspacePurgeCommand extends Command +{ + /** + * {@inheritDoc} + */ + protected function configure() + { + parent::configure(); + + $this + ->setName('phpcr:workspace:purge') + ->setDescription('Remove all nodes from a workspace') + ->addOption('force', null, InputOption::VALUE_NONE, 'Use to bypass the confirmation dialog') + ->setHelp(<<phpcr:purge command remove all the non-standard nodes from the workspace. +EOF + ) + ; + } + + /** + * {@inheritDoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $session = $this->getHelper('phpcr')->getSession(); + $force = $input->getOption('force'); + + if (!$force) { + $dialog = new DialogHelper(); + $workspaceName = $session->getWorkspace()->getName(); + $force = $dialog->askConfirmation($output, sprintf( + 'Are you sure you want to purge workspace "%s" Y/N ?', + $workspaceName + ), false); + } + + if ($force) { + $message = ''; + $output->writeln(sprintf('Purging workspace: %s', $path)); + NodeHelper::purgeWorkspace($session); + $session->save(); + } else { + $output->writeln('Aborted'); + } + + return 0; + } +} + diff --git a/src/PHPCR/Util/Console/Command/QueryCommand.php b/src/PHPCR/Util/Console/Command/WorkspaceQueryCommand.php similarity index 97% rename from src/PHPCR/Util/Console/Command/QueryCommand.php rename to src/PHPCR/Util/Console/Command/WorkspaceQueryCommand.php index a41d7f9..efa589d 100644 --- a/src/PHPCR/Util/Console/Command/QueryCommand.php +++ b/src/PHPCR/Util/Console/Command/WorkspaceQueryCommand.php @@ -33,7 +33,7 @@ * * @author Daniel Barsotti */ -class QueryCommand extends Command +class WorkspaceQueryCommand extends Command { /** * {@inheritDoc} @@ -42,7 +42,7 @@ protected function configure() { parent::configure(); - $this->setName('phpcr:query') + $this->setName('phpcr:workspace:query') ->addArgument('query', InputArgument::REQUIRED, 'A query statement to execute') ->addOption('language', 'l', InputOption::VALUE_OPTIONAL, 'The query language (sql, jcr_sql2', 'jcr_sql2') ->addOption('limit', null, InputOption::VALUE_OPTIONAL, 'The query limit', 0)