Skip to content

Commit 6d0b695

Browse files
committed
continued cleanup
1 parent 81caa98 commit 6d0b695

27 files changed

+343
-104
lines changed

cli-config.php.dist

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<?php
22

3-
// adjust as needed
3+
/**
4+
* This is a sample bootstrap file for the console. All jackalope variants
5+
* provide their own bootstrap file. This file is only relevant for people
6+
* implementing PHPCR and using the phpcr-utils.
7+
*/
8+
49
$path_to_jackalope = __DIR__.'/../jackalope';
510

611
// $autoload was created in the autoload that is included before this.
@@ -12,14 +17,19 @@ $workspace = 'default';
1217
$user = 'admin';
1318
$pass = 'admin';
1419

15-
/* bootstrapping the repository implementation. for jackalope with jackrabbit, do this: */
16-
$factory = new \Jackalope\RepositoryFactoryJackrabbit;
17-
$repository = $factory->getRepository(array("jackalope.jackrabbit_uri" => $jackrabbit_url));
18-
$credentials = new \PHPCR\SimpleCredentials($user, $pass);
19-
$session = $repository->login($credentials, $workspace);
20+
if (isset($argv[1])
21+
&& $argv[1] != 'list'
22+
&& $argv[1] != 'help'
23+
) {
24+
/* bootstrapping the repository implementation. for jackalope with jackrabbit, do this: */
25+
$factory = new \Jackalope\RepositoryFactoryJackrabbit;
26+
$repository = $factory->getRepository(array("jackalope.jackrabbit_uri" => $jackrabbit_url));
27+
$credentials = new \PHPCR\SimpleCredentials($user, $pass);
28+
$session = $repository->login($credentials, $workspace);
2029

21-
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
22-
'phpcr' => new \PHPCR\Util\Console\Helper\PhpcrHelper($session),
23-
'phpcr_cli' => new \PHPCR\Util\Console\Helper\PhpcrCliHelper($session),
24-
'phpcr_console_dumper' => new \PHPCR\Util\Console\Helper\PhpcrConsoleDumperHelper(),
25-
));
30+
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
31+
'dialog' => new \Symfony\Component\Console\Helper\DialogHelper(),
32+
'phpcr' => new \PHPCR\Util\Console\Helper\PhpcrHelper($session),
33+
'phpcr_console_dumper' => new \PHPCR\Util\Console\Helper\PhpcrConsoleDumperHelper(),
34+
));
35+
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
},
3939
"extra": {
4040
"branch-alias": {
41-
"dev-master": "1.0-dev"
41+
"dev-master": "1.1-dev"
4242
}
4343
}
4444
}

