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 2 commits into
base: 0.x
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -54,10 +54,18 @@ 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 \DateTime($data['lastModified'])
: null
);
}

if (\array_key_exists('authored', $data)) {
$dimensionContent->setAuthored(
$data['authored']
? new \DateTimeImmutable($data['authored'])
? new \DateTime($data['authored'])
: null
);
}
Expand Down
4 changes: 4 additions & 0 deletions Content/Application/ContentMerger/Merger/AuthorMerger.php
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
10 changes: 8 additions & 2 deletions Content/Domain/Model/AuthorInterface.php
Expand Up @@ -17,11 +17,17 @@

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

public function getLastModified(): ?\DateTime;

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;
}
26 changes: 23 additions & 3 deletions Content/Domain/Model/AuthorTrait.php
Expand Up @@ -26,10 +26,30 @@ trait AuthorTrait
private $author;

/**
* @var \DateTimeImmutable|null
* @var \DateTime|null
*/
private $authored;

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

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

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

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

public function getAuthor(): ?ContactInterface
{
return $this->author;
Expand All @@ -40,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;
}
Expand Down
3 changes: 3 additions & 0 deletions Content/Domain/Model/TemplateTrait.php
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
3 changes: 2 additions & 1 deletion Content/Infrastructure/Doctrine/MetadataLoader.php
Expand Up @@ -117,7 +117,8 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void
}

if ($reflection->implementsInterface(AuthorInterface::class)) {
$this->addField($metadata, 'authored', '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);
}

Expand Down
6 changes: 5 additions & 1 deletion Content/Infrastructure/Sulu/Link/ContentLinkProvider.php
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
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
82 changes: 81 additions & 1 deletion Content/Infrastructure/Sulu/Structure/ContentDocument.php
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,79 @@ 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
{
throw $this->createReadOnlyException(__METHOD__);
}

public function getAuthored(): ?\DateTime
{
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;
}
}
15 changes: 11 additions & 4 deletions Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php
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
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
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
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
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
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
Expand Up @@ -38,5 +38,7 @@
"template": "example-2",
"title": "Test Example",
"url": "/my-example",
"workflowPlace": "unpublished"
"workflowPlace": "unpublished",
"lastModifiedEnabled": false,
"lastModified": null
}
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
Expand Up @@ -38,5 +38,7 @@
"title": "Test Example",
"url": "/my-example",
"workflowPlace": "unpublished",
"mainWebspace": "sulu-io"
"mainWebspace": "sulu-io",
"lastModifiedEnabled": false,
"lastModified": null
}