Skip to content

Commit 7babb50

Browse files
committed
Merge pull request #55 from phpcr/target_path_basename
Node Copy, Move, and Move append basename on target exist.
2 parents d397a8c + c53b149 commit 7babb50

File tree

9 files changed

+67
-14
lines changed

9 files changed

+67
-14
lines changed

CHANGELOG.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,27 @@ Changelog
44
alpha-4
55
-------
66

7+
### Features
8+
9+
- [node] copy,move and clone - Target paths automatically append basename if target is a node.
710
- [query] Always show path next to resultset
811

912
alpha-3
1013
-------
1114

1215
### Features
1316

14-
- [file]: `file:import` - New command to import files into the repository.
15-
- [node]: `node:list` Added `--level` option to rescursively show children nodes and properties.
16-
- [node]: `node:list` Show "unulfilled" property and child node definitions when listing node contents.
17+
- [file] `file:import` - New command to import files into the repository.
18+
- [node] `node:list` Added `--level` option to rescursively show children nodes and properties.
19+
- [node] `node:list` Show "unulfilled" property and child node definitions when listing node contents.
1720

1821
### Improvements
1922

20-
- [export]: `session:export:view`: Added `--pretty` option to `session:export:view` command to output formatted XML.
21-
- [export]: `session:export:view`: Ask confirmation before overwriting file.
22-
- [shell]: Autocomplete completes property names in addition to node names in current path.
23+
- [export] `session:export:view`: Added `--pretty` option to `session:export:view` command to output formatted XML.
24+
- [export] `session:export:view`: Ask confirmation before overwriting file.
25+
- [shell] Autocomplete completes property names in addition to node names in current path.
2326

2427
### Bugs
2528

26-
- [shell]: Aliases do not allow quoted arguments.
27-
- [shell]: Autocomplete causes segfault.
29+
- [shell] Aliases do not allow quoted arguments.
30+
- [shell] Autocomplete causes segfault.

features/phpcr_node_clone.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ Feature: Clone a node from a given workspace to the current workspace
1616
And I save the session
1717
And there should exist a node at "/cms/clone"
1818

19+
Scenario: Clone node onto existing node
20+
Given I execute the "node:clone /cms/articles/article1 /cms/test" command
21+
Then the command should not fail
22+
And I save the session
23+
And there should exist a node at "/cms/test/article1"
24+
1925
Scenario: Clone node
2026
Given I execute the "node:clone /tests_general_base /cms/foobar default_1" command
2127
Then the command should not fail

features/phpcr_node_copy.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@ Feature: Copy a node from a given workspace to the current workspace
2020
Given I execute the "node:copy /tests_general_base/index.txt /index.txt default_1" command
2121
Then the command should not fail
2222
And there should exist a node at "/index.txt"
23+
24+
Scenario: Copy node onto existing target
25+
Given I execute the "node:copy /tests_general_base/index.txt /tests_general_base/daniel" command
26+
Then the command should not fail
27+
And I save the session
28+
And there should exist a node at "/tests_general_base/daniel"

features/phpcr_node_move.feature

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@ Feature: Move a node in the current session
2121
And I execute the "session:save" command
2222
And there should exist a node at "/barfoo"
2323
And there should not exist a node at "/tests_general_base/index.txt"
24+
25+
Scenario: Move onto existing target
26+
Given the current node is "/tests_general_base/index.txt"
27+
And I execute the "node:move . /tests_general_base/daniel" command
28+
Then the command should not fail
29+
And I execute the "session:save" command
30+
And there should exist a node at "/tests_general_base/daniel/index.txt"

src/PHPCR/Shell/Console/Command/Phpcr/NodeCloneCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function execute(InputInterface $input, OutputInterface $output)
5959
$session = $this->getHelper('phpcr')->getSession();
6060
$srcWorkspace = $input->getArgument('srcWorkspace');
6161
$srcAbsPath = $session->getAbsPath($input->getArgument('srcPath'));
62-
$destAbsPath = $session->getAbsPath($input->getArgument('destPath'));
62+
$destAbsPath = $session->getAbsTargetPath($srcAbsPath, $input->getArgument('destPath'));
6363
$removeExisting = $input->getOption('remove-existing');
6464

