Skip to content

Commit

Permalink
EZP-30899: Propagated ContentInfo::isHidden status when publishing (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
konradoboza authored and lserwatka committed Oct 4, 2019
1 parent 3b29de3 commit 497ec7a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ function (Repository $repository) use ($locationId) {

$request = $this->requestStack->getCurrentRequest();
if (!$request || !$request->attributes->get(PreviewController::PREVIEW_PARAMETER_NAME, false)) {
if ($location->invisible) {
if ($location->invisible || $location->hidden) {
throw new HiddenLocationException($location, 'Location cannot be displayed as it is flagged as invisible.');
}
}
Expand Down
2 changes: 2 additions & 0 deletions eZ/Publish/Core/Persistence/Legacy/Content/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private function createContentInfoFromCreateStruct(CreateStruct $struct, $curren
$contentInfo->currentVersionNo = $currentVersionNo;
$contentInfo->status = ContentInfo::STATUS_DRAFT;
$contentInfo->isPublished = false;
$contentInfo->isHidden = $struct->isHidden;

return $contentInfo;
}
Expand Down Expand Up @@ -507,6 +508,7 @@ public function createCreateStructFromContent(Content $content)
$struct->initialLanguageId = $this->languageHandler->loadByLanguageCode($content->versionInfo->initialLanguageCode)->id;
$struct->mainLanguageId = $this->languageHandler->loadByLanguageCode($content->versionInfo->contentInfo->mainLanguageCode)->id;
$struct->modified = time();
$struct->isHidden = $content->versionInfo->contentInfo->isHidden;

foreach ($content->fields as $field) {
$newField = clone $field;
Expand Down
4 changes: 3 additions & 1 deletion eZ/Publish/Core/Repository/ContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1692,11 +1692,13 @@ protected function internalPublishVersion(APIVersionInfo $versionInfo, $publicat
$publicationDate = $currentTime;
}

$contentInfo = $versionInfo->getContentInfo();
$metadataUpdateStruct = new SPIMetadataUpdateStruct();
$metadataUpdateStruct->publicationDate = $publicationDate;
$metadataUpdateStruct->modificationDate = $currentTime;
$metadataUpdateStruct->isHidden = $contentInfo->isHidden;

$contentId = $versionInfo->getContentInfo()->id;
$contentId = $contentInfo->id;
$spiContent = $this->persistenceHandler->contentHandler()->publish(
$contentId,
$versionInfo->versionNo,
Expand Down
27 changes: 20 additions & 7 deletions eZ/Publish/Core/Repository/Tests/Service/Mock/ContentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5483,8 +5483,14 @@ public function testCopyContent()

$contentInfoMock->expects($this->any())
->method('__get')
->with('id')
->will($this->returnValue(42));
->will(
$this->returnValueMap(
[
['isHidden', true],
['id', 42],
]
)
);
$versionInfoMock = $this->createMock(APIVersionInfo::class);

$versionInfoMock->expects($this->any())
Expand Down Expand Up @@ -5542,7 +5548,7 @@ public function testCopyContent()
->will($this->returnValue($versionInfoMock));

/* @var \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfoMock */
$content = $this->mockPublishVersion(123456, 126666);
$content = $this->mockPublishVersion(123456, 126666, true);
$locationServiceMock->expects($this->once())
->method('createLocation')
->with(
Expand Down Expand Up @@ -5608,8 +5614,13 @@ public function testCopyContentWithVersionInfo()

$contentInfoMock->expects($this->any())
->method('__get')
->with('id')
->will($this->returnValue(42));
->will(
$this->returnValueMap([
['isHidden', true],
['id', 42],
])
);

$versionInfoMock = $this->createMock(APIVersionInfo::class);

$versionInfoMock->expects($this->any())
Expand Down Expand Up @@ -5665,7 +5676,7 @@ public function testCopyContentWithVersionInfo()
->will($this->returnValue($versionInfoMock));

/* @var \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfoMock */
$content = $this->mockPublishVersion(123456, 126666);
$content = $this->mockPublishVersion(123456, 126666, true);
$locationServiceMock->expects($this->once())
->method('createLocation')
->with(
Expand Down Expand Up @@ -5862,10 +5873,11 @@ protected function mockSetDefaultObjectStates()
/**
* @param int|null $publicationDate
* @param int|null $modificationDate
* @param bool $isHidden
*
* @return \eZ\Publish\API\Repository\Values\Content\Content
*/
protected function mockPublishVersion($publicationDate = null, $modificationDate = null)
protected function mockPublishVersion($publicationDate = null, $modificationDate = null, $isHidden = false)
{
$versionInfoMock = $this->createMock(APIVersionInfo::class);
$contentInfoMock = $this->createMock(APIContentInfo::class);
Expand Down Expand Up @@ -5925,6 +5937,7 @@ protected function mockPublishVersion($publicationDate = null, $modificationDate
// Account for 1 second of test execution time
$metadataUpdateStruct->publicationDate = $publicationDate;
$metadataUpdateStruct->modificationDate = $modificationDate ?? $currentTime;
$metadataUpdateStruct->isHidden = $isHidden;

$contentHandlerMock->expects($this->once())
->method('publish')
Expand Down
7 changes: 7 additions & 0 deletions eZ/Publish/SPI/Persistence/Content/CreateStruct.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,11 @@ class CreateStruct extends ValueObject
* @var int
*/
public $modified;

/**
* Is hidden flag.
*
* @var bool
*/
public $isHidden;
}

0 comments on commit 497ec7a

Please sign in to comment.