Skip to content

Commit

Permalink
Merge branch '6.13' into 7.5
Browse files Browse the repository at this point in the history
  • Loading branch information
alongosz committed Aug 26, 2019
2 parents b7c787b + b26b7e5 commit 39091b7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
50 changes: 50 additions & 0 deletions eZ/Publish/API/Repository/Tests/LocationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2747,6 +2747,56 @@ public function testMoveSubtreeThrowsInvalidArgumentException()
/* END: Use Case */
}

/**
* Test that Legacy ezcontentobject_tree.path_identification_string field is correctly updated
* after moving subtree.
*
* @covers \eZ\Publish\API\Repository\LocationService::moveSubtree
*
* @throws \ErrorException
* @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
*/
public function testMoveSubtreeUpdatesPathIdentificationString(): void
{
$repository = $this->getRepository();
$locationService = $repository->getLocationService();

$topNode = $this->createFolder(['eng-US' => 'top_node'], 2);

$newParentLocation = $locationService->loadLocation(
$this
->createFolder(['eng-US' => 'Parent'], $topNode->contentInfo->mainLocationId)
->contentInfo
->mainLocationId
);
$location = $locationService->loadLocation(
$this
->createFolder(['eng-US' => 'Move Me'], $topNode->contentInfo->mainLocationId)
->contentInfo
->mainLocationId
);

$locationService->moveSubtree($location, $newParentLocation);

// path location string is not present on API level, so we need to query database
$serviceContainer = $this->getSetupFactory()->getServiceContainer();
/** @var \Doctrine\DBAL\Connection $connection */
$connection = $serviceContainer->get('ezpublish.persistence.connection');
$query = $connection->createQueryBuilder();
$query
->select('path_identification_string')
->from('ezcontentobject_tree')
->where('node_id = :nodeId')
->setParameter('nodeId', $location->id);

self::assertEquals(
'top_node/parent/move_me',
$query->execute()->fetchColumn()
);
}

/**
* Loads properties from all locations in the $location's subtree.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,15 @@ public function moveSubtreeNodes(array $sourceNodeData, array $destinationNodeDa
$destinationNodeData['path_string'],
'prefix' . $row['path_string']
);
$replace = rtrim($destinationNodeData['path_identification_string'], '/');
if (empty($oldParentPathIdentificationString)) {
$replace .= '/';
}
$newPathIdentificationString = str_replace(
'prefix' . $oldParentPathIdentificationString,
$destinationNodeData['path_identification_string'] . '/',
$replace,
'prefix' . $row['path_identification_string']
);

$newParentId = $row['parent_node_id'];
if ($row['path_string'] === $fromPathString) {
$newParentId = (int)implode('', array_slice(explode('/', $newPathString), -3, 1));
Expand Down

0 comments on commit 39091b7

Please sign in to comment.