Skip to content
Merged
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
9 changes: 7 additions & 2 deletions packages/article/config/lists/articles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<entity-name>dimensionContent</entity-name>
<field-name>Sulu\Article\Domain\Model\ArticleInterface.dimensionContents</field-name>
<method>LEFT</method>
<condition>dimensionContent.locale = :locale AND dimensionContent.stage = 'draft'</condition>
<condition>dimensionContent.locale = :locale AND dimensionContent.stage = 'draft' AND dimensionContent.version = 0</condition>
</join>
</joins>

Expand All @@ -37,7 +37,7 @@
<entity-name>unlocalizedDimensionContent</entity-name>
<field-name>Sulu\Article\Domain\Model\ArticleInterface.dimensionContents</field-name>
<method>LEFT</method>
<condition>unlocalizedDimensionContent.locale IS NULL AND unlocalizedDimensionContent.stage = 'draft'</condition>
<condition>unlocalizedDimensionContent.locale IS NULL AND unlocalizedDimensionContent.stage = 'draft' AND unlocalizedDimensionContent.version = 0</condition>
</join>
</joins>

Expand All @@ -64,6 +64,11 @@
<entity-name>Sulu\Article\Domain\Model\ArticleInterface</entity-name>
</property>

<property name="version" visibility="never">
<field-name>version</field-name>
<entity-name>dimensionContent</entity-name>
</property>

<case-property name="title" translation="sulu_admin.title" visibility="always" searchability="yes">
<field>
<field-name>title</field-name>
Expand Down
69 changes: 69 additions & 0 deletions packages/article/config/lists/articles_versions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" ?>
<list xmlns="http://schemas.sulu.io/list-builder/list">
<key>articles_versions</key>

<joins name="dimensionContent">
<join>
<entity-name>dimensionContent</entity-name>
<field-name>Sulu\Article\Domain\Model\ArticleInterface.dimensionContents</field-name>
<method>INNER</method>
<condition>dimensionContent.locale = :locale AND dimensionContent.stage = 'draft' AND dimensionContent.version > 0 AND Sulu\Article\Domain\Model\ArticleInterface.uuid = :id</condition>
</join>
</joins>

<joins name="changer">
<join>
<entity-name>%sulu.model.user.class%</entity-name>
<field-name>dimensionContent.changer</field-name>
</join>
<join>
<entity-name>%sulu.model.contact.class%</entity-name>
<field-name>%sulu.model.user.class%.contact</field-name>
</join>
</joins>

<properties>
<!-- TODO should be uuid not id -->
<property name="id" translation="sulu_admin.uuid" visibility="never">
<field-name>uuid</field-name>
<entity-name>Sulu\Article\Domain\Model\ArticleInterface</entity-name>
</property>

<property name="title" translation="sulu_admin.title" visibility="always" searchability="yes">
<field-name>title</field-name>
<entity-name>dimensionContent</entity-name>

<joins ref="dimensionContent"/>

<transformer type="title"/>
</property>

<property name="version" translation="sulu_admin.published" visibility="yes">
<field-name>version</field-name>
<entity-name>dimensionContent</entity-name>

<transformer type="datetime"/>
</property>

<concatenation-property name="changer" glue=" " translation="sulu_admin.changer" sortable="false" visibility="yes">
<field>
<field-name>firstName</field-name>
<entity-name>%sulu.model.contact.class%</entity-name>

<joins ref="changer"/>
</field>
<field>
<field-name>lastName</field-name>
<entity-name>%sulu.model.contact.class%</entity-name>

<joins ref="changer"/>
</field>
</concatenation-property>

<property name="changed" translation="sulu_admin.changed">
<field-name>changed</field-name>
<entity-name>Sulu\Article\Domain\Model\ArticleInterface</entity-name>
<transformer type="datetime"/>
</property>
</properties>
</list>
6 changes: 6 additions & 0 deletions packages/article/config/routing_admin_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ sulu_article.get_articles:
controller: sulu_article.admin_article_controller::cgetAction
format: json

sulu_article.get_article_versions:
path: /articles/{id}/versions.{_format}
methods: GET
controller: sulu_article.admin_article_controller::getVersionsAction
format: json

sulu_article.get_article:
path: /articles/{id}.{_format}
methods: GET
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Article\Application\Message;

