-
Notifications
You must be signed in to change notification settings - Fork 19
/
NodeOrderBeforeCommand.php
49 lines (41 loc) · 2.04 KB
/
NodeOrderBeforeCommand.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
<?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;
class NodeOrderBeforeCommand extends Command
{
protected function configure()
{
$this->setName('node:order-before');
$this->setDescription('Reorder a child node of the current node');
$this->addArgument('path', InputArgument::REQUIRED, 'Path of node');
$this->addArgument('srcChildRelPath', InputArgument::REQUIRED, 'The relative path to the child node to be moved in the ordering');
$this->addArgument('destChildRelPath', InputArgument::REQUIRED, 'The relative path to the child before which the node srcChildRelPath will be placed');
$this->setHelp(<<<HERE
If this node supports child node ordering, this method inserts the child
node at <info>srcChildRelPath</info> into the child node list at the position
immediately before <info>destChildRelPath</info>
To place the node <info>srcChildRelPath</info> at the end of the list, a
destChildRelPath of null is used.
Note that (apart from the case where <info>destChildRelPath</info> is null) both of
these arguments must be relative paths of depth one, in other words they
are the names of the child nodes, possibly suffixed with an index.
If <info>srcChildRelPath</info> and <info>destChildRelPath</info> are the same, then no change is
made.
This is session-write method, meaning that a change made by this method
is dispatched on save.
HERE
);
}
public function execute(InputInterface $input, OutputInterface $output)
{
$session = $this->getHelper('phpcr')->getSession();
$path = $input->getArgument('path');
$srcChildRelPath = $input->getArgument('srcChildRelPath');
$destChildRelPath = $input->getArgument('destChildRelPath');
$node = $session->getNodeByPathOrIdentifier($path);
$node->orderBefore($srcChildRelPath, $destChildRelPath);
}
}