Skip to content

Commit

Permalink
Add update date to settings tab
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlagler committed Jan 11, 2024
1 parent c890e28 commit 13099ae
Show file tree
Hide file tree
Showing 30 changed files with 146 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ 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'])
: null
);
}

if (\array_key_exists('authored', $data)) {
$dimensionContent->setAuthored(
$data['authored']
Expand Down
4 changes: 4 additions & 0 deletions Content/Application/ContentMerger/Merger/AuthorMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public function merge(object $targetObject, object $sourceObject): void
$targetObject->setAuthor($author);
}

if ($lastModified = $sourceObject->getLastModified()) {
$targetObject->setLastModified($lastModified);
}

if ($authored = $sourceObject->getAuthored()) {
$targetObject->setAuthored($authored);
}
Expand Down
6 changes: 6 additions & 0 deletions Content/Domain/Model/AuthorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

interface AuthorInterface
{
public function getLastModifiedEnabled(): ?bool;

public function getLastModified(): ?\DateTimeImmutable;

public function setLastModified(?\DateTimeImmutable $updated): void;

public function getAuthor(): ?ContactInterface;

public function setAuthor(?ContactInterface $author): void;
Expand Down
20 changes: 20 additions & 0 deletions Content/Domain/Model/AuthorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ trait AuthorTrait
*/
private $authored;

/**
* @var \DateTimeImmutable|null
*/
private $lastModified;

public function getLastModifiedEnabled(): ?bool
{
return null !== $this->lastModified;
}

public function getLastModified(): ?\DateTimeImmutable
{
return $this->lastModified;
}

public function setLastModified(?\DateTimeImmutable $lastModified): void
{
$this->lastModified = $lastModified;
}

public function getAuthor(): ?ContactInterface
{
return $this->author;
Expand Down
3 changes: 3 additions & 0 deletions Content/Domain/Model/TemplateTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public function getTemplateData(): array
return $this->templateData;
}

/**
* @param mixed[] $templateData
*/
public function setTemplateData(array $templateData): void
{
$this->templateData = $templateData;
Expand Down
1 change: 1 addition & 0 deletions Content/Infrastructure/Doctrine/MetadataLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ 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->addManyToOne($event, $metadata, 'author', ContactInterface::class, true);
}

Expand Down
6 changes: 5 additions & 1 deletion Content/Infrastructure/Sulu/Link/ContentLinkProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function preload(array $hrefs, $locale, $published = true): array
return null;
}

/** @var array{title?: string, name?: string} $data */
$data = $this->contentManager->normalize($resolvedDimensionContent);

return new LinkItem(
Expand All @@ -104,7 +105,10 @@ public function preload(array $hrefs, $locale, $published = true): array

/**
* @param B $dimensionContent
* @param mixed[] $data
* @param array{
* title?: string,
* name?: string
* } $data
*/
protected function getTitle(DimensionContentInterface $dimensionContent, array $data): ?string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function getMaxPage($scheme, $host): int
->getQuery()
->getSingleScalarResult();

return (int) \ceil($amount / $this->pageSize);
return (int) \ceil((int) $amount / $this->pageSize);
} catch (NoResultException|NonUniqueResultException $e) { // @codeCoverageIgnore
// TODO FIXME add testcase for this
return 0; // @codeCoverageIgnore
Expand Down
15 changes: 11 additions & 4 deletions Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ function(ContentRichEntityInterface $contentRichEntity) use ($locale): ?Teaser {
return null;
}

/** @var array{title?: string|null, name?: string|null} $data */
$data = $this->contentManager->normalize($resolvedDimensionContent);

return $this->createTeaser($resolvedDimensionContent, $data, $locale);
Expand All @@ -125,7 +126,10 @@ function(ContentRichEntityInterface $contentRichEntity) use ($locale): ?Teaser {

/**
* @param B $dimensionContent
* @param array<string, mixed> $data
* @param array{
* title?: string|null,
* name?: string|null
* } $data
*/
protected function createTeaser(DimensionContentInterface $dimensionContent, array $data, string $locale): ?Teaser
{
Expand All @@ -139,10 +143,10 @@ protected function createTeaser(DimensionContentInterface $dimensionContent, arr
$title = $this->getTitle($dimensionContent, $data);

/** @var string $description */
$description = $this->getDescription($dimensionContent, $data); // @phpstan-ignore-line
$description = $this->getDescription($dimensionContent, $data);

/** @var string $moreText */
$moreText = $this->getMoreText($dimensionContent, $data); // @phpstan-ignore-line
$moreText = $this->getMoreText($dimensionContent, $data);

/** @var int $mediaId */
$mediaId = $this->getMediaId($dimensionContent, $data);
Expand All @@ -162,7 +166,10 @@ protected function createTeaser(DimensionContentInterface $dimensionContent, arr

/**
* @param B $dimensionContent
* @param mixed[] $data
* @param array{
* title?: string|null,
* name?: string|null
* } $data
*/
protected function getTitle(DimensionContentInterface $dimensionContent, array $data): ?string
{
Expand Down
17 changes: 17 additions & 0 deletions Resources/config/forms/content_settings_author.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@
<title>sulu_content.author</title>
</meta>
<properties>
<property name="lastModifiedEnabled" type="checkbox" colspan="6">
<meta>
<title>sulu_content.last_modified_enabled</title>
</meta>

<params>
<param name="type" value="toggler"/>
<param name="default_value" value="false"/>
</params>
</property>

<property name="lastModified" type="datetime" colspan="6" disabledCondition="!lastModifiedEnabled">
<meta>
<title>sulu_content.last_modified_date</title>
</meta>
</property>

<property name="authored" type="datetime" colspan="6">
<meta>
<title>sulu_content.authored_date</title>
Expand Down
2 changes: 2 additions & 0 deletions Resources/translations/admin.de.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"sulu_content.excerpt": "Auszug & Taxonomien",
"sulu_content.content": "Inhalt",
"sulu_content.published": "Veröffentlicht am",
"sulu_content.last_modified_enabled": "Aktualisierungsdatum aktivieren",
"sulu_content.last_modified_date": "Datum der Aktualisierung",
"sulu_content.author": "Autor",
"sulu_content.authored_date": "Verfasst am",
"sulu_content.shadow_page": "Shadow Seite",
Expand Down
2 changes: 2 additions & 0 deletions Resources/translations/admin.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"sulu_content.excerpt": "Excerpt & Taxonomies",
"sulu_content.content": "Content",
"sulu_content.published": "Published on",
"sulu_content.last_modified_enabled": "Enable last modified date",
"sulu_content.last_modified_date": "Last modified date",
"sulu_content.author": "Author",
"sulu_content.authored_date": "Authored Date",
"sulu_content.shadow_page": "Shadow page",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function countBy(array $filters = []): int

$queryBuilder->select('COUNT(DISTINCT example.id)');

return (int) $queryBuilder->getQuery()->getSingleScalarResult(); // @phpstan-ignore-line
return (int) $queryBuilder->getQuery()->getSingleScalarResult();
}

/**
Expand Down
6 changes: 6 additions & 0 deletions Tests/Functional/Integration/ExampleControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public function testPostPublish(): int
'excerptMedia' => null,
'author' => null,
'authored' => '2020-05-08T00:00:00+00:00',
'lastModifiedEnabled' => true,
'lastModified' => '2022-05-08T00:00:00+00:00',
'mainWebspace' => 'sulu-io',
]) ?: null);

Expand Down Expand Up @@ -136,6 +138,8 @@ public function testPost(): int
'excerptMedia' => null,
'mainWebspace' => 'sulu-io',
'authored' => '2020-05-08T00:00:00+00:00',
'lastModifiedEnabled' => false,
'lastModified' => null,
]) ?: null);

$response = $this->client->getResponse();
Expand Down Expand Up @@ -226,6 +230,8 @@ public function testPut(int $id): void
'excerptMedia' => null,
'authored' => '2020-06-09T00:00:00+00:00',
'mainWebspace' => 'sulu-io2',
'lastModifiedEnabled' => true,
'lastModified' => '2022-05-08T00:00:00+00:00',
]) ?: null);

$response = $this->client->getResponse();
Expand Down
4 changes: 3 additions & 1 deletion Tests/Functional/Integration/responses/example_get.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@
"template": "example-2",
"title": "Test Example",
"url": "/my-example",
"workflowPlace": "unpublished"
"workflowPlace": "unpublished",
"lastModifiedEnabled": false,
"lastModified": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@
"stage": "draft",
"template": null,
"title": null,
"workflowPlace": null
"workflowPlace": null,
"lastModifiedEnabled": false,
"lastModified": null
}
4 changes: 3 additions & 1 deletion Tests/Functional/Integration/responses/example_post.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@
"title": "Test Example",
"url": "/my-example",
"workflowPlace": "unpublished",
"mainWebspace": "sulu-io"
"mainWebspace": "sulu-io",
"lastModifiedEnabled": false,
"lastModified": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@
"title": "Test Example",
"url": "/my-example",
"workflowPlace": "published",
"mainWebspace": "sulu-io"
"mainWebspace": "sulu-io",
"lastModifiedEnabled": true,
"lastModified": "2022-05-08T00:00:00+00:00"
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@
"template": "example-2",
"title": "Test Example",
"url": "/my-example",
"workflowPlace": "unpublished"
"workflowPlace": "unpublished",
"lastModifiedEnabled": false,
"lastModified": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@
"title": "Test Example",
"url": "\/my-example",
"workflowPlace": "unpublished",
"mainWebspace": "sulu-io"
"mainWebspace": "sulu-io",
"lastModifiedEnabled": true,
"lastModified": "2022-05-08T00:00:00+00:00"
}
2 changes: 2 additions & 0 deletions Tests/Functional/Integration/responses/example_put.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"author": null,
"authored": "2020-06-09T00:00:00+00:00",
"lastModifiedEnabled": true,
"lastModified": "2022-05-08T00:00:00+00:00",
"article": "<p>Test Article 2</p>",
"availableLocales": [
"en",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public function testMapData(): void
$data = [
'author' => 1,
'authored' => '2020-05-08T00:00:00+00:00',
'lastModifiedEnabled' => true,
'lastModified' => '2024-05-08T00:00:00+00:00',
];

$example = new Example();
Expand All @@ -100,15 +102,20 @@ public function testMapData(): void

$this->assertSame($contact, $localizedDimensionContent->getAuthor());
$authored = $localizedDimensionContent->getAuthored();
/** @var \DateTimeImmutable $lastModified */
$lastModified = $localizedDimensionContent->getLastModified();
$this->assertNotNull($authored);
$this->assertSame('2020-05-08T00:00:00+00:00', $authored->format('c'));
$this->assertSame('2024-05-08T00:00:00+00:00', $lastModified->format('c'));
}

public function testMapDataNull(): void
{
$data = [
'author' => null,
'authored' => null,
'lastModifiedEnabled' => false,
'lastModified' => '2024-05-08T00:00:00+00:00',
];

$example = new Example();
Expand All @@ -123,6 +130,7 @@ public function testMapDataNull(): void
$authorMapper = $this->createAuthorDataMapperInstance();
$authorMapper->map($unlocalizedDimensionContent, $localizedDimensionContent, $data);

$this->assertNull($localizedDimensionContent->getLastModified());
$this->assertNull($localizedDimensionContent->getAuthor());
$this->assertNull($localizedDimensionContent->getAuthored());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function testMapDefaultWebspace(): void

$webspace = new Webspace();
$webspace->setKey('default-webspace');
$this->webspaceCollection->setWebspaces([$webspace]);
$this->webspaceCollection->setWebspaces(['default-webspace' => $webspace]);

$authorMapper = $this->createWebspaceDataMapperInstance();
$authorMapper->map($unlocalizedDimensionContent, $localizedDimensionContent, $data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,17 @@ public function testMergeSet(): void

$contact = $this->prophesize(ContactInterface::class);
$authoredDate = new \DateTimeImmutable('2020-05-08T00:00:00+00:00');
$updateDate = new \DateTimeImmutable('2020-05-08T00:00:00+00:00');

$source = $this->prophesize(DimensionContentInterface::class);
$source->willImplement(AuthorInterface::class);
$source->getLastModified()->willReturn($updateDate)->shouldBeCalled();
$source->getAuthor()->willReturn($contact->reveal())->shouldBeCalled();
$source->getAuthored()->willReturn($authoredDate)->shouldBeCalled();

$target = $this->prophesize(DimensionContentInterface::class);
$target->willImplement(AuthorInterface::class);
$target->setLastModified($updateDate)->shouldBeCalled();
$target->setAuthor($contact->reveal())->shouldBeCalled();
$target->setAuthored($authoredDate)->shouldBeCalled();

Expand All @@ -83,11 +86,13 @@ public function testMergeNotSet(): void

$source = $this->prophesize(DimensionContentInterface::class);
$source->willImplement(AuthorInterface::class);
$source->getLastModified()->willReturn(null)->shouldBeCalled();
$source->getAuthor()->willReturn(null)->shouldBeCalled();
$source->getAuthored()->willReturn(null)->shouldBeCalled();

$target = $this->prophesize(DimensionContentInterface::class);
$target->willImplement(AuthorInterface::class);
$target->setLastModified(Argument::any())->shouldNotBeCalled();
$target->setAuthor(Argument::any())->shouldNotBeCalled();
$target->setAuthored(Argument::any())->shouldNotBeCalled();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,20 @@ public function testEnhance(): void
$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');

$data = [
'author' => $contact->reveal(),
'authored' => $authored,
'lastModifiedEnabled' => true,
'lastModified' => $lastModified,
];

$expectedResult = [
'author' => 1,
'authored' => $authored,
'lastModifiedEnabled' => true,
'lastModified' => $lastModified,
];

$this->assertSame(
Expand Down
Loading

0 comments on commit 13099ae

Please sign in to comment.