Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add update date to settings tab #255

Open
wants to merge 3 commits into
base: 0.8
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 $lastModified): 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
1 change: 1 addition & 0 deletions Content/Infrastructure/Doctrine/MetadataLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,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
85 changes: 84 additions & 1 deletion Content/Infrastructure/Sulu/Structure/ContentDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -151,4 +156,82 @@ protected function createReadOnlyException(string $method): \BadMethodCallExcept
)
);
}

public function getLastModifiedEnabled(): ?bool
{
if ($this->content instanceof AuthorInterface) {
return $this->content->getLastModifiedEnabled();
}

return null;
}

public function getLastModified(): ?\DateTimeImmutable
{
if ($this->content instanceof AuthorInterface) {
return $this->content->getLastModified();
}

return null;
}

/**
* @param \DateTimeImmutable|null $lastModified
*/
public function setLastModified($lastModified): void
{
throw $this->createReadOnlyException(__METHOD__);
}

/**
* @return \DateTimeInterface|null
*/
public function getAuthored()
{
if ($this->content instanceof AuthorInterface) {
return $this->content->getAuthored();
}

return null;
}

public function setAuthored($authored): void
{
throw $this->createReadOnlyException(__METHOD__);
}

public function getAuthor(): ?ContactInterface
{
if ($this->content instanceof AuthorInterface) {
return $this->content->getAuthor();
}

return null;
}

/**
* @param ContactInterface|null $contactId
*/
public function setAuthor($contactId): void
{
throw $this->createReadOnlyException(__METHOD__);
}

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;
}
}
10 changes: 7 additions & 3 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 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
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
Loading
Loading