Skip to content

Commit

Permalink
Add last modified date to settings tab
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlagler authored and alexander-schranz committed Jun 7, 2024
1 parent 6608b76 commit 4230b77
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 122 deletions.
1 change: 1 addition & 0 deletions Content/ArticleDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ protected function getConfigurationBuilder(): BuilderInterface
['column' => 'created', 'title' => 'sulu_admin.created'],
['column' => 'title.raw', 'title' => 'sulu_admin.title'],
['column' => 'author_full_name.raw', 'title' => 'sulu_admin.author'],
['column' => 'last_modified_or_authored', 'title' => 'sulu_article.last_modified_or_authored'],
]
);

Expand Down
8 changes: 8 additions & 0 deletions Content/ArticleResourceItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ public function getPublished(): \DateTime
return $this->article->getPublished();
}

/**
* Returns lastModified.
*/
public function getLastModified(): ?\DateTime
{
return $this->article->getLastModified();
}

/**
* Returns authored.
*/
Expand Down
35 changes: 34 additions & 1 deletion Document/ArticleDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Sulu\Component\Content\Document\Behavior\ExtensionBehavior;
use Sulu\Component\Content\Document\Behavior\LocalizedAuditableBehavior;
use Sulu\Component\Content\Document\Behavior\LocalizedAuthorBehavior;
use Sulu\Component\Content\Document\Behavior\LocalizedLastModifiedBehavior;
use Sulu\Component\Content\Document\Behavior\LocalizedStructureBehavior;
use Sulu\Component\Content\Document\Behavior\ShadowLocaleBehavior;
use Sulu\Component\Content\Document\Behavior\StructureBehavior;
Expand Down Expand Up @@ -56,7 +57,8 @@ class ArticleDocument implements UuidBehavior,
ChildrenBehavior,
ArticleInterface,
ShadowLocaleBehavior,
WebspaceBehavior
WebspaceBehavior,
LocalizedLastModifiedBehavior
{
public const RESOURCE_KEY = 'articles';

Expand Down Expand Up @@ -147,6 +149,11 @@ class ArticleDocument implements UuidBehavior,
*/
protected $changed;

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

/**
* @var int
*/
Expand Down Expand Up @@ -427,6 +434,32 @@ public function getAuthored()
return $this->authored;
}

/**
* @return bool
*/
public function getLastModifiedEnabled()
{
return null !== $this->lastModified;
}

/**
* @param \DateTime|null $lastModified
*
* @return void
*/
public function setLastModified($lastModified)
{
$this->lastModified = $lastModified;
}

/**
* @return \DateTime|null
*/
public function getLastModified()
{
return $this->lastModified;
}

