Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/6.13' into 7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ViniTou committed Oct 9, 2018
2 parents 997d600 + 29a2d0e commit 5179158
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 13 deletions.
13 changes: 11 additions & 2 deletions eZ/Publish/API/Repository/Tests/BaseContentServiceTest.php
Expand Up @@ -9,6 +9,7 @@
namespace eZ\Publish\API\Repository\Tests;

use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\User\User;

/**
* Base class for content specific tests.
Expand Down Expand Up @@ -68,8 +69,12 @@ protected function createContentVersion1EmptyBinaryField()
*
* @return \eZ\Publish\API\Repository\Values\Content\Content
*/
protected function createContentDraftVersion1($locationId = 56, $contentTypeIdentifier = 'forum', $contentFieldNameIdentifier = 'name')
{
protected function createContentDraftVersion1(
$locationId = 56,
$contentTypeIdentifier = 'forum',
$contentFieldNameIdentifier = 'name',
User $contentOwner = null
) {
$repository = $this->getRepository();

$parentLocationId = $this->generateId('location', $locationId);
Expand Down Expand Up @@ -102,6 +107,10 @@ protected function createContentDraftVersion1($locationId = 56, $contentTypeIden
$contentCreate->sectionId = $sectionId;
$contentCreate->alwaysAvailable = true;

if ($contentOwner) {
$contentCreate->ownerId = $contentOwner->id;
}

// Create a draft
$draft = $contentService->createContent($contentCreate, array($locationCreate));
/* END: Inline */
Expand Down
54 changes: 54 additions & 0 deletions eZ/Publish/API/Repository/Tests/ContentServiceTest.php
Expand Up @@ -3258,6 +3258,60 @@ public function testCopyContent()
);
}

/**
* Test for the copyContent() method with ezsettings.default.content.retain_owner_on_copy set to false
* See settings/test/integration_legacy.yml for service override.
*
* @see \eZ\Publish\API\Repository\ContentService::copyContent()
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
* @group field-type
*/
public function testCopyContentWithNewOwner()
{
$parentLocationId = $this->generateId('location', 56);

$repository = $this->getRepository();

$contentService = $repository->getContentService();
$locationService = $repository->getLocationService();
$userService = $repository->getUserService();

$newOwner = $this->createUser('new_owner', 'foo', 'bar');
/* BEGIN: Use Case */
/** @var \eZ\Publish\API\Repository\Values\Content\Content $contentVersion2 */
$contentVersion2 = $this->createContentDraftVersion1(
$parentLocationId,
'forum',
'name',
$newOwner
);

// Configure new target location
$targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);

$targetLocationCreate->priority = 42;
$targetLocationCreate->hidden = true;
$targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
$targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
$targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;

// Copy content with all versions and drafts
$contentCopied = $contentService->copyContent(
$contentVersion2->contentInfo,
$targetLocationCreate
);
/* END: Use Case */

$this->assertEquals(
$newOwner->id,
$contentVersion2->contentInfo->ownerId
);
$this->assertEquals(
$userService->loadUserByLogin('admin')->getUserId(),
$contentCopied->contentInfo->ownerId
);
}

/**
* Test for the copyContent() method.
*
Expand Down
10 changes: 7 additions & 3 deletions eZ/Publish/Core/Persistence/Cache/ContentHandler.php
Expand Up @@ -51,11 +51,15 @@ public function createDraftFromVersion($contentId, $srcVersion, $userId)
/**
* {@inheritdoc}
*/
public function copy($contentId, $versionNo = null)
public function copy($contentId, $versionNo = null, $newOwnerId = null)
{
$this->logger->logCall(__METHOD__, array('content' => $contentId, 'version' => $versionNo));
$this->logger->logCall(__METHOD__, array(
'content' => $contentId,
'version' => $versionNo,
'newOwner' => $newOwnerId,
));

return $this->persistenceHandler->contentHandler()->copy($contentId, $versionNo);
return $this->persistenceHandler->contentHandler()->copy($contentId, $versionNo, $newOwnerId);
}