6565
// todo: Check to ensure that source node has the referenceable mixin

src/PHPCR/Shell/Console/Command/Phpcr/NodeCopyCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function execute(InputInterface $input, OutputInterface $output)
8888
{
8989
$session = $this->getHelper('phpcr')->getSession();
9090
$srcAbsPath = $session->getAbsPath($input->getArgument('srcPath'));
91-
$destAbsPath = $session->getAbsPath($input->getArgument('destPath'));
91+
$destAbsPath = $session->getAbsTargetPath($srcAbsPath, $input->getArgument('destPath'));
9292
$srcWorkspace = $input->getArgument('srcWorkspace');
9393

9494
$workspace = $session->getWorkspace();

src/PHPCR/Shell/Console/Command/Phpcr/NodeMoveCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ protected function configure()
5252
public function execute(InputInterface $input, OutputInterface $output)
5353
{
5454
$session = $this->getHelper('phpcr')->getSession();
55-
$srcPath = $session->getAbsPath($input->getArgument('srcPath'));
56-
$destPath = $session->getAbsPath($input->getArgument('destPath'));
55+
$srcPath = $input->getArgument('srcPath');
56+
$destPath = $input->getArgument('destPath');
57+
5758
$session->move($srcPath, $destPath);
5859
}
5960
}

src/PHPCR/Shell/PhpcrSession.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,32 @@ public function getAbsPath($path)
105105
return $absPath;
106106
}
107107

108+
/**
109+
* Infer the absolute target path for a given source path.
110+
*
111+
* This means that if there is a node at targetPath then we
112+
* will return append the basename of $srcPath to $targetPath.
113+
*
114+
* @param string $srcPath
115+
* @param string $targetPath
116+
*
117+
* @return string
118+
*/
119+
public function getAbsTargetPath($srcPath, $targetPath)
120+
{
121+
$targetPath = $this->getAbsPath($targetPath);
122+
123+
try {
124+
$this->getNode($targetPath);
125+
} catch (PathNotFoundException $e) {
126+
return $targetPath;
127+
}
128+
129+
$basename = basename($this->getAbsPath($srcPath));
130+
131+
return $this->getAbsPath(sprintf('%s/%s', $targetPath, $basename));
132+
}
133+
108134
public function getAbsPaths($paths)
109135
{
110136
$newPaths = array();
@@ -200,9 +226,9 @@ public function propertyExists($path)
200226
return $this->session->propertyExists($this->getAbsPath($path));
201227
}
202228

203-
public function move($srcAbsPath, $destAbsPath)
229+
public function move($srcPath, $destPath)
204230
{
205-
return $this->session->move($this->getAbsPath($srcAbsPath), $this->getAbsPath($destAbsPath));
231+
return $this->session->move($this->getAbsPath($srcPath), $this->getAbsTargetPath($srcPath, $destPath));
206232
}
207233

208234
public function removeItem($path)

tests/PHPCR/Shell/PhpcrSessionTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PHPCR\Shell;
44

55
use PHPCR\SessionInterface;
6+
use PHPCR\PathNotFoundException;
67

78
class PhpcrSessionTest extends \Phpunit_Framework_TestCase
89
{
@@ -73,6 +74,9 @@ public function testMv($cwd, $relSrc, $relTar, $expSrc, $expTar)
7374
$this->phpcr->expects($this->once())
7475
->method('move')
7576
->with($expSrc, $expTar);
77+
$this->phpcr->expects($this->once())
78+
->method('getNode')
79+
->will($this->throwException(new PathNotFoundException));
7680
$this->session->setCwd($cwd);
7781
$this->session->move($relSrc, $relTar);
7882
}

0 commit comments

Comments
 (0)