public function setAuthored($authored)
{
$this->authored = $authored;
Expand Down
51 changes: 51 additions & 0 deletions Document/ArticleViewDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,27 @@ class ArticleViewDocument implements ArticleViewDocumentInterface
*/
protected $seo;

/**
* @var \DateTime|null
*
* @Property(type="date")
*/
protected $lastModified;

/**
* @var \DateTime
*
* @Property(type="date")
*/
protected $authored;

/**
* @var \DateTime
*
* @Property(type="date")
*/
protected $lastModifiedOrAuthored;

/**
* @var string
*
Expand Down Expand Up @@ -484,6 +498,43 @@ public function setSeo(SeoViewObject $seo)
return $this;
}

/**
* @return \DateTime|null
*/
public function getLastModified()
{
return $this->lastModified;
}

/**
* @param \DateTime|null $lastModified
*
* @return $this|ArticleViewDocument
*/
public function setLastModified($lastModified)
{
$this->lastModified = $lastModified;

return $this;
}

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

/**
* @param \DateTime|null $lastModified
*
* @return $this|ArticleViewDocument
*/
public function setLastModifiedOrAuthored()
{
$this->lastModifiedOrAuthored = $this->lastModified ?? $this->authored;

return $this;
}

public function getAuthored()
{
return $this->authored;
Expand Down
25 changes: 25 additions & 0 deletions Document/ArticleViewDocumentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,22 @@ public function getSeo();
*/
public function setSeo(SeoViewObject $seo);

/**
* Returns lastModified.
*
* @return \DateTime|null
*/
public function getLastModified();

/**
* Set lastModified date.
*
* @param \DateTime|null $lastModified
*
* @return $this
*/
public function setLastModified($lastModified);

/**
* Returns authored.
*
Expand All @@ -271,6 +287,15 @@ public function getAuthored();
*/
public function setAuthored(?\DateTime $authored = null);

/**
* Returns lastModified or authored date.
*
* @return \DateTime|null
*/
public function getLastModifiedOrAuthored();

public function setLastModifiedOrAuthored();

/**
* Returns author full name.
*
Expand Down
7 changes: 7 additions & 0 deletions Document/Form/ArticleDocumentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ public function buildForm(FormBuilderInterface $builder, array $options)
]
);

$builder->add(
'lastModified',
DateTimeType::class,
[
'widget' => 'single_text',
]
);
$builder->add('author', TextType::class);
$builder->add(
'authored',
Expand Down
1 change: 1 addition & 0 deletions Document/Index/ArticleIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ protected function createOrUpdateArticle(
$this->setParentPageUuid($document, $article);
$article->setChanged($document->getChanged());
$article->setCreated($document->getCreated());
$article->setLastModified($document->getLastModified());
$article->setAuthored($document->getAuthored());
if ($document->getAuthor() && $author = $this->contactRepository->find($document->getAuthor())) {
$article->setAuthorId($author->getId());
Expand Down
15 changes: 15 additions & 0 deletions Resources/config/forms/article_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@
<title>sulu_page.editing_information</title>
</meta>
<properties>
<property name="lastModifiedEnabled" type="checkbox" colspan="6">
<meta>
<title>sulu_page.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_page.last_modified_date</title>
</meta>
</property>
<property name="authored" type="datetime" colspan="6">
<meta>
<title>sulu_page.authored_date</title>
Expand Down
2 changes: 2 additions & 0 deletions Resources/config/serializer/Document.ArticleDocument.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<property name="published" type="DateTime" groups="website,defaultArticle,smallArticle,preview"/>
<property name="author" type="integer" groups="website,defaultArticle,preview"/>
<property name="authored" type="DateTime" groups="website,defaultArticle,smallArticle,preview"/>
<virtual-property method="getLastModifiedEnabled" name="lastModifiedEnabled" serialized-name="lastModifiedEnabled" groups="defaultArticle,smallArticle,preview"/>
<property name="lastModified" type="DateTime" groups="website,defaultArticle,smallArticle,preview"/>
<property name="extensions" type="Sulu\Component\Content\Document\Extension\ExtensionContainer" serialized-name="ext" groups="defaultArticle,preview"/>

<property name="shadowLocale" type="string" serialized-name="shadowBaseLanguage" groups="defaultArticle"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<property name="changerFullName" type="string" expose="true"/>
<property name="created" type="DateTime" expose="true"/>
<property name="changed" type="DateTime" expose="true"/>
<property name="lastModified" type="DateTime" expose="true"/>
<property name="authored" type="DateTime" expose="true"/>
<property name="published" type="DateTime" expose="true"/>
<property name="publishedState" type="boolean" expose="true"/>
Expand Down
1 change: 1 addition & 0 deletions Resources/translations/admin.de.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"sulu_article.published": "Veröffentlicht",
"sulu_article.not_published": "Nicht Veröffentlicht",
"sulu_article.route": "Route",
"sulu_article.last_modified_or_authored": "Zuletzt geändert oder verfasst",
"sulu_activity.resource.articles": "Artikel",
"sulu_activity.resource.articles.translation": "Übersetzung",
"sulu_activity.description.articles.created": "{userFullName} hat den Artikel \"{resourceTitle}\" erstellt",
Expand Down
1 change: 1 addition & 0 deletions Resources/translations/admin.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"sulu_article.published": "Published",
"sulu_article.not_published": "Not Published",
"sulu_article.route": "Route",
"sulu_article.last_modified_or_authored": "Last modified or authored",
"sulu_activity.resource.articles": "Article",
"sulu_activity.resource.articles.translation": "Translation",
"sulu_activity.description.articles.created": "{userFullName} has created the article \"{resourceTitle}\"",
Expand Down
2 changes: 1 addition & 1 deletion Sitemap/ArticleSitemapProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protected function buildUrl(
$this->findUrl($articleView, $scheme, $host, $webspaceKey),
$articleView->getLocale(),
null,
$articleView->getChanged()
$articleView->getLastModified() ?? $articleView->getChanged()
);
}

Expand Down
21 changes: 21 additions & 0 deletions Trash/ArticleTrashItemHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@ public function store(object $article, array $options = []): TrashItemInterface
$structureData = $localizedArticle->getStructure()->toArray();

$articleTitles[$locale] = $localizedArticle->getTitle();
$lastModified = $localizedArticle->getLastModified() ? $localizedArticle->getLastModified()->format('c') : null;

$data['locales'][] = [
'title' => $localizedArticle->getTitle(),
'locale' => $locale,
'creator' => $localizedArticle->getCreator(),
'created' => $localizedArticle->getCreated()->format('c'),
'lastModified' => $lastModified,
'author' => $localizedArticle->getAuthor(),
'authored' => $localizedArticle->getAuthored()->format('c'),
'structureType' => $localizedArticle->getStructureType(),
Expand Down Expand Up @@ -145,6 +147,23 @@ public function restore(TrashItemInterface $trashItem, array $restoreFormData =
}
}

/** @var array{
* title: string,
* locale: string,
* creator: ?int,
* created: string,
* lastModified: ?string,
* author: ?int,
* authored: string,
* structureType: string,
* structureData: mixed,
* extensionsData: mixed,
* shadowLocaleEnabled: bool,
* shadowLocale: ?string,
* mainWebspace: ?string,
* additionalWebspaces: ?array<string>,
* } $localeData
*/
foreach ($sortedLocales as $localeData) {
$locale = $localeData['locale'];

Expand All @@ -157,11 +176,13 @@ public function restore(TrashItemInterface $trashItem, array $restoreFormData =
$localizedArticle->setParent($this->documentManager->find($data['parentUuid']));
$localizedArticle->setUuid($uuid);
}
$lastModified = array_key_exists('lastModified', $localeData) && $localeData['lastModified'] ? new \DateTime($localeData['lastModified']) : null;

$localizedArticle->setTitle($localeData['title']);
$localizedArticle->setLocale($locale);
$localizedArticle->setCreator($localeData['creator']);
$localizedArticle->setCreated(new \DateTime($localeData['created']));
$localizedArticle->setLastModified($lastModified);
$localizedArticle->setAuthor($localeData['author']);
$localizedArticle->setAuthored(new \DateTime($localeData['authored']));
$localizedArticle->setStructureType($localeData['structureType']);
Expand Down
Loading

0 comments on commit 4230b77

Please sign in to comment.