Skip to content

Commit dc2e407

Browse files
committed
Versioning commands
1 parent 556d745 commit dc2e407

17 files changed

+556
-82
lines changed

README.md

Lines changed: 4 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -60,87 +60,9 @@ Options:
6060
--repo-url (-url) URL of repository (e.g. for jackrabbit). (default: "http://localhost:8080/server/")
6161
````
6262

63-
## Executing Select Queries
63+
## TODO
6464

65-
JCR_SQL2 Select queries can be executed in the same way as in the MySQL shell:
65+
- Versioning:
66+
- Activity
67+
- Configuration
6668

67-
````bash
68-
PHPCR > SELECT * FROM [nt:unstructured];
69-
70-
| Row: #13 Score: 3
71-
| Sel: nt:unstructured Path: /functional/Lyon_65019 UID: e6e74fdb-d329-4405-abd6-317bd0a9a325
72-
+--------------------+--------+----------+--------------------------------------+
73-
| Name | Type | Multiple | Value |
74-
+--------------------+--------+----------+--------------------------------------+
75-
| phpcr:classparents | String | yes | |
76-
| phpcr:class | String | no | Doctrine\Tests\Models\CMS\CmsAddress |
77-
| jcr:uuid | String | no | e6e74fdb-d329-4405-abd6-317bd0a9a325 |
78-
| jcr:mixinTypes | Name | yes | [0] phpcr:managed |
79-
| | | | [1] mix:referenceable |
80-
| country | String | no | France |
81-
| jcr:primaryType | Name | no | nt:unstructured |
82-
| city | String | no | Lyon |
83-
| zip | String | no | 65019 |
84-
+--------------------+--------+----------+--------------------------------------+
85-
86-
| Row: #14 Score: 3
87-
| Sel: nt:unstructured Path: /functional/anonymous UID: 40d35c13-083a-447d-a86a-04bfee2f0608
88-
+--------------------+--------+----------+--------------------------------------+
89-
| Name | Type | Multiple | Value |
90-
+--------------------+--------+----------+--------------------------------------+
91-
| phpcr:class | String | no | Doctrine\Tests\Models\CMS\CmsUser |
92-
| phpcr:classparents | String | yes | |
93-
| jcr:uuid | String | no | 40d35c13-083a-447d-a86a-04bfee2f0608 |
94-
| jcr:mixinTypes | Name | yes | [0] phpcr:managed |
95-
| | | | [1] mix:referenceable |
96-
| username | String | no | anonymous |
97-
| jcr:primaryType | Name | no | nt:unstructured |
98-
+--------------------+--------+----------+--------------------------------------+
99-
100-
2 rows in set (0.04 sec)
101-
````
102-
103-
## Changing the CWD
104-
105-
The PHPCR shell allows you to navigate the PHPCR document hierarchy like a file system
106-
107-
````bash
108-
PHPCR > ls
109-
ROOT:
110-
cms/
111-
foobar/
112-
some-node
113-
PHPCR > cd cms/foobar
114-
PHPCR > pwd
115-
/cms/foobar
116-
PHPCR > mv foobar /barfoo
117-
````
118-
119-
## All other commands
120-
121-
The PHPCR shell wraps all the commands of the `phpcr-utils` package, list
122-
them with the `list` command:
123-
124-
````bash
125-
PHPCR> list
126-
Available commands:
127-
cd Change the current path
128-
exit Logout and quit the shell
129-
help Displays help for a command
130-
list Lists commands
131-
ls Alias for dump
132-
mv Moves a node from one path to another
133-
nt-list List all available node types in the repository
134-
nt-register Register node types in the PHPCR repository
135-
pwd Print Working Directory (or path)
136-
rm Remove content from the repository
137-
select Execute an JCR_SQL2 query.
138-
touch Create or modify a node
139-
update Command to manipulate the nodes in the workspace.
140-
workspace-create Create a workspace in the configured repository
141-
workspace-delete Delete a workspace from the configured repository
142-
workspace-export Export nodes from the repository, either to the JCR system view format or the document view format
143-
workspace-import Import xml data into the repository, either in JCR system view format or arbitrary xml
144-
workspace-list List all available workspaces in the configured repository
145-
workspace-purge Remove all nodes from a workspace
146-
````

