diff --git a/Content/Application/ContentDataMapper/DataMapper/AuthorDataMapper.php b/Content/Application/ContentDataMapper/DataMapper/AuthorDataMapper.php index 37a02a8e..998f484c 100644 --- a/Content/Application/ContentDataMapper/DataMapper/AuthorDataMapper.php +++ b/Content/Application/ContentDataMapper/DataMapper/AuthorDataMapper.php @@ -57,7 +57,7 @@ private function setAuthorData(AuthorInterface $dimensionContent, array $data): if (\array_key_exists('lastModified', $data)) { $dimensionContent->setLastModified( $data['lastModified'] && (\array_key_exists('lastModifiedEnabled', $data) && $data['lastModifiedEnabled']) - ? new \DateTimeImmutable($data['lastModified']) + ? new \DateTime($data['lastModified']) : null ); } @@ -65,7 +65,7 @@ private function setAuthorData(AuthorInterface $dimensionContent, array $data): if (\array_key_exists('authored', $data)) { $dimensionContent->setAuthored( $data['authored'] - ? new \DateTimeImmutable($data['authored']) + ? new \DateTime($data['authored']) : null ); } diff --git a/Content/Domain/Model/AuthorInterface.php b/Content/Domain/Model/AuthorInterface.php index 3e9d5d65..9e765a7c 100644 --- a/Content/Domain/Model/AuthorInterface.php +++ b/Content/Domain/Model/AuthorInterface.php @@ -19,15 +19,15 @@ interface AuthorInterface { public function getLastModifiedEnabled(): ?bool; - public function getLastModified(): ?\DateTimeImmutable; + public function getLastModified(): ?\DateTime; - public function setLastModified(?\DateTimeImmutable $lastModified): void; + public function setLastModified(?\DateTime $lastModified): void; public function getAuthor(): ?ContactInterface; public function setAuthor(?ContactInterface $author): void; - public function getAuthored(): ?\DateTimeImmutable; + public function getAuthored(): ?\DateTime; - public function setAuthored(?\DateTimeImmutable $authored): void; + public function setAuthored(?\DateTime $authored): void; } diff --git a/Content/Domain/Model/AuthorTrait.php b/Content/Domain/Model/AuthorTrait.php index 6c2bd53a..ff5d700f 100644 --- a/Content/Domain/Model/AuthorTrait.php +++ b/Content/Domain/Model/AuthorTrait.php @@ -26,12 +26,12 @@ trait AuthorTrait private $author; /** - * @var \DateTimeImmutable|null + * @var \DateTime|null */ private $authored; /** - * @var \DateTimeImmutable|null + * @var \DateTime|null */ private $lastModified; @@ -40,12 +40,12 @@ public function getLastModifiedEnabled(): ?bool return null !== $this->lastModified; } - public function getLastModified(): ?\DateTimeImmutable + public function getLastModified(): ?\DateTime { return $this->lastModified; } - public function setLastModified(?\DateTimeImmutable $lastModified): void + public function setLastModified(?\DateTime $lastModified): void { $this->lastModified = $lastModified; } @@ -60,12 +60,12 @@ public function setAuthor(?ContactInterface $author): void $this->author = $author; } - public function getAuthored(): ?\DateTimeImmutable + public function getAuthored(): ?\DateTime { return $this->authored; } - public function setAuthored(?\DateTimeImmutable $authored): void + public function setAuthored(?\DateTime $authored): void { $this->authored = $authored; } diff --git a/Content/Infrastructure/Doctrine/MetadataLoader.php b/Content/Infrastructure/Doctrine/MetadataLoader.php index e3a0b7e5..cf56377e 100644 --- a/Content/Infrastructure/Doctrine/MetadataLoader.php +++ b/Content/Infrastructure/Doctrine/MetadataLoader.php @@ -117,8 +117,8 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void } if ($reflection->implementsInterface(AuthorInterface::class)) { - $this->addField($metadata, 'authored', 'datetime_immutable', ['nullable' => true]); - $this->addField($metadata, 'lastModified', 'datetime_immutable', ['nullable' => true]); + $this->addField($metadata, 'authored', 'datetime', ['nullable' => true]); + $this->addField($metadata, 'lastModified', 'datetime', ['nullable' => true]); $this->addManyToOne($event, $metadata, 'author', ContactInterface::class, true); } diff --git a/Content/Infrastructure/Sulu/Structure/ContentDocument.php b/Content/Infrastructure/Sulu/Structure/ContentDocument.php index d5fa0954..5bb71843 100644 --- a/Content/Infrastructure/Sulu/Structure/ContentDocument.php +++ b/Content/Infrastructure/Sulu/Structure/ContentDocument.php @@ -13,12 +13,17 @@ namespace Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Structure; +use Sulu\Bundle\ContactBundle\Entity\ContactInterface; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\AuthorInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\ExcerptInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\SeoInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface; use Sulu\Component\Content\Document\Behavior\ExtensionBehavior; +use Sulu\Component\Content\Document\Behavior\LocalizedAuthorBehavior; +use Sulu\Component\Persistence\Model\UserBlameInterface; +use Sulu\Component\Security\Authentication\UserInterface; -class ContentDocument implements ExtensionBehavior +class ContentDocument implements ExtensionBehavior, LocalizedAuthorBehavior { /** * @var TemplateInterface @@ -151,4 +156,85 @@ protected function createReadOnlyException(string $method): \BadMethodCallExcept ) ); } + + public function getLastModifiedEnabled(): ?bool + { + if ($this->content instanceof AuthorInterface) { + return $this->content->getLastModifiedEnabled(); + } + + return null; + } + + public function getLastModified(): ?\DateTime + { + if ($this->content instanceof AuthorInterface) { + return $this->content->getLastModified(); + } + + return null; + } + + /** + * @param \DateTime|null $lastModified + */ + public function setLastModified($lastModified): void + { + if ($this->content instanceof AuthorInterface) { + $this->content->setLastModified($lastModified); + } + } + + public function getAuthored(): ?\DateTime + { + if ($this->content instanceof AuthorInterface) { + return $this->content->getAuthored(); + } + + return null; + } + + public function setAuthored($authored): void + { + if ($this->content instanceof AuthorInterface) { + $this->content->setAuthored($authored); + } + } + + public function getAuthor(): ?ContactInterface + { + if ($this->content instanceof AuthorInterface) { + return $this->content->getAuthor(); + } + + return null; + } + + /** + * @param ContactInterface|null $contactId + */ + public function setAuthor($contactId): void + { + if ($this->content instanceof AuthorInterface) { + $this->content->setAuthor($contactId); + } + } + + public function getCreator(): ?UserInterface + { + if ($this->content instanceof UserBlameInterface) { + return $this->content->getCreator(); + } + + return null; + } + + public function getChanger(): ?UserInterface + { + if ($this->content instanceof UserBlameInterface) { + return $this->content->getChanger(); + } + + return null; + } } diff --git a/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/AuthorDataMapperTest.php b/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/AuthorDataMapperTest.php index 40ab710f..bfec8887 100644 --- a/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/AuthorDataMapperTest.php +++ b/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/AuthorDataMapperTest.php @@ -102,7 +102,7 @@ public function testMapData(): void $this->assertSame($contact, $localizedDimensionContent->getAuthor()); $authored = $localizedDimensionContent->getAuthored(); - /** @var \DateTimeImmutable $lastModified */ + /** @var \DateTime $lastModified */ $lastModified = $localizedDimensionContent->getLastModified(); $this->assertNotNull($authored); $this->assertSame('2020-05-08T00:00:00+00:00', $authored->format('c')); @@ -122,7 +122,7 @@ public function testMapDataNull(): void $unlocalizedDimensionContent = new ExampleDimensionContent($example); $localizedDimensionContent = new ExampleDimensionContent($example); $localizedDimensionContent->setAuthor(new Contact()); - $localizedDimensionContent->setAuthored(new \DateTimeImmutable()); + $localizedDimensionContent->setAuthored(new \DateTime()); $this->contactFactory->create(Argument::cetera()) ->shouldNotBeCalled(); diff --git a/Tests/Unit/Content/Application/ContentMerger/Merger/AuthorMergerTest.php b/Tests/Unit/Content/Application/ContentMerger/Merger/AuthorMergerTest.php index d9e2133a..4d7b700f 100644 --- a/Tests/Unit/Content/Application/ContentMerger/Merger/AuthorMergerTest.php +++ b/Tests/Unit/Content/Application/ContentMerger/Merger/AuthorMergerTest.php @@ -62,8 +62,8 @@ public function testMergeSet(): void $merger = $this->getAuthorMergerInstance(); $contact = $this->prophesize(ContactInterface::class); - $authoredDate = new \DateTimeImmutable('2020-05-08T00:00:00+00:00'); - $lastModifiedDate = new \DateTimeImmutable('2020-05-08T00:00:00+00:00'); + $authoredDate = new \DateTime('2020-05-08T00:00:00+00:00'); + $lastModifiedDate = new \DateTime('2020-05-08T00:00:00+00:00'); $source = $this->prophesize(DimensionContentInterface::class); $source->willImplement(AuthorInterface::class); diff --git a/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/AuthorNormalizerTest.php b/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/AuthorNormalizerTest.php index 8c943a71..61b61063 100644 --- a/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/AuthorNormalizerTest.php +++ b/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/AuthorNormalizerTest.php @@ -59,7 +59,7 @@ public function testEnhanceNotImplementAuthorInterface(): void $data = [ 'author' => 1, - 'authored' => new \DateTimeImmutable('2020-05-08T00:00:00+00:00'), + 'authored' => new \DateTime('2020-05-08T00:00:00+00:00'), ]; $this->assertSame( @@ -76,8 +76,8 @@ public function testEnhance(): void $contact = $this->prophesize(ContactInterface::class); $contact->getId()->shouldBeCalled()->willReturn(1); $object->getAuthor()->willReturn($contact->reveal()); - $authored = new \DateTimeImmutable('2020-05-08T00:00:00+00:00'); - $lastModified = new \DateTimeImmutable('2022-05-08T00:00:00+00:00'); + $authored = new \DateTime('2020-05-08T00:00:00+00:00'); + $lastModified = new \DateTime('2022-05-08T00:00:00+00:00'); $data = [ 'author' => $contact->reveal(), diff --git a/Tests/Unit/Content/Domain/Model/AuthorTraitTest.php b/Tests/Unit/Content/Domain/Model/AuthorTraitTest.php index ca080696..2ffe0cf7 100644 --- a/Tests/Unit/Content/Domain/Model/AuthorTraitTest.php +++ b/Tests/Unit/Content/Domain/Model/AuthorTraitTest.php @@ -42,7 +42,7 @@ public function testGetSetAuthor(): void public function testGetSetAuthored(): void { $model = $this->getAuthorInstance(); - $authored = new \DateTimeImmutable('2020-05-08T00:00:00+00:00'); + $authored = new \DateTime('2020-05-08T00:00:00+00:00'); $this->assertNull($model->getAuthored()); $model->setAuthored($authored); $this->assertSame($authored, $model->getAuthored()); @@ -51,7 +51,7 @@ public function testGetSetAuthored(): void public function testGetSetLastModified(): void { $model = $this->getAuthorInstance(); - $lastModified = new \DateTimeImmutable('2024-05-08T00:00:00+00:00'); + $lastModified = new \DateTime('2024-05-08T00:00:00+00:00'); $model->setLastModified($lastModified); $this->assertTrue($model->getLastModifiedEnabled()); $this->assertSame($lastModified, $model->getLastModified()); diff --git a/composer.json b/composer.json index 75224ea4..c7df5bec 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "friendsofsymfony/rest-bundle": "^2.6 || ^3.0", "massive/search-bundle": "^2.4", "ramsey/uuid": "^3.8 || ^4.0", - "sulu/sulu": "^2.4 || ^2.6@dev", + "sulu/sulu": "dev-feature/updated-date as 2.5.99", "symfony/config": "^4.4 || ^5.4 || ^6.0", "symfony/dependency-injection": "^4.4 || ^5.4 || ^6.0", "symfony/event-dispatcher": "^4.4 || ^5.4 || ^6.0",