-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy published date to live DimensionContent (#138)
* Copy published date to live DimensionContent * fix review issues * add tests
- Loading branch information
Showing
15 changed files
with
363 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
Content/Application/ContentDataMapper/DataMapper/WorkflowDataMapper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) Sulu GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\ContentBundle\Content\Application\ContentDataMapper\DataMapper; | ||
|
||
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; | ||
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionInterface; | ||
use Sulu\Bundle\ContentBundle\Content\Domain\Model\WorkflowInterface; | ||
|
||
class WorkflowDataMapper implements DataMapperInterface | ||
{ | ||
public function map( | ||
array $data, | ||
object $unlocalizedObject, | ||
?object $localizedObject = null | ||
): void { | ||
if (!$unlocalizedObject instanceof WorkflowInterface) { | ||
return; | ||
} | ||
|
||
if ($localizedObject) { | ||
if (!$localizedObject instanceof WorkflowInterface) { | ||
throw new \RuntimeException(sprintf('Expected "$localizedObject" from type "%s" but "%s" given.', WorkflowInterface::class, \get_class($localizedObject))); | ||
} | ||
|
||
$this->setWorkflowData($localizedObject, $data); | ||
|
||
return; | ||
} | ||
|
||
$this->setWorkflowData($unlocalizedObject, $data); | ||
} | ||
|
||
/** | ||
* @param mixed[] $data | ||
*/ | ||
private function setWorkflowData(WorkflowInterface $object, array $data): void | ||
{ | ||
if (!$object instanceof DimensionContentInterface | ||
|| DimensionInterface::STAGE_LIVE !== $object->getDimension()->getStage()) { | ||
return; | ||
} | ||
|
||
$published = $data['published'] ?? null; | ||
|
||
if (!$published) { | ||
return; | ||
} | ||
|
||
$object->setWorkflowPublished(new \DateTimeImmutable($published)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
Tests/Functional/Integration/responses/example_post_trigger_unpublish.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"excerptCategories": [], | ||
"excerptDescription": "Excerpt Description", | ||
"excerptIcon": null, | ||
"excerptImage": null, | ||
"excerptMore": "Excerpt More", | ||
"excerptTags": [ | ||
"Tag 1", | ||
"Tag 2" | ||
], | ||
"excerptTitle": "Excerpt Title", | ||
"id": "@integer@", | ||
"images": null, | ||
"published": null, | ||
"publishedState": false, | ||
"seoCanonicalUrl": "https:\/\/sulu.io\/", | ||
"seoDescription": "Seo Description", | ||
"seoHideInSitemap": true, | ||
"seoKeywords": "Seo Keyword 1, Seo Keyword 2", | ||
"seoNoFollow": true, | ||
"seoNoIndex": true, | ||
"seoTitle": "Seo Title", | ||
"template": "example-2", | ||
"title": "Test Example", | ||
"url": "\/my-example", | ||
"workflowPlace": "unpublished" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.