features/fixtures/versionable.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<sv:node xmlns:crx="http://www.day.com/crx/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:fn_old="http://www.w3.org/2004/10/xpath-functions" xmlns:vlt="http://www.day.com/jcr/vault/1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:rep="internal" sv:name="tests_version_base">
3+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
4+
<sv:value>nt:unstructured</sv:value>
5+
</sv:property>
6+
<sv:property sv:name="jcr:created" sv:type="Date">
7+
<sv:value>2009-04-27T13:00:54.082+02:00</sv:value>
8+
</sv:property>
9+
<sv:node sv:name="versionable">
10+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
11+
<sv:value>nt:unstructured</sv:value>
12+
</sv:property>
13+
</sv:node>
14+
<sv:node sv:name="unversionable">
15+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
16+
<sv:value>nt:unstructured</sv:value>
17+
</sv:property>
18+
</sv:node>
19+
<sv:node sv:name="versioned">
20+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
21+
<sv:value>nt:unstructured</sv:value>
22+
</sv:property>
23+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
24+
<sv:value>mix:versionable</sv:value>
25+
</sv:property>
26+
<sv:property sv:name="foo" sv:type="String">
27+
<sv:value>something</sv:value>
28+
</sv:property>
29+
</sv:node>
30+
<sv:node sv:name="simpleVersioned">
31+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
32+
<sv:value>nt:unstructured</sv:value>
33+
</sv:property>
34+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
35+
<sv:value>mix:simpleVersionable</sv:value>
36+
</sv:property>
37+
<sv:property sv:name="foo" sv:type="String">
38+
<sv:value>something</sv:value>
39+
</sv:property>
40+
</sv:node>
41+
</sv:node>

features/version_checkin.feature

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Feature: Checkin a version
2+
In order to checkin a version of a given absolute path
3+
As a user logged into the shell
4+
I need to be able to execute a command which does that
5+
6+
Background:
7+
Given that I am logged in as "testuser"
8+
And the "versionable.xml" fixtures are loaded
9+
10+
Scenario: Checkin a version of a given node
11+
Given I execute the "version:checkin /tests_version_base/versioned" command
12+
Then the command should not fail
13+
And I should see the following:
14+
"""
15+
Version:
16+
"""
17+
18+
Scenario: Checkin a non-versionable node
19+
Given I execute the "version:checkin /tests_version_base" command
20+
Then the command should fail
21+
And I should see the following:
22+
"""
23+
Node "/tests_version_base" is not versionable
24+
"""

features/version_checkout.feature

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Feature: Checkout a version
2+
In order to modify a versionable node
3+
As a user logged into the shell
4+
I must be able to execute a command which checksout the node
5+
6+
Background:
7+
Given that I am logged in as "testuser"
8+
And the "versionable.xml" fixtures are loaded
9+
10+
Scenario: Checkout a a given node
11+
Given I execute the "version:checkout /tests_version_base/versioned" command
12+
Then the command should not fail
13+
And the node "/tests_version_base/verionable" should be checked out
14+
15+
Scenario: Checkout a non-versionable node
16+
Given I execute the "version:checkout /tests_version_base" command
17+
Then the command should fail
18+
And I should see the following:
19+
"""
20+
Node "/tests_version_base" is not versionable
21+
"""
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Feature: Checkpoint
2+
In order to commit the version status of a node and checkit out again
3+
As a user logged into the shell
4+
I want to be able to execute a command which does that
5+
6+
Background:
7+
Given that I am logged in as "testuser"
8+
And the "versionable.xml" fixtures are loaded
9+
10+
Scenario: Checkpoint a a given node
11+
Given I execute the "version:checkpoint /tests_version_base/versioned" command
12+
Then the command should not fail
13+
And the node "/tests_version_base/verionable" should be checked out
14+
And I should see the following:
15+
"""
16+
Version:
17+
"""
18+
19+
Scenario: Checkpoint a non versionable node
20+
Given I execute the "version:checkpoint /tests_version_base" command
21+
Then the command should fail
22+
And I should see the following:
23+
"""
24+
Node "/tests_version_base" is not versionable
25+
"""

