Skip to content

Commit

Permalink
EZP-29586: Set ownership of copied Content Versions to the current Us…
Browse files Browse the repository at this point in the history
…er (#2464)

* EZP-29586: Properly handle owner of old content versions when copying

* EZP-29586: Properly handle owner of old content versions when copying - integration tests
  • Loading branch information
ViniTou authored and lserwatka committed Dec 13, 2019
1 parent 441ec54 commit 33e7998
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 17 additions & 4 deletions eZ/Publish/API/Repository/Tests/ContentServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3211,13 +3211,13 @@ public function testCopyContentWithNewOwner()

$userService = $this->getRepository()->getUserService();

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

// Configure new target location
Expand All @@ -3229,20 +3229,33 @@ public function testCopyContentWithNewOwner()
$targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
$targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;

$this->contentService->publishVersion($contentVersion2->versionInfo);
$this->contentService->createContentDraft($contentVersion2->contentInfo);

// Copy content with all versions and drafts
$contentCopied = $this->contentService->copyContent(
$contentVersion2->contentInfo,
$targetLocationCreate
);

$this->assertEquals(
$newOwner->id,
$owner->id,
$contentVersion2->contentInfo->ownerId
);
$newOwnerId = $userService->loadUserByLogin('admin')->getUserId();
$this->assertEquals(
$userService->loadUserByLogin('admin')->getUserId(),
$newOwnerId,
$contentCopied->contentInfo->ownerId
);
$versions = $this->contentService->loadVersions($contentCopied->contentInfo);
$this->assertCount(2, $versions);

foreach ($versions as $version) {
$this->assertEquals(
$newOwnerId,
$version->creatorId
);
}
}

/**
Expand Down
2 changes: 2 additions & 0 deletions eZ/Publish/Core/Persistence/Legacy/Content/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,8 @@ public function copy($contentId, $versionNo = null, $newOwnerId = null)
$versionContent->versionInfo->contentInfo->id = $content->versionInfo->contentInfo->id;
$versionContent->versionInfo->modificationDate = $createStruct->modified;
$versionContent->versionInfo->creationDate = $createStruct->modified;
$versionContent->versionInfo->creatorId = $createStruct->ownerId;

$versionContent->versionInfo->id = $this->contentGateway->insertVersion(
$versionContent->versionInfo,
$versionContent->fields
Expand Down

0 comments on commit 33e7998

Please sign in to comment.