/**
Expand Down
10 changes: 7 additions & 3 deletions eZ/Publish/Core/Persistence/Cache/LocationHandler.php
Expand Up @@ -140,11 +140,15 @@ public function loadByRemoteId($remoteId)
/**
* {@inheritdoc}
*/
public function copySubtree($sourceId, $destinationParentId)
public function copySubtree($sourceId, $destinationParentId, $newOwnerId = null)
{
$this->logger->logCall(__METHOD__, array('source' => $sourceId, 'destination' => $destinationParentId));
$this->logger->logCall(__METHOD__, array(
'source' => $sourceId,
'destination' => $destinationParentId,
'newOwner' => $newOwnerId,
));

return $this->persistenceHandler->locationHandler()->copySubtree($sourceId, $destinationParentId);
return $this->persistenceHandler->locationHandler()->copySubtree($sourceId, $destinationParentId, $newOwnerId);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion eZ/Publish/Core/Persistence/Legacy/Content/Handler.php
Expand Up @@ -684,10 +684,11 @@ public function listVersions($contentId, $status = null, $limit = -1)
*
* @param mixed $contentId
* @param mixed|null $versionNo Copy all versions if left null
* @param int|null $newOwnerId
*
* @return \eZ\Publish\SPI\Persistence\Content
*/
public function copy($contentId, $versionNo = null)
public function copy($contentId, $versionNo = null, $newOwnerId = null)
{
$currentVersionNo = isset($versionNo) ?
$versionNo :
Expand All @@ -697,6 +698,9 @@ public function copy($contentId, $versionNo = null)
$createStruct = $this->mapper->createCreateStructFromContent(
$this->load($contentId, $currentVersionNo)
);
if ($newOwnerId) {
$createStruct->ownerId = $newOwnerId;
}
$content = $this->internalCreate($createStruct, $currentVersionNo);

// If version was not passed also copy other versions
Expand Down
Expand Up @@ -211,10 +211,12 @@ protected function setContentStates(Content $content, array $contentStates)
*
* @param mixed $sourceId
* @param mixed $destinationParentId
* @param int|null $newOwnerId
*
* @return Location the newly created Location.
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
*/
public function copySubtree($sourceId, $destinationParentId)
public function copySubtree($sourceId, $destinationParentId, $newOwnerId = null)
{
$children = $this->locationGateway->getSubtreeContent($sourceId);
$destinationParentData = $this->locationGateway->getBasicNodeData($destinationParentId);
Expand Down Expand Up @@ -242,7 +244,8 @@ public function copySubtree($sourceId, $destinationParentId)
if (!isset($contentMap[$child['contentobject_id']])) {
$content = $this->contentHandler->copy(
$child['contentobject_id'],
$child['contentobject_version']
$child['contentobject_version'],
$newOwnerId
);

$this->setContentStates($content, $defaultObjectStates);
Expand Down
3 changes: 2 additions & 1 deletion eZ/Publish/Core/Repository/ContentService.php
Expand Up @@ -1677,7 +1677,8 @@ public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $dest
try {
$spiContent = $this->persistenceHandler->contentHandler()->copy(
$contentInfo->id,
$versionInfo ? $versionInfo->versionNo : null
$versionInfo ? $versionInfo->versionNo : null,
$this->repository->getPermissionResolver()->getCurrentUserReference()->getUserId()
);

$objectStateHandler = $this->persistenceHandler->objectStateHandler();
Expand Down
3 changes: 2 additions & 1 deletion eZ/Publish/Core/Repository/LocationService.php
Expand Up @@ -168,7 +168,8 @@ public function copySubtree(APILocation $subtree, APILocation $targetParentLocat
try {
$newLocation = $this->persistenceHandler->locationHandler()->copySubtree(
$loadedSubtree->id,
$loadedTargetLocation->id
$loadedTargetLocation->id,
$this->repository->getPermissionResolver()->getCurrentUserReference()->getUserId()
);

$content = $this->repository->getContentService()->loadContent($newLocation->contentId);
Expand Down
42 changes: 42 additions & 0 deletions eZ/Publish/Core/Repository/Tests/Service/Mock/ContentTest.php
Expand Up @@ -5415,6 +5415,20 @@ public function testCopyContent()
$contentInfoMock = $this->createMock(APIContentInfo::class);
$locationCreateStruct = new LocationCreateStruct();
$location = new Location(['id' => $locationCreateStruct->parentLocationId]);
$user = $this->getStubbedUser(14);

$permissionResolverMock = $this
->getMockBuilder('eZ\\Publish\\API\\Repository\\PermissionResolver')
->disableOriginalConstructor()
->getMock();

$permissionResolverMock
->method('getCurrentUserReference')
->willReturn($user);

$repositoryMock
->method('getPermissionResolver')
->willReturn($permissionResolverMock);

$repositoryMock->expects($this->exactly(3))
->method('getLocationService')
Expand Down Expand Up @@ -5530,6 +5544,20 @@ public function testCopyContentWithVersionInfo()
$contentInfoMock = $this->createMock(APIContentInfo::class);
$locationCreateStruct = new LocationCreateStruct();
$location = new Location(['id' => $locationCreateStruct->parentLocationId]);
$user = $this->getStubbedUser(14);

$permissionResolverMock = $this
->getMockBuilder('eZ\\Publish\\API\\Repository\\PermissionResolver')
->disableOriginalConstructor()
->getMock();

$permissionResolverMock
->method('getCurrentUserReference')
->willReturn($user);

$repositoryMock
->method('getPermissionResolver')
->willReturn($permissionResolverMock);

$repositoryMock->expects($this->exactly(3))
->method('getLocationService')
Expand Down Expand Up @@ -5642,6 +5670,20 @@ public function testCopyContentWithRollback()
$locationCreateStruct = new LocationCreateStruct();
$location = new Location(['id' => $locationCreateStruct->parentLocationId]);
$locationServiceMock = $this->getLocationServiceMock();
$user = $this->getStubbedUser(14);

$permissionResolverMock = $this
->getMockBuilder('eZ\\Publish\\API\\Repository\\PermissionResolver')
->disableOriginalConstructor()
->getMock();

$permissionResolverMock
->method('getCurrentUserReference')
->willReturn($user);

$repositoryMock
->method('getPermissionResolver')
->willReturn($permissionResolverMock);

$repositoryMock->expects($this->once())
->method('getLocationService')
Expand Down

0 comments on commit 5179158

Please sign in to comment.