features/version_history.feature

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Feature: Node Version History
2+
In order to see the version history of a given node
3+
As a user logged into the shell
4+
I want to be able to execute a command which does that
5+
6+
Background:
7+
Given that I am logged in as "testuser"
8+
And the "versionable.xml" fixtures are loaded
9+
10+
Scenario: Checkout a a given node
11+
Given I execute the "version:history /tests_version_base/versioned" command
12+
Then the command should not fail
13+
And I should see a table containing the following rows:
14+
| Name | Created |
15+
16+
Scenario: History on a non versionable node
17+
Given I execute the "version:history /tests_version_base" command
18+
Then the command should fail
19+
And I should see the following:
20+
"""
21+
Node "/tests_version_base" is not versionable
22+
"""

features/version_remove.feature

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Feature: Remove node version
2+
In order to remove a version of a node
3+
As a user logged into the shell
4+
I want to be able to execute a command which does that
5+
6+
Background:
7+
Given that I am logged in as "testuser"
8+
And the "session_data.xml" fixtures are loaded
9+
10+
Scenario: Checkout a a given node
11+
Given the node "/tests_general_base" has a version with label "mylabel"
12+
And I execute the "version:remove /tests_general_base mylabel" command
13+
Then the command should not fail
14+
And the node "/tests_general_base" should have a node version labeled "mylabel"

features/version_restore.feature

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Feature: Restore a version
2+
In order to revert a node to a given version
3+
As a user logged into the shell
4+
I need to be able to execute a command which restores a given version
5+
6+
Background:
7+
Given that I am logged in as "testuser"
8+
And the "session_data.xml" fixtures are loaded
9+
10+
Scenario: Restore node version
11+
Given there exists a node version "asd" for node "/tests_general_base"
12+
And I execute the "version:restore --version=asd" command
13+
Then the command should not fail
14+
And the version of "/tests_general_base" should be "asd"
15+
16+
Scenario: Restore node version by label
17+
Given there exists a node version "asd" for node "/tests_general_base"
18+
And I execute the "version:restore --label=asd" command
19+
Then the command should not fail
20+
And the version of "/tests_general_base" should be "asd"
21+
22+
Scenario: Restore multiple node versions
23+
Given there exists a node version "asd" for node "/tests_general_base"
24+
And I execute the "version:restore --version=asd --version=dsa" command
25+
Then the command should not fail
26+
And the version of "/tests_general_base" should be "asd"

src/PHPCR/Shell/Console/Application/ShellApplication.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PHPCR\Shell\Console\Command\Shell\ChangePathCommand;
1111
use PHPCR\Shell\Console\Command\Shell\PwdCommand;
1212
use PHPCR\Shell\Console\Helper\ResultFormatterHelper;
13+
use PHPCR\Shell\Console\Helper\NodeHelper;
1314
use PHPCR\Shell\PhpcrSession;
1415
use PHPCR\SimpleCredentials;
1516
use PHPCR\Util\Console\Command\NodeDumpCommand;
@@ -60,6 +61,12 @@
6061
use PHPCR\Shell\Console\Command\NodeTypeUnregisterCommand;
6162
use PHPCR\Shell\Console\Command\NodeTypeListCommand;
6263
use PHPCR\Shell\Console\Command\NodeTypeLoadCommand;
64+
use PHPCR\Shell\Console\Command\VersionCheckoutCommand;
65+
use PHPCR\Shell\Console\Command\VersionCheckinCommand;
66+
use PHPCR\Shell\Console\Command\VersionHistoryCommand;
67+
use PHPCR\Shell\Console\Command\VersionRestoreCommand;
68+
use PHPCR\Shell\Console\Command\VersionRemoveCommand;
69+
use PHPCR\Shell\Console\Command\VersionCheckpointCommand;
6370

