Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into delete-hard-references
Browse files Browse the repository at this point in the history
Conflicts:
	src/PHPCR/Util/NodeHelper.php
  • Loading branch information
dbu committed Jan 12, 2013
2 parents 8f584e2 + 6d9f1d9 commit bd87bb4
Show file tree
Hide file tree
Showing 29 changed files with 672 additions and 235 deletions.
2 changes: 1 addition & 1 deletion bin/phpcr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ $file = $vendorDir.'/autoload.php';
if (file_exists($file)) {
$autoload = require_once $file;
} else {
die("Install dependencies to run test suite.\n");
die("Install dependencies before using this command.\n");
}

$configFile = getcwd() . DIRECTORY_SEPARATOR . 'cli-config.php';
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"require": {
"php": ">=5.3.0",
"phpcr/phpcr": ">=2.1.0-beta5",
"symfony/console": ">=2.0.0,<2.2.0-dev"
"symfony/console": ">=2.0.0,<2.3.0-dev"
},
"autoload": {
"psr-0": {
Expand Down
4 changes: 3 additions & 1 deletion src/PHPCR/Util/Console/Command/CreateWorkspaceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$workspace = $session->getWorkspace();

if (! $session->getRepository()->getDescriptor(\PHPCR\RepositoryInterface::OPTION_WORKSPACE_MANAGEMENT_SUPPORTED)) {
throw new \Exception('Your PHPCR implemenation does not support workspace management. Please refer to the documentation of your PHPCR implementation to learn how to create a workspace.');
$output->writeln('<error>Your PHPCR implemenation does not support workspace management. Please refer to the documentation of your PHPCR implementation to learn how to create a workspace.</error>');

return 1;
}

$workspace->createWorkspace($name);
Expand Down
23 changes: 17 additions & 6 deletions src/PHPCR/Util/Console/Command/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace PHPCR\Util\Console\Command;


use Symfony\Component\Console\Command\Command;
use PHPCR\ItemNotFoundException;
use PHPCR\RepositoryException;
use PHPCR\PathNotFoundException;
use PHPCR\Util\UUIDHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -31,8 +34,8 @@ protected function configure()
->setName('phpcr:dump')
->addOption('sys_nodes', null, InputOption::VALUE_OPTIONAL, 'Set to "yes" to dump the system nodes', "no")
->addOption('props', null, InputOption::VALUE_OPTIONAL, 'Set to "yes" to dump the node properties', "no")
//TODO: implement ->addOption('recurse', null, InputOption::VALUE_OPTIONAL, 'Set to a number to limit how deep into the tree to recurse', "-1")
->addArgument('path', InputArgument::OPTIONAL, 'Path of the node to dump', '/')
->addOption('depth', null, InputOption::VALUE_OPTIONAL, 'Set to a number to limit how deep into the tree to recurse', "-1")
->addArgument('identifier', InputArgument::OPTIONAL, 'Path or UUID of the node to dump', '/')
->setDescription('Dump the content repository')
->setHelp(<<<EOF
The <info>dump</info> command recursively outputs the name of the node specified
Expand Down Expand Up @@ -68,7 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$session = $this->getHelper('phpcr')->getSession();

$path = $input->getArgument('path');
$identifier = $input->getArgument('identifier');

$nodeVisitor = new ConsoleDumperNodeVisitor($output);

Expand All @@ -85,8 +88,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
$walker->addPropertyFilter($filter);
}

// do not catch error but let user see the node was not found
$walker->traverse($session->getNode($path));
try {
$node = $session->getNodeByIdentifier($identifier);
$walker->traverse($node, $input->getOption('depth'));
} catch (RepositoryException $e) {
if ($e instanceof PathNotFoundException || $e instanceof ItemNotFoundException) {
$output->writeln("<error>Path '$identifier' does not exist</error>");

return 1;
}
}

return 0;
}
Expand Down
64 changes: 64 additions & 0 deletions src/PHPCR/Util/Console/Command/ExportXmlCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace PHPCR\Util\Console\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

use PHPCR\RepositoryInterface;

class ExportXmlCommand extends Command
{
/**
* @see Command
*/
protected function configure()
{
parent::configure();

$this
->setName('phpcr:import')
->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")
->addOption('recurse', null, InputOption::VALUE_OPTIONAL, 'Set to "no" to prevent recursion', "yes")
->setDescription('Export nodes from the repository, either to the JCR system view format or the document view format')
->setHelp(<<<EOF
The <info>export</info> command uses the PHPCR SessionInterface::exportSystemView
method to export parts of the repository into an XML document.
If the <info>path</info> option is set, given path is exported.
Otherwise the entire repository is exported.
EOF
)
;
}

/**
* Executes the current command.
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*
* @return integer 0 if everything went fine, or an error code
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var $session \PHPCR\SessionInterface */
$session = $this->getHelper('phpcr')->getSession();
if (! $session->getRepository()->getDescriptor(RepositoryInterface::OPTION_XML_EXPORT_SUPPORTED)) {
$output->writeln('<error>This repository does not support xml export</error>');

return 1;
}

$path = $input->getOption('path');
$stream = fopen($input->getArgument('filename'), 'w');
$session->exportSystemView($path, $stream, $input->getOption('skip_binary') === 'yes', $input->getOption('recurse') === 'no');

return 0;
}
}
14 changes: 8 additions & 6 deletions src/PHPCR/Util/Console/Command/ImportXmlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace PHPCR\Util\Console\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -23,11 +22,11 @@ protected function configure()
$this
->setName('phpcr: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')
->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')
->setHelp(<<<EOF
The <info>import</info> command uses the PHPCR Session::importXml method to
import an XML document into the repository. If the document is in the JCR
The <info>import</info> command uses the PHPCR SessionInterface::importXml method
to import an XML document into the repository. If the document is in the JCR
system view format, it is interpreted according to the spec, otherwise it is
treated as document view format, meaning XML elements are translated to nodes
and XML attributes into properties.
Expand All @@ -52,9 +51,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
/** @var $session \PHPCR\SessionInterface */
$session = $this->getHelper('phpcr')->getSession();
if (! $session->getRepository()->getDescriptor(RepositoryInterface::OPTION_XML_IMPORT_SUPPORTED)) {
throw new \RuntimeException('This repository does not support xml import');
$output->writeln('<error>This repository does not support xml import</error>');

return 1;
}
$parentpath = $input->getOption('parentpath') ? $input->getOption('parentpath') : '/';

$parentpath = $input->getOption('parentpath');
$session->importXml($parentpath, $input->getArgument('filename'), ImportUUIDBehaviorInterface::IMPORT_UUID_CREATE_NEW);
$session->save();

Expand Down
1 change: 0 additions & 1 deletion src/PHPCR/Util/Console/Command/ListWorkspacesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace PHPCR\Util\Console\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand Down
19 changes: 14 additions & 5 deletions src/PHPCR/Util/Console/Command/PurgeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace PHPCR\Util\Console\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -22,7 +23,8 @@ protected function configure()

$this
->setName('phpcr:purge')
->setDescription('Remove all content from the repository')
->setDescription('Remove content from the repository')
->addArgument('path', InputArgument::OPTIONAL, 'Path of the node to purge', '/')
->addOption('force', null, InputOption::VALUE_OPTIONAL, 'Set to "yes" to bypass the confirmation dialog', "no")
->setHelp(<<<EOF
The <info>phpcr:purge</info> command remove all the non-standard nodes from the content repository
Expand All @@ -43,17 +45,24 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$session = $this->getHelper('phpcr')->getSession();

$path = $input->getArgument('path');
$force = ConsoleParametersParser::isTrueString($input->getOption('force'));

if (! $force) {
$dialog = new DialogHelper();
$res = $dialog->askConfirmation($output, 'Are you sure you want to delete all the nodes of the content repository? [yes|no]: ', false); // TODO: output server and workspace name
$workspaceName = $session->getWorkspace()->getName();
$force = $dialog->askConfirmation($output, "Are you sure you want to purge path '$path' and all its children from the workspace '$workspaceName'? [yes|no]: ", false);
}

if ($force || $res) {
NodeHelper::deleteAllNodes($this->getHelper('phpcr')->getSession());
if ($force) {
if ('/' === $path) {
NodeHelper::deleteAllNodes($this->getHelper('phpcr')->getSession());
} else {
$session->removeItem($path);
}

$session->save();
$output->writeln("Done\n");
$output->writeln("Done purging '$path' and all its children\n");
} else {
$output->writeln("Aborted\n");
}
Expand Down
22 changes: 16 additions & 6 deletions src/PHPCR/Util/Console/Command/QueryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use PHPCR\Util\NodeHelper;
use PHPCR\Util\TreeWalker;
use PHPCR\Util\Console\Helper\TreeDumper\ConsoleDumperNodeVisitor;
use PHPCR\Util\Console\Helper\TreeDumper\ConsoleDumperPropertyVisitor;
use PHPCR\Util\Console\Helper\TreeDumper\SystemNodeFilter;

/**
* @author Daniel Barsotti <daniel.barsotti@liip.ch>
*/
Expand All @@ -29,6 +23,8 @@ protected function configure()
$this->setName('phpcr: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)
->addOption('offset', null, InputOption::VALUE_OPTIONAL, 'The query offset', 0)
->setDescription('Execute a JCR SQL2 statement')
->setHelp("The <info>query</info> command executes a JCR query statement on the content repository");
}
Expand All @@ -48,20 +44,34 @@ protected function execute(InputInterface $input, OutputInterface $output)
$session = $this->getHelper('phpcr')->getSession();
$qm = $session->getWorkspace()->getQueryManager();
$language = strtoupper($input->getOption('language'));
$limit = $input->getOption('limit');
$offset = $input->getOption('offset');
if (!defined('\PHPCR\Query\QueryInterface::'.$language)) {
throw new \RuntimeException("Query language '\\PHPCR\\Query\\QueryInterface::$language' not defined.");
}

$query = $qm->createQuery($sql, constant('\PHPCR\Query\QueryInterface::'.$language));
if ($limit) {
$query->setLimit($limit);
}
if ($offset) {
$query->setOffset($offset);
}

$output->writeln(sprintf('<info>Executing, language:</info> %s', $query->getLanguage()));

$start = microtime(true);
$result = $query->execute();
$elapsed = microtime(true) - $start;

$output->writeln("Results:\n");
foreach ($result as $i => $row) {
$output->writeln("\n".($i+1).'. Row (Path: '. $row->getPath() .', Score: '. $row->getScore() .'):');
foreach ($row as $column => $value) {
$output->writeln("$column: $value");
}
}
$output->writeln(sprintf('<info>%.2f seconds</info>', $elapsed));

return 0;
}
Expand Down
15 changes: 12 additions & 3 deletions src/PHPCR/Util/Console/Command/RegisterNodeTypesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,34 @@ protected function execute(InputInterface $input, OutputInterface $output)
$allowUpdate = $input->getOption('allow-update');
$session = $this->getHelper('phpcr')->getSession();

$this->updateFromCnd($input, $output, $session, $cnd, $allowUpdate);
try {
$this->updateFromCnd($input, $output, $session, $cnd, $allowUpdate);
} catch (\Exception $e) {
$output->writeln('<error>'.$e->getMessage().'</error>');

return 1;
}

$output->write(PHP_EOL.sprintf('Successfully registered node types from "<info>%s</info>"', $cnd_file) . PHP_EOL);

return 0;
}

/**
* Actually do the update.
*
* @param SessionInterface $session the phpcr session to talk to
* @param string $cnd the compact namespace and node type definition in string form
* @param string $cnd the compact namespace and node type definition in string form
*
* @throws \PHPCR\NodeType\NodeTypeExistsException if the node already exists and allowUpdate is false
* @throws \PHPCR\RepositoryException on other errors
* @throws \PHPCR\RepositoryException on other errors
*/
protected function updateFromCnd(InputInterface $input, OutputInterface $output, SessionInterface $session, $cnd, $allowUpdate)
{
if (! $session instanceof \Jackalope\Session) {
throw new \Exception('PHPCR only provides an API to register node types. Your implementation is not Jackalope (which provides a method for .cnd). TODO: parse the file and do the necessary API calls');
}

$ntm = $session->getWorkspace()->getNodeTypeManager();

try {
Expand Down
6 changes: 4 additions & 2 deletions src/PHPCR/Util/Console/Helper/ConsoleParametersParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,26 @@ class ConsoleParametersParser
/**
* Return true if $value is a string that can be considered as true.
* I.e. if it is case insensitively "true" or "yes".
* @param string $value
* @param string $value
* @return boolean
*/
public static function isTrueString($value)
{
$value = strtolower($value);

return $value === 'true' || $value === 'yes';
}

/**
* Return true if $value is a string that can be considered as false.
* I.e. if it is case insensitively "false" or "no".
* @param string $value
* @param string $value
* @return boolean
*/
public static function isFalseString($value)
{
$value = strtolower($value);

return $value === 'false' || $value === 'no';
}
}
1 change: 0 additions & 1 deletion src/PHPCR/Util/Console/Helper/PhpcrHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ public function getName()
return 'phpcr';
}
}

Loading

0 comments on commit bd87bb4

Please sign in to comment.