-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathVersionRestoreCommand.php
106 lines (89 loc) · 4.91 KB
/
VersionRestoreCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
namespace PHPCR\Shell\Console\Command\Phpcr;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
class VersionRestoreCommand extends BasePhpcrCommand
{
protected function configure()
{
$this->setName('version:restore');
$this->setDescription('Restore a node version');
$this->addArgument('path', InputArgument::REQUIRED, 'Path to node');
$this->addArgument('versionName', InputArgument::REQUIRED, 'Name of version to retore');
$this->addOption('remove-existing', null, InputOption::VALUE_NONE, 'Flag that governs what happens in case of identifier collision');
$this->setHelp(<<<HERE
Attempt to restore an old version of a node.
* If <info>path</info> is given and <info>versionName</info> is a version name:
Restores the node at <info>path</info> to the state defined by the version with
the specified version name (<info>versionName</info>).
This method will work regardless of whether the node at path is
checked-in or not.
* If <info>path</info> is given and <info>versionName</info> is a VersionInterface instance:
Restores the specified version to <info>path</info>. There must be no existing
node at <info>path</info>. If one exists, a VersionException is thrown.
There must be a parent node to the location at <info>path</info>, otherwise a
PathNotFoundException is thrown.
If the would-be parent of the location <info>path</info> is actually a property,
or if a node type restriction would be violated, then a
ConstraintViolationException is thrown.
* If <info>versionName</info> is VersionInterface instance:
Restores the node in the current workspace that is the versionable node
of the specified version to the state reflected in that version.
This method ignores checked-in status.
* If <info>versionName</info> is an array of VersionInterface instances:
Restores a set of versions at once. Used in cases where a "chicken and
egg" problem of mutually referring REFERENCE properties would prevent
the restore in any serial order.
The following restrictions apply to the set of versions specified: If S
is the set of versions being restored simultaneously,
- For every version V in S that corresponds to a missing node, there
must also be a parent of V in S.
- S must contain at least one version that corresponds to an existing
node in the workspace.
- No V in S can be a root version (jcr:rootVersion).
If any of these restrictions does not hold, the restore will fail
because the system will be unable to determine the path locations to
which one or more versions are to be restored. In this case a
VersionException is thrown.
The versionable nodes in the current workspace that correspond to the
versions being restored define a set of (one or more) subgraphs.
If the restore succeeds the changes made are dispatched immediately;
there is no need to call save.
If an array of VersionInterface instances is restored, an identifier
collision occurs when the current workspace contains a node outside these
subgraphs that has the same identifier as one of the nodes that would be
introduced by the restore operation into one of these subgraphs.
Else, an identifier collision occurs when a node exists outside the
subgraph rooted at path with the same identifier as a node that would
be introduced by the restore operation into the affected subgraph.
The result in such a case is governed by the removeExisting flag. If
<info>removeExisting</info> is true, then the incoming node takes precedence, and the
existing node (and its subgraph) is removed (if possible; otherwise a
RepositoryException is thrown). If <info>removeExisting</info> is false, then an
ItemExistsException is thrown and no changes are made. Note that this
applies not only to cases where the restored node itself conflicts with
an existing node but also to cases where a conflict occurs with any node
that would be introduced into the workspace by the restore operation. In
particular, conflicts involving subnodes of the restored node that have
OnParentVersion settings of COPY or VERSION are also governed by the
<info>removeExisting</info> flag.
Note:
The Java API defines this with multiple differing
signatures, you need to act accordingly in your implementation.
HERE
);
}
public function execute(InputInterface $input, OutputInterface $output)
{
$session = $this->get('phpcr.session');
$path = $session->getAbsPath($input->getArgument('path'));
$versionName = $input->getArgument('versionName');
$removeExisting = $input->getOption('remove-existing');
$workspace = $session->getWorkspace();
$versionManager = $workspace->getVersionManager();
$versionManager->restore($removeExisting, $versionName, $path);
}
}