Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
Take into account base path
Browse files Browse the repository at this point in the history
  • Loading branch information
dantleech committed Jun 2, 2016
1 parent c12c5cf commit 05be4f2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
14 changes: 14 additions & 0 deletions Repository/AbstractPhpcrRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Webmozart\PathUtil\Path;
use Puli\Repository\AbstractRepository;
use Symfony\Cmf\Component\Resource\Repository\Api\EditableRepository;
use DTL\Glob\GlobHelper;

/**
* Abstract repository for both PHPCR and PHPCR-ODM repositories.
Expand All @@ -38,13 +39,19 @@ abstract class AbstractPhpcrRepository extends AbstractRepository implements Res
*/
private $finder;

/**
* @var GlobHelper
*/
private $globHelper;

/**
* @param string $basePath
*/
public function __construct(FinderInterface $finder, $basePath = null)
{
$this->finder = $finder;
$this->basePath = $basePath;
$this->globHelper = new GlobHelper();
}

/**
Expand Down Expand Up @@ -108,6 +115,8 @@ public function move($query, $targetPath, $language = 'glob')
return 0;
}

$targetPath = $this->resolvePath($targetPath);

try {
// delegate moving to the implementation
$this->moveNodes($nodes, $query, $targetPath);
Expand Down Expand Up @@ -172,6 +181,11 @@ protected function unresolvePath($path)
return $path;
}

protected function isGlobbed($string)
{
return $this->globHelper->isGlobbed($string);
}

/**
* Build a collection of PHPCR resources.
*
Expand Down
7 changes: 3 additions & 4 deletions Repository/PhpcrOdmRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function __construct(ManagerRegistry $managerRegistry, $basePath = null,
$finder = $finder ?: new PhpcrOdmTraversalFinder($managerRegistry);
parent::__construct($finder, $basePath);
$this->managerRegistry = $managerRegistry;
$this->globHelper = new GlobHelper();
}

/**
Expand Down Expand Up @@ -139,15 +138,15 @@ protected function removeNodes(array $documents)
/**
* {@inheritdoc}
*/
protected function moveNodes(array $nodes, $sourceQuery, $targetPath)
protected function moveNodes(array $documents, $sourceQuery, $targetPath)
{
$this->doMoveNodes($nodes, $sourceQuery, $targetPath);
$this->doMoveNodes($documents, $sourceQuery, $targetPath);
$this->getManager()->flush();
}

private function doMoveNodes(array $documents, $sourceQuery, $targetPath)
{
if (false === $this->globHelper->isGlobbed($sourceQuery)) {
if (false === $this->isGlobbed($sourceQuery)) {
return $this->getManager()->move(current($documents), $targetPath);
}

Expand Down
2 changes: 1 addition & 1 deletion Repository/PhpcrRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected function moveNodes(array $nodes, $sourceQuery, $targetPath)

private function doMoveNodes(array $nodes, $sourceQuery, $targetPath)
{
if (count($nodes) === 1 && current($nodes)->getPath() === $sourceQuery) {
if (false === $this->isGlobbed($sourceQuery)) {
return $this->session->move(current($nodes)->getPath(), $targetPath);
}

Expand Down

0 comments on commit 05be4f2

Please sign in to comment.