src/PHPCR/Util/CND/Parser/CndParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* @license http://opensource.org/licenses/MIT MIT License
3232
*
3333
* @author Daniel Barsotti <[email protected]>
34-
* @author David Buchmann <david@liip.ch>
34+
* @author David Buchmann <mail@davidbu.ch>
3535
*/
3636
class CndParser extends AbstractParser
3737
{

src/PHPCR/Util/CND/Writer/CndWriter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* @license http://www.apache.org/licenses Apache License Version 2.0, January 2004
2424
* @license http://opensource.org/licenses/MIT MIT License
2525
*
26-
* @author David Buchmann <david@liip.ch>
26+
* @author David Buchmann <mail@davidbu.ch>
2727
*/
2828
class CndWriter
2929
{
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace PHPCR\Util\Console\Command;
4+
5+
use Symfony\Component\Console\Input\InputOption;
6+
7+
/**
8+
* Base command for node manipulations, providing common setup.
9+
*
10+
* @license http://www.apache.org/licenses Apache License Version 2.0, January 2004
11+
* @license http://opensource.org/licenses/MIT MIT License
12+
*/
13+
abstract class BaseNodeManipulationCommand extends BaseCommand
14+
{
15+
/**
16+
* Set up the options to manipulate nodes.
17+
*/
18+
protected function configureNodeManipulationInput()
19+
{
20+
$this->addOption('set-prop', 'p',
21+
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
22+
'Set node property on nodes use foo=bar'
23+
);
24+
$this->addOption('remove-prop', 'r',
25+
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
26+
'Remove property from nodes'
27+
);
28+
$this->addOption('add-mixin', null,
29+
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
30+
'Add a mixin to the nodes'
31+
);
32+
$this->addOption('remove-mixin', null,
33+
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
34+
'Remove mixin from the nodes'
35+
);
36+
$this->addOption('apply-closure', null,
37+
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
38+
'Apply a closure to each node, closures are passed PHPCR\Session and PHPCR\NodeInterface'
39+
);
40+
}
41+
}

src/PHPCR/Util/Console/Command/NodeMoveCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
* @author Daniel Leech <[email protected]>
1717
*/
18-
class NodeMoveCommand extends Command
18+
class NodeMoveCommand extends BaseCommand
1919
{
2020
/**
2121
* {@inheritDoc}
@@ -45,7 +45,7 @@ protected function configure()
4545
*/
4646
protected function execute(InputInterface $input, OutputInterface $output)
4747
{
48-
$session = $this->getHelper('phpcr')->getSession();
48+
$session = $this->getPhpcrSession();
4949

5050
$sourcePath = $input->getArgument('source');
5151
$destPath = $input->getArgument('destination');
@@ -57,6 +57,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
5757

5858
$session->move($sourcePath, $destPath);
5959
$session->save();
60+
61+
return 0;
6062
}
6163

6264
}

src/PHPCR/Util/Console/Command/NodeRemoveCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* @author Daniel Barsotti <[email protected]>
2222
* @author Daniel Leech <[email protected]>
2323
*/
24-
class NodeRemoveCommand extends Command
24+
class NodeRemoveCommand extends BaseCommand
2525
{
2626
/**
2727
* {@inheritDoc}
@@ -57,8 +57,7 @@ protected function configure()
5757
*/
5858
protected function execute(InputInterface $input, OutputInterface $output)
5959
{
60-
/** @var $session SessionInterface*/
61-
$session = $this->getHelper('phpcr')->getSession();
60+
$session = $this->getPhpcrSession();
6261

6362
$path = $input->getArgument('path');
6463
$force = $input->getOption('force');
@@ -74,7 +73,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
7473
}
7574

7675
if (!$force) {
77-
$dialog = new DialogHelper();
76+
/** @var $dialog DialogHelper */
77+
$dialog = $this->getHelperSet()->get('dialog');
7878
$workspaceName = $session->getWorkspace()->getName();
7979

8080
if ($onlyChildren) {

src/PHPCR/Util/Console/Command/NodeTouchCommand.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
* @author Daniel Leech <[email protected]>
2121
*/
22-
class NodeTouchCommand extends BaseCommand
22+
class NodeTouchCommand extends BaseNodeManipulationCommand
2323
{
2424
/**
2525
* {@inheritDoc}
@@ -71,7 +71,7 @@ protected function configure()
7171
*/
7272
protected function execute(InputInterface $input, OutputInterface $output)
7373
{
74-
$helper = $this->getPhpcrCliHelper();
74+
$helper = $this->getPhpcrHelper();
7575
$session = $this->getPhpcrSession();
7676

7777
$path = $input->getArgument('path');
@@ -98,13 +98,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
9898
));
9999

100100
if ($nodeType != $type) {
101-
throw new \Exception(sprintf(
102-
'You have specified node type "%s" but the existing node is of type "%s"',
101+
$output->writeln(sprintf(
102+
'<error>You have specified node type "%s" but the existing node is of type "%s"</error>',
103103
$type, $nodeType
104104
));
105+
106+
return 1;
105107
}
106108
} else {
107-
108109
$nodeName = PathHelper::getNodeName($path);
109110
$parentPath = PathHelper::getParentPath($path);
110111

@@ -116,7 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
116117
$parentPath
117118
));
118119

119-
return;
120+
return 2;
120121
}
121122

122123
$output->writeln(sprintf(
@@ -135,5 +136,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
135136
));
136137

137138
$session->save();
139+
140+
return 0;
138141
}
139142
}

src/PHPCR/Util/Console/Command/NodesUpdateCommand.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Symfony\Component\Console\Input\InputInterface;
77
use Symfony\Component\Console\Output\OutputInterface;
88
use Symfony\Component\Console\Helper\DialogHelper;
9-
use PHPCR\Util\Console\Command\BaseCommand;
109

1110
/**
1211
* Command which can update the properties of nodes found
@@ -17,7 +16,7 @@
1716
*
1817
* @author Daniel Leech <[email protected]>
1918
*/
20-
class NodesUpdateCommand extends BaseCommand
19+
class NodesUpdateCommand extends BaseNodeManipulationCommand
2120
{
2221
/**
2322
* {@inheritDoc}
@@ -82,8 +81,6 @@ protected function configure()
8281
*/
8382
protected function execute(InputInterface $input, OutputInterface $output)
8483
{
85-
$this->dialog = new DialogHelper();
86-
8784
$query = $input->getOption('query');
8885
$queryLanguage = strtoupper($input->getOption('query-language'));
8986
$persistCounter = intval($input->getOption('persist-counter'));
@@ -93,7 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9390
$removeMixins = $input->getOption('remove-mixin');
9491
$applyClosures = $input->getOption('apply-closure');
9592
$noInteraction = $input->getOption('no-interaction');
96-
$helper = $this->getPhpcrCliHelper();
93+
$helper = $this->getPhpcrHelper();
9794
$session = $this->getPhpcrSession();
9895

9996
if (!$query) {
@@ -154,7 +151,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
154151

155152
protected function getAction($output, $result)
156153
{
157-
$response = strtoupper($this->dialog->ask($output, sprintf(
154+
/** @var $dialog DialogHelper */
155+
$dialog = $this->getHelperSet()->get('dialog');
156+
$response = strtoupper($dialog->ask($output, sprintf(
158157
'<question>About to update %d nodes. Enter "Y" to continue, "N" to cancel or "L" to list.</question>',
159158
count($result->getRows())
160159
), false));

src/PHPCR/Util/Console/Command/WorkspaceCreateCommand.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
* @license http://opensource.org/licenses/MIT MIT License
1717
*
1818
* @author Lukas Kahwe Smith <[email protected]>
19-
* @author David Buchmann <david@liip.ch>
19+
* @author David Buchmann <mail@davidbu.ch>
2020
*/
21-
class WorkspaceCreateCommand extends Command
21+
class WorkspaceCreateCommand extends BaseCommand
2222
{
2323
/**
2424
* {@inheritDoc}
@@ -43,8 +43,7 @@ protected function configure()
4343
*/
4444
protected function execute(InputInterface $input, OutputInterface $output)
4545
{
46-
/** @var $session SessionInterface */
47-
$session = $this->getHelper('phpcr')->getSession();
46+
$session = $this->getPhpcrSession();
4847

4948
$workspaceName = $input->getArgument('name');
5049

@@ -61,9 +60,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
6160
return 1;
6261
}
6362

63+
if (array_search($workspaceName, $workspace->getAccessibleWorkspaceNames())) {
64+
$output->writeln(
65+
sprintf('<comment>This repository already has a workspace called "%s"</comment>', $workspaceName)
66+
);
67+
68+
return 2;
69+
}
70+
6471
$workspace->createWorkspace($workspaceName);
6572

66-
$output->writeln("Created workspace '$workspaceName'.");
73+
$output->writeln(sprintf('<info>Created workspace "%s".</info>', $workspaceName));
6774

6875
return 0;
6976
}

0 commit comments

Comments
 (0)