6471
class ShellApplication extends Application
6572
{
@@ -131,6 +138,12 @@ public function init()
131138
$this->add(new NodeTypeUnregisterCommand());
132139
$this->add(new NodeTypeListCommand());
133140
$this->add(new NodeTypeLoadCommand());
141+
$this->add(new VersionCheckoutCommand());
142+
$this->add(new VersionHistoryCommand());
143+
$this->add(new VersionRestoreCommand());
144+
$this->add(new VersionRemoveCommand());
145+
$this->add(new VersionCheckpointCommand());
146+
$this->add(new VersionCheckinCommand());
134147

135148
// add shell-specific commands
136149
$this->add(new ChangePathCommand());
@@ -173,6 +186,7 @@ public function init()
173186
$this->getHelperSet()->set(new PhpcrHelper($session));
174187
$this->getHelperSet()->set(new ResultFormatterHelper());
175188
$this->getHelperSet()->set(new TextHelper());
189+
$this->getHelperSet()->set(new NodeHelper($session));
176190

177191
$this->initialized = true;
178192
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
10+
class VersionCheckinCommand extends Command
11+
{
12+
protected function configure()
13+
{
14+
$this->setName('version:checkin');
15+
$this->setDescription('Checkin (commit) a node version');
16+
$this->addArgument('absPath', null, InputArgument::REQUIRED, 'Absolute path to node');
17+
$this->setHelp(<<<HERE
18+
Creates for the versionable node at <info>absPath</info> a new version with a system
19+
generated version name and returns that version (which will be the new
20+
base version of this node). Sets the <comment>jcr:checkedOut</comment> property to false
21+
thus putting the node into the checked-in state. This means that the node
22+
and its connected non-versionable subgraph become read-only. A node's
23+
connected non-versionable subgraph is the set of non-versionable descendant
24+
nodes reachable from that node through child links without encountering
25+
any versionable nodes. In other words, the read-only status flows down
26+
from the checked-in node along every child link until either a versionable
27+
node is encountered or an item with no children is encountered. In a
28+
system that supports only simple versioning the connected non-versionable
29+
subgraph will be equivalent to the whole subgraph, since simple-versionable
30+
nodes cannot have simple-versionable descendants.
31+
32+
Read-only status means that an item cannot be altered by the client using
33+
standard API methods (addNode, setProperty, etc.). The only exceptions to
34+
this rule are the restore(), restoreByLabel(), merge() and Node::update()
35+
operations; these do not respect read-only status due to check-in. Note
36+
that remove of a read-only node is possible, as long as its parent is not
37+
read-only (since removal is an alteration of the parent node).
38+
39+
If this node is already checked-in, this method has no effect but returns
40+
the current base version of this node.
41+
42+
If checkin succeeds, the change to the <comment>jcr:isCheckedOut</comment> property is
43+
dispatched immediately.
44+
HERE
45+
);
46+
}
47+
48+
public function execute(InputInterface $input, OutputInterface $output)
49+
{
50+
$session = $this->getHelper('phpcr')->getSession();
51+
$nodeHelper = $this->getHelper('node');
52+
$absPath = $input->getArgument('absPath');
53+
$workspace = $session->getWorkspace();
54+
55+
$versionManager = $workspace->getVersionManager();
56+
57+
$node = $session->getNode($absPath);
58+
$nodeHelper->assertNodeIsVersionable($node);
59+
60+
$version = $versionManager->checkin($absPath);
61+
62+
$output->writeln('Version: ' . $version->getName());
63+
}
64+
}

0 commit comments

Comments
 (0)