class RestoreArticleVersionMessage
{
/**
* @param array{
* uuid?: string,
* } $articleIdentifier
* @param array<string, mixed> $options
*/
public function __construct(
private array $articleIdentifier,
private int $version,
private array $options = []
) {
}

/**
* @return array{
* uuid?: string,
* }
*/
public function getArticleIdentifier(): array
{
return $this->articleIdentifier;
}

public function getVersion(): int
{
return $this->version;
}

/**
* @return array<string, mixed>
*/
public function getOptions(): array
{
return $this->options;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Article\Application\MessageHandler;

use Sulu\Article\Application\Message\RestoreArticleVersionMessage;
use Sulu\Article\Domain\Model\ArticleInterface;
use Sulu\Article\Domain\Repository\ArticleRepositoryInterface;
use Sulu\Content\Application\ContentCopier\ContentCopierInterface;
use Sulu\Content\Domain\Model\DimensionContentInterface;

/**
* @experimental
*
* @internal This class should not be instantiated by a project.
* Create your own Message and Handler instead.
*/
class RestoreArticleVersionMessageHandler
{
public function __construct(
private ArticleRepositoryInterface $articleRepository,
private ContentCopierInterface $contentCopier
) {
}

public function __invoke(RestoreArticleVersionMessage $message): ArticleInterface
{
$article = $this->articleRepository->getOneBy($message->getArticleIdentifier());
$options = $message->getOptions();

$dimensionContent = $this->contentCopier->copy(
$article,
[
'stage' => $options['stage'] ?? DimensionContentInterface::STAGE_DRAFT,
'locale' => $options['locale'] ?? null,
'version' => $message->getVersion(),
],
$article,
[
'stage' => $options['stage'] ?? DimensionContentInterface::STAGE_DRAFT,
'locale' => $options['locale'] ?? null,
'version' => DimensionContentInterface::CURRENT_VERSION,
],
[
'ignoredAttributes' => ['url'],
]
);

return $dimensionContent->getResource();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Sulu\Content\Domain\Model\SeoTrait;
use Sulu\Content\Domain\Model\ShadowTrait;
use Sulu\Content\Domain\Model\TemplateTrait;
//use Sulu\Content\Domain\Model\WebspaceTrait;
use Sulu\Content\Domain\Model\WebspaceTrait;
use Sulu\Content\Domain\Model\WorkflowTrait;

Expand Down
47 changes: 19 additions & 28 deletions packages/article/src/Infrastructure/Sulu/Admin/ArticleAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Sulu\Article\Infrastructure\Sulu\Admin;

use Sulu\Article\Domain\Model\ArticleInterface;
use Sulu\Bundle\ActivityBundle\Infrastructure\Sulu\Admin\View\ActivityViewBuilderFactoryInterface;
use Sulu\Bundle\AdminBundle\Admin\Admin;
use Sulu\Bundle\AdminBundle\Admin\Navigation\NavigationItem;
use Sulu\Bundle\AdminBundle\Admin\Navigation\NavigationItemCollection;
Expand Down Expand Up @@ -42,36 +43,13 @@ class ArticleAdmin extends Admin

public const EDIT_TABS_VIEW = 'sulu_article.article.edit_tabs';

/**
* @var ViewBuilderFactoryInterface
*/
private $viewBuilderFactory;

/**
* @var ContentViewBuilderFactoryInterface
*/
private $contentViewBuilderFactory;

/**
* @var SecurityCheckerInterface
*/
private $securityChecker;

/**
* @var LocalizationManagerInterface
*/
private $localizationManager;

public function __construct(
ViewBuilderFactoryInterface $viewBuilderFactory,
ContentViewBuilderFactoryInterface $contentViewBuilderFactory,
SecurityCheckerInterface $securityChecker,
LocalizationManagerInterface $localizationManager
private ViewBuilderFactoryInterface $viewBuilderFactory,
private ContentViewBuilderFactoryInterface $contentViewBuilderFactory,
private SecurityCheckerInterface $securityChecker,
private LocalizationManagerInterface $localizationManager,
private ActivityViewBuilderFactoryInterface $activityViewBuilderFactory,
) {
$this->viewBuilderFactory = $viewBuilderFactory;
$this->contentViewBuilderFactory = $contentViewBuilderFactory;
$this->securityChecker = $securityChecker;
$this->localizationManager = $localizationManager;
}

public function configureNavigationItems(NavigationItemCollection $navigationItemCollection): void
Expand Down Expand Up @@ -143,6 +121,19 @@ public function configureViews(ViewCollection $viewCollection): void
foreach ($viewBuilders as $viewBuilder) {
$viewCollection->add($viewBuilder);
}

if ($this->activityViewBuilderFactory->hasActivityListPermission()) {
$insightsResourceTabViewName = ArticleAdmin::EDIT_TABS_VIEW . '.insights';
$viewCollection->add(
$this->activityViewBuilderFactory
->createActivityListViewBuilder(
$insightsResourceTabViewName . '.activity',
'/activities',
ArticleInterface::RESOURCE_KEY
)
->setParent($insightsResourceTabViewName)
);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Sulu\Article\Application\MessageHandler\CreateArticleMessageHandler;
use Sulu\Article\Application\MessageHandler\ModifyArticleMessageHandler;
use Sulu\Article\Application\MessageHandler\RemoveArticleMessageHandler;
use Sulu\Article\Application\MessageHandler\RestoreArticleVersionMessageHandler;
use Sulu\Article\Domain\Model\Article;
use Sulu\Article\Domain\Model\ArticleDimensionContent;
use Sulu\Article\Domain\Model\ArticleDimensionContentInterface;
Expand Down Expand Up @@ -139,6 +140,14 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
])
->tag('messenger.message_handler');

$services->set('sulu_article.restore_article_version_handler')
->class(RestoreArticleVersionMessageHandler::class)
->args([
new Reference('sulu_article.article_repository'),
new Reference('sulu_content.content_copier'),
])
->tag('messenger.message_handler');

// Mapper service
$services->set('sulu_article.article_content_mapper')
->class(ArticleContentMapper::class)
Expand All @@ -155,6 +164,7 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
new Reference('sulu_content.content_view_builder_factory'),
new Reference('sulu_security.security_checker'),
new Reference('sulu.core.localization_manager'),
new Reference('sulu_activity.activity_list_view_builder_factory'),
])
->tag('sulu.context', ['context' => 'admin'])
->tag('sulu.admin');
Expand Down Expand Up @@ -287,6 +297,12 @@ public function prependExtension(ContainerConfigurator $container, ContainerBuil
'detail' => 'sulu_article.get_article',
],
],
'articles_versions' => [
'routes' => [
'list' => 'sulu_article.get_article_versions',
'detail' => 'sulu_article.get_article',
],
],
],
'field_type_options' => [
'selection' => [
Expand Down
Loading
Loading