diff --git a/features/repository_descriptor_list.feature b/features/repository_descriptor_list.feature index aafe3579..f7611f60 100644 --- a/features/repository_descriptor_list.feature +++ b/features/repository_descriptor_list.feature @@ -8,6 +8,6 @@ Feature: List Repository Descriptors And I execute the "repository:descriptor:list" command Then the command should not fail And I should see a table containing the following rows: - | Key | Value | - | jcr.repository.name | Jackrabbit | - | jcr.repository.vendor | Apache Software Foundation | + | Key | Value | Standard? | + | jcr.repository.name | Jackrabbit | yes | + | jcr.repository.vendor | Apache Software Foundation | yes | diff --git a/src/PHPCR/Shell/Console/Application/ShellApplication.php b/src/PHPCR/Shell/Console/Application/ShellApplication.php index c2209bd1..abbea9f6 100644 --- a/src/PHPCR/Shell/Console/Application/ShellApplication.php +++ b/src/PHPCR/Shell/Console/Application/ShellApplication.php @@ -95,6 +95,8 @@ use Jackalope\NotImplementedException; use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Formatter\OutputFormatter; +use PHPCR\Shell\Console\Helper\RepositoryHelper; +use PHPCR\Shell\Console\Command\PhpcrShellCommand; class ShellApplication extends Application { @@ -136,6 +138,16 @@ public function init() $this->transports[$transport->getName()] = $transport;; } + $session = $this->getSession($this->sessionInput); + + $this->getHelperSet()->set(new EditorHelper($session)); + $this->getHelperSet()->set(new PhpcrConsoleDumperHelper()); + $this->getHelperSet()->set(new PhpcrHelper($session)); + $this->getHelperSet()->set(new ResultFormatterHelper()); + $this->getHelperSet()->set(new TextHelper()); + $this->getHelperSet()->set(new NodeHelper($session)); + $this->getHelperSet()->set(new RepositoryHelper($session->getRepository())); + // add new commands $this->add(new AccessControlPrivilegeListCommand()); $this->add(new RepositoryDescriptorListCommand()); @@ -239,15 +251,6 @@ public function init() ->setName('workspace-purge') ); - $this->initSession(); - - $this->getHelperSet()->set(new EditorHelper($this->session)); - $this->getHelperSet()->set(new PhpcrConsoleDumperHelper()); - $this->getHelperSet()->set(new PhpcrHelper($this->session)); - $this->getHelperSet()->set(new ResultFormatterHelper()); - $this->getHelperSet()->set(new TextHelper()); - $this->getHelperSet()->set(new NodeHelper($this->session)); - $this->initialized = true; } diff --git a/src/PHPCR/Shell/Console/Command/LockInfoCommand.php b/src/PHPCR/Shell/Console/Command/LockInfoCommand.php index f31b4c3f..289f7625 100644 --- a/src/PHPCR/Shell/Console/Command/LockInfoCommand.php +++ b/src/PHPCR/Shell/Console/Command/LockInfoCommand.php @@ -7,8 +7,9 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; +use PHPCR\RepositoryInterface; -class LockInfoCommand extends Command +class LockInfoCommand extends PhpcrShellCommand { protected function configure() { @@ -23,6 +24,9 @@ protected function configure() above that node. HERE ); + + $this->requiresDescriptor(RepositoryInterface::OPTION_LOCKING_SUPPORTED, true); + $this->dequiresDescriptor('jackalope.not_implemented.lock.get'); } public function execute(InputInterface $input, OutputInterface $output) diff --git a/src/PHPCR/Shell/Console/Command/LockLockCommand.php b/src/PHPCR/Shell/Console/Command/LockLockCommand.php index 931d792f..027212a0 100644 --- a/src/PHPCR/Shell/Console/Command/LockLockCommand.php +++ b/src/PHPCR/Shell/Console/Command/LockLockCommand.php @@ -7,8 +7,9 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; +use PHPCR\RepositoryInterface; -class LockLockCommand extends Command +class LockLockCommand extends PhpcrShellCommand { protected function configure() { @@ -51,6 +52,8 @@ protected function configure() It is possible to lock a node even if it is checked-in. HERE ); + + $this->requiresDescriptor(RepositoryInterface::OPTION_LOCKING_SUPPORTED, true); } public function execute(InputInterface $input, OutputInterface $output) diff --git a/src/PHPCR/Shell/Console/Command/LockRefreshCommand.php b/src/PHPCR/Shell/Console/Command/LockRefreshCommand.php index 04ca8a90..28b86cb7 100644 --- a/src/PHPCR/Shell/Console/Command/LockRefreshCommand.php +++ b/src/PHPCR/Shell/Console/Command/LockRefreshCommand.php @@ -7,8 +7,9 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; +use PHPCR\RepositoryInterface; -class LockRefreshCommand extends Command +class LockRefreshCommand extends PhpcrShellCommand { protected function configure() { @@ -23,6 +24,8 @@ protected function configure() has no effect. HERE ); + $this->requiresDescriptor(RepositoryInterface::OPTION_LOCKING_SUPPORTED, true); + $this->dequiresDescriptor('jackalope.not_implemented.lock.refresh'); } public function execute(InputInterface $input, OutputInterface $output) diff --git a/src/PHPCR/Shell/Console/Command/LockTokenAddCommand.php b/src/PHPCR/Shell/Console/Command/LockTokenAddCommand.php index 3b5e248b..ae189c2c 100644 --- a/src/PHPCR/Shell/Console/Command/LockTokenAddCommand.php +++ b/src/PHPCR/Shell/Console/Command/LockTokenAddCommand.php @@ -7,8 +7,9 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; +use PHPCR\RepositoryInterface; -class LockTokenAddCommand extends Command +class LockTokenAddCommand extends PhpcrShellCommand { protected function configure() { @@ -22,6 +23,8 @@ protected function configure() specified by that particular lock token. HERE ); + $this->requiresDescriptor(RepositoryInterface::OPTION_LOCKING_SUPPORTED, true); + $this->dequiresDescriptor('jackalope.not_implemented.lock.token'); } public function execute(InputInterface $input, OutputInterface $output) diff --git a/src/PHPCR/Shell/Console/Command/LockTokenListCommand.php b/src/PHPCR/Shell/Console/Command/LockTokenListCommand.php index d7c04720..fcee7b74 100644 --- a/src/PHPCR/Shell/Console/Command/LockTokenListCommand.php +++ b/src/PHPCR/Shell/Console/Command/LockTokenListCommand.php @@ -7,8 +7,9 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; +use PHPCR\RepositoryInterface; -class LockTokenListCommand extends Command +class LockTokenListCommand extends PhpcrShellCommand { protected function configure() { @@ -22,6 +23,8 @@ protected function configure() locks, since session-scoped locks do not have tokens. HERE ); + $this->requiresDescriptor(RepositoryInterface::OPTION_LOCKING_SUPPORTED, true); + $this->dequiresDescriptor('jackalope.not_implemented.lock.token'); } public function execute(InputInterface $input, OutputInterface $output) diff --git a/src/PHPCR/Shell/Console/Command/LockTokenRemoveCommand.php b/src/PHPCR/Shell/Console/Command/LockTokenRemoveCommand.php index f156205e..b20e3bbd 100644 --- a/src/PHPCR/Shell/Console/Command/LockTokenRemoveCommand.php +++ b/src/PHPCR/Shell/Console/Command/LockTokenRemoveCommand.php @@ -7,8 +7,9 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; +use PHPCR\RepositoryInterface; -class LockTokenRemoveCommand extends Command +class LockTokenRemoveCommand extends PhpcrShellCommand { protected function configure() { @@ -19,6 +20,8 @@ protected function configure() Removes the specified lock token from the current Session. HERE ); + $this->requiresDescriptor(RepositoryInterface::OPTION_LOCKING_SUPPORTED, true); + $this->dequiresDescriptor('jackalope.not_implemented.lock.token'); } public function execute(InputInterface $input, OutputInterface $output) diff --git a/src/PHPCR/Shell/Console/Command/LockUnlockCommand.php b/src/PHPCR/Shell/Console/Command/LockUnlockCommand.php index 8b8351db..c43a26a8 100644 --- a/src/PHPCR/Shell/Console/Command/LockUnlockCommand.php +++ b/src/PHPCR/Shell/Console/Command/LockUnlockCommand.php @@ -7,8 +7,9 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; +use PHPCR\RepositoryInterface; -class LockUnlockCommand extends Command +class LockUnlockCommand extends PhpcrShellCommand { protected function configure() { @@ -35,6 +36,7 @@ protected function configure() lock-related properties will be changed despite the checked-in status). HERE ); + $this->requiresDescriptor(RepositoryInterface::OPTION_LOCKING_SUPPORTED, true); } public function execute(InputInterface $input, OutputInterface $output) diff --git a/src/PHPCR/Shell/Console/Command/NodeLifecycleFollowCommand.php b/src/PHPCR/Shell/Console/Command/NodeLifecycleFollowCommand.php index 26cd5d1d..7b623711 100644 --- a/src/PHPCR/Shell/Console/Command/NodeLifecycleFollowCommand.php +++ b/src/PHPCR/Shell/Console/Command/NodeLifecycleFollowCommand.php @@ -10,8 +10,9 @@ use PHPCR\NodeType\NoSuchNodeTypeException; use PHPCR\Util\CND\Parser\CndParser; use PHPCR\NamespaceException; +use PHPCR\RepositoryInterface; -class NodeLifecycleFollowCommand extends Command +class NodeLifecycleFollowCommand extends PhpcrShellCommand { protected function configure() { @@ -30,6 +31,8 @@ protected function configure() need to call save. HERE ); + + $this->requiresDescriptor(RepositoryInterface::OPTION_LIFECYCLE_SUPPORTED, true); } public function execute(InputInterface $input, OutputInterface $output) diff --git a/src/PHPCR/Shell/Console/Command/NodeLifecycleListCommand.php b/src/PHPCR/Shell/Console/Command/NodeLifecycleListCommand.php index 8e88aee1..b4e79bca 100644 --- a/src/PHPCR/Shell/Console/Command/NodeLifecycleListCommand.php +++ b/src/PHPCR/Shell/Console/Command/NodeLifecycleListCommand.php @@ -10,8 +10,9 @@ use PHPCR\NodeType\NoSuchNodeTypeException; use PHPCR\Util\CND\Parser\CndParser; use PHPCR\NamespaceException; +use PHPCR\RepositoryInterface; -class NodeLifecycleListCommand extends Command +class NodeLifecycleListCommand extends PhpcrShellCommand { protected function configure() { @@ -21,6 +22,8 @@ protected function configure() Returns the list of valid state transitions for this node. HERE ); + + $this->requiresDescriptor(RepositoryInterface::OPTION_LIFECYCLE_SUPPORTED, true); } public function execute(InputInterface $input, OutputInterface $output) diff --git a/src/PHPCR/Shell/Console/Command/NodeSharedRemoveCommand.php b/src/PHPCR/Shell/Console/Command/NodeSharedRemoveCommand.php index f61fde9f..c9536c54 100644 --- a/src/PHPCR/Shell/Console/Command/NodeSharedRemoveCommand.php +++ b/src/PHPCR/Shell/Console/Command/NodeSharedRemoveCommand.php @@ -11,8 +11,9 @@ use PHPCR\Util\CND\Parser\CndParser; use PHPCR\NamespaceException; use Symfony\Component\Console\Input\InputOption; +use PHPCR\RepositoryInterface; -class NodeSharedRemoveCommand extends Command +class NodeSharedRemoveCommand extends PhpcrShellCommand { protected function configure() { @@ -27,7 +28,9 @@ protected function configure() If this node is not shared this method removes only this node. HERE - ); + ); + + $this->requiresDescriptor(RepositoryInterface::OPTION_SHAREABLE_NODES_SUPPORTED, true); } public function execute(InputInterface $input, OutputInterface $output) diff --git a/src/PHPCR/Shell/Console/Command/NodeSharedShowCommand.php b/src/PHPCR/Shell/Console/Command/NodeSharedShowCommand.php index 8bf20bfe..e03a53ac 100644 --- a/src/PHPCR/Shell/Console/Command/NodeSharedShowCommand.php +++ b/src/PHPCR/Shell/Console/Command/NodeSharedShowCommand.php @@ -11,8 +11,9 @@ use PHPCR\Util\CND\Parser\CndParser; use PHPCR\NamespaceException; use Symfony\Component\Console\Input\InputOption; +use PHPCR\RepositoryInterface; -class NodeSharedShowCommand extends Command +class NodeSharedShowCommand extends PhpcrShellCommand { protected function configure() { @@ -27,6 +28,8 @@ protected function configure() If this node is not shared then only this node is shown. HERE ); + + $this->requiresDescriptor(RepositoryInterface::OPTION_SHAREABLE_NODES_SUPPORTED, true); } public function execute(InputInterface $input, OutputInterface $output) diff --git a/src/PHPCR/Shell/Console/Command/PhpcrShellCommand.php b/src/PHPCR/Shell/Console/Command/PhpcrShellCommand.php new file mode 100644 index 00000000..b682b8cd --- /dev/null +++ b/src/PHPCR/Shell/Console/Command/PhpcrShellCommand.php @@ -0,0 +1,41 @@ +descriptorRequires[$descriptorKey] = $value; + } + + public function dequiresDescriptor($descriptorKey, $value = null) + { + $this->descriptorDequires[$descriptorKey] = $value; + } + + public function isEnabled() + { + foreach ($this->descriptorRequires as $key => $value) { + $has = $this->getHelper('repository')->hasDescriptor($key, $value); + if (!$has) { + return false; + } + } + + foreach ($this->descriptorDequires as $key => $value) { + $has = $this->getHelper('repository')->hasDescriptor($key, $value); + + if ($has) { + return false; + } + } + + return true; + } +} diff --git a/src/PHPCR/Shell/Console/Command/RepositoryDescriptorListCommand.php b/src/PHPCR/Shell/Console/Command/RepositoryDescriptorListCommand.php index 7bfcf058..ebb051f0 100644 --- a/src/PHPCR/Shell/Console/Command/RepositoryDescriptorListCommand.php +++ b/src/PHPCR/Shell/Console/Command/RepositoryDescriptorListCommand.php @@ -26,16 +26,30 @@ public function execute(InputInterface $input, OutputInterface $output) $keys = $repository->getDescriptorKeys(); $table = clone $this->getHelper('table'); - $table->setHeaders(array('Key', 'Value')); + $table->setHeaders(array('Key', 'Value', 'Standard?')); foreach ($keys as $key) { $descriptor = $repository->getDescriptor($key); + $isStandard = $repository->isStandardDescriptor($key); if (is_array($descriptor)) { - $descriptor = implode(', ', $descriptor); + $descriptor = implode(', ', $this->getDescriptorValue($descriptor)); } - $table->addRow(array($key, $descriptor)); + $table->addRow(array( + $key, + $this->getDescriptorValue($descriptor), + $isStandard ? 'yes' : 'no', + )); } $table->render($output); } + + private function getDescriptorValue($value) + { + if (is_bool($value)) { + return $value ? 'true' : 'false'; + } + + return $value; + } } diff --git a/src/PHPCR/Shell/Console/Command/RetentionHoldAddCommand.php b/src/PHPCR/Shell/Console/Command/RetentionHoldAddCommand.php index f6871ea4..b9f00324 100644 --- a/src/PHPCR/Shell/Console/Command/RetentionHoldAddCommand.php +++ b/src/PHPCR/Shell/Console/Command/RetentionHoldAddCommand.php @@ -7,8 +7,9 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; +use PHPCR\RepositoryInterface; -class RetentionHoldAddCommand extends Command +class RetentionHoldAddCommand extends PhpcrShellCommand { protected function configure() { @@ -26,6 +27,8 @@ protected function configure() specified. They are application-dependent. HERE ); + + $this->requiresDescriptor(RepositoryInterface::OPTION_RETENTION_SUPPORTED, true); } public function execute(InputInterface $input, OutputInterface $output) diff --git a/src/PHPCR/Shell/Console/Command/RetentionHoldListCommand.php b/src/PHPCR/Shell/Console/Command/RetentionHoldListCommand.php index f23df924..45793aa3 100644 --- a/src/PHPCR/Shell/Console/Command/RetentionHoldListCommand.php +++ b/src/PHPCR/Shell/Console/Command/RetentionHoldListCommand.php @@ -7,8 +7,9 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; +use PHPCR\RepositoryInterface; -class RetentionHoldListCommand extends Command +class RetentionHoldListCommand extends PhpcrShellCommand { protected function configure() { @@ -20,6 +21,8 @@ protected function configure() existing node at absPath. HERE ); + + $this->requiresDescriptor(RepositoryInterface::OPTION_RETENTION_SUPPORTED, true); } public function execute(InputInterface $input, OutputInterface $output) diff --git a/src/PHPCR/Shell/Console/Command/RetentionHoldRemoveCommand.php b/src/PHPCR/Shell/Console/Command/RetentionHoldRemoveCommand.php index 7c74b9f5..d76277b4 100644 --- a/src/PHPCR/Shell/Console/Command/RetentionHoldRemoveCommand.php +++ b/src/PHPCR/Shell/Console/Command/RetentionHoldRemoveCommand.php @@ -7,8 +7,9 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; +use PHPCR\RepositoryInterface; -class RetentionHoldRemoveCommand extends Command +class RetentionHoldRemoveCommand extends PhpcrShellCommand { protected function configure() { @@ -22,6 +23,8 @@ protected function configure() The removal does not take effect until a save is performed. HERE ); + + $this->requiresDescriptor(RepositoryInterface::OPTION_RETENTION_SUPPORTED, true); } public function execute(InputInterface $input, OutputInterface $output) diff --git a/src/PHPCR/Shell/Console/Command/RetentionPolicyGetCommand.php b/src/PHPCR/Shell/Console/Command/RetentionPolicyGetCommand.php index ae878a6d..497725d5 100644 --- a/src/PHPCR/Shell/Console/Command/RetentionPolicyGetCommand.php +++ b/src/PHPCR/Shell/Console/Command/RetentionPolicyGetCommand.php @@ -7,8 +7,9 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; +use PHPCR\RepositoryInterface; -class RetentionPolicyGetCommand extends Command +class RetentionPolicyGetCommand extends PhpcrShellCommand { protected function configure() { @@ -19,6 +20,8 @@ protected function configure() Gets the retention policy of a node identified by its path. HERE ); + + $this->requiresDescriptor(RepositoryInterface::OPTION_RETENTION_SUPPORTED, true); } public function execute(InputInterface $input, OutputInterface $output) diff --git a/src/PHPCR/Shell/Console/Command/RetentionPolicyRemoveCommand.php b/src/PHPCR/Shell/Console/Command/RetentionPolicyRemoveCommand.php index b274ea8f..0bea8918 100644 --- a/src/PHPCR/Shell/Console/Command/RetentionPolicyRemoveCommand.php +++ b/src/PHPCR/Shell/Console/Command/RetentionPolicyRemoveCommand.php @@ -7,8 +7,9 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; +use PHPCR\RepositoryInterface; -class RetentionPolicyRemoveCommand extends Command +class RetentionPolicyRemoveCommand extends PhpcrShellCommand { protected function configure() { @@ -19,6 +20,8 @@ protected function configure() Removes the retention policy of a node identified by its path. HERE ); + + $this->requiresDescriptor(RepositoryInterface::OPTION_RETENTION_SUPPORTED, true); } public function execute(InputInterface $input, OutputInterface $output) diff --git a/src/PHPCR/Shell/Console/Helper/RepositoryHelper.php b/src/PHPCR/Shell/Console/Helper/RepositoryHelper.php new file mode 100644 index 00000000..e49cf5fe --- /dev/null +++ b/src/PHPCR/Shell/Console/Helper/RepositoryHelper.php @@ -0,0 +1,75 @@ +repository = $repository; + } + + /** + * Return true if the repository supports the given descriptor + * which relates to a descriptor key + * + * @param string $descriptor + */ + public function hasDescriptor($descriptor, $value = null) + { + $this->loadDescriptors(); + + $exists = array_key_exists($descriptor, $this->descriptors); + + if (false === $exists) { + return false; + } + + if (null === $value) { + return true; + } + + $descriptorValue = $this->descriptors[$descriptor]; + + // normalize + if ($descriptorValue === 'true') { + $descriptorValue = true; + } + if ($descriptorValue === 'false') { + $descriptorValue = false; + } + + if ($value === $descriptorValue) { + return true; + } + + return false; + } + + private function loadDescriptors() + { + if (null === $this->descriptors) { + foreach ($this->repository->getDescriptorKeys() as $key) { + $this->descriptors[$key] = $this->repository->getDescriptor($key); + } + } + } + + public function getName() + { + return 'repository'; + } +}