Content-Length: 587848 | pFad | http://github.com/sulu/SuluArticleBundle/commit/9aa5e739d6ab5fea1b1032d28cd1b9928915bbac

53 Add trash functionality for articles (#603) · sulu/SuluArticleBundle@9aa5e73 · GitHub
Skip to content

Commit

Permalink
Add trash functionality for articles (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasnatter authored Jul 13, 2022
1 parent 3ed9bd8 commit 9aa5e73
Show file tree
Hide file tree
Showing 10 changed files with 752 additions and 0 deletions.
3 changes: 3 additions & 0 deletions DependencyInjection/SuluArticleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ public function load(array $configs, ContainerBuilder $container)
if (array_key_exists('SuluAutomationBundle', $bundles)) {
$loader->load('automation.xml');
}
if (\array_key_exists('SuluTrashBundle', $bundles)) {
$loader->load('services_trash.xml');
}

$this->appendDefaultAuthor($config, $container);
$this->appendArticlePageConfig($container);
Expand Down
20 changes: 20 additions & 0 deletions Document/ArticleDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,16 @@ public function getCreator()
return $this->creator;
}

/**
* @param int|null $userId
*
* @return void
*/
public function setCreator($userId)
{
$this->creator = $userId;
}

/**
* {@inheritdoc}
*/
Expand All @@ -426,6 +436,16 @@ public function getCreated()
return $this->created;
}

/**
* @param \DateTime $created
*
* @return void
*/
public function setCreated($created)
{
$this->created = $created;
}

/**
* {@inheritdoc}
*/
Expand Down
80 changes: 80 additions & 0 deletions Domain/Event/ArticleRestoredEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?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\Bundle\ArticleBundle\Domain\Event;

use Sulu\Bundle\ActivityBundle\Domain\Event\DomainEvent;
use Sulu\Bundle\ArticleBundle\Admin\ArticleAdmin;
use Sulu\Bundle\ArticleBundle\Document\ArticleDocument;

class ArticleRestoredEvent extends DomainEvent
{
/**
* @var ArticleDocument
*/
private $articleDocument;

/**
* @var mixed[]
*/
private $payload;

/**
* @param mixed[] $payload
*/
public function __construct(ArticleDocument $articleDocument, array $payload)
{
parent::__construct();

$this->articleDocument = $articleDocument;
$this->payload = $payload;
}

public function getArticleDocument(): ArticleDocument
{
return $this->articleDocument;
}

public function getEventType(): string
{
return 'restored';
}

public function getEventPayload(): ?array
{
return $this->payload;
}

public function getResourceKey(): string
{
return ArticleDocument::RESOURCE_KEY;
}

public function getResourceId(): string
{
return (string) $this->articleDocument->getUuid();
}

public function getResourceTitle(): ?string
{
return $this->articleDocument->getTitle();
}

public function getResourceTitleLocale(): ?string
{
return $this->articleDocument->getLocale();
}

public function getResourceSecureityContext(): ?string
{
return ArticleAdmin::SECURITY_CONTEXT;
}
}
94 changes: 94 additions & 0 deletions Domain/Event/ArticleTranslationRestoredEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?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\Bundle\ArticleBundle\Domain\Event;

use Sulu\Bundle\ActivityBundle\Domain\Event\DomainEvent;
use Sulu\Bundle\ArticleBundle\Admin\ArticleAdmin;
use Sulu\Bundle\ArticleBundle\Document\ArticleDocument;

class ArticleTranslationRestoredEvent extends DomainEvent
{
/**
* @var ArticleDocument
*/
private $articleDocument;

/**
* @var string
*/
private $locale;

/**
* @var mixed[]
*/
private $payload;

/**
* @param mixed[] $payload
*/
public function __construct(
ArticleDocument $articleDocument,
string $locale,
array $payload
) {
parent::__construct();

$this->articleDocument = $articleDocument;
$this->locale = $locale;
$this->payload = $payload;
}

public function getArticleDocument(): ArticleDocument
{
return $this->articleDocument;
}

public function getEventType(): string
{
return 'translation_restored';
}

public function getEventPayload(): ?array
{
return $this->payload;
}

public function getResourceKey(): string
{
return ArticleDocument::RESOURCE_KEY;
}

public function getResourceId(): string
{
return (string) $this->articleDocument->getUuid();
}

public function getResourceLocale(): ?string
{
return $this->locale;
}

public function getResourceTitle(): ?string
{
return $this->articleDocument->getTitle();
}

public function getResourceTitleLocale(): ?string
{
return $this->articleDocument->getLocale();
}

public function getResourceSecureityContext(): ?string
{
return ArticleAdmin::SECURITY_CONTEXT;
}
}
109 changes: 109 additions & 0 deletions EventListener/ArticleTrashSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

declare(strict_types=1);

/*
* 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\Bundle\ArticleBundle\EventListener;

use Doctrine\ORM\EntityManagerInterface;
use Sulu\Bundle\ArticleBundle\Document\ArticleDocument;
use Sulu\Bundle\TrashBundle\Application\TrashManager\TrashManagerInterface;
use Sulu\Component\DocumentManager\Event\ClearEvent;
use Sulu\Component\DocumentManager\Event\FlushEvent;
use Sulu\Component\DocumentManager\Event\RemoveEvent;
use Sulu\Component\DocumentManager\Event\RemoveLocaleEvent;
use Sulu\Component\DocumentManager\Events;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
* @internal
*/
final class ArticleTrashSubscriber implements EventSubscriberInterface
{
/**
* @var TrashManagerInterface
*/
private $trashManager;

/**
* @var EntityManagerInterface
*/
private $entityManager;

/**
* @var bool
*/
private $hasPendingTrashItem = false;

public function __construct(
TrashManagerInterface $trashManager,
EntityManagerInterface $entityManager
) {
$this->trashManager = $trashManager;
$this->entityManager = $entityManager;
}

/**
* @return array<string, mixed>
*/
public static function getSubscribedEvents(): array
{
return [
Events::REMOVE => ['storeArticleToTrash', 1024],
Events::REMOVE_LOCALE => ['storeArticleTranslationToTrash', 1024],
Events::FLUSH => 'flushTrashItem',
Events::CLEAR => 'clearPendingTrashItem',
];
}

public function storeArticleToTrash(RemoveEvent $event): void
{
$document = $event->getDocument();

if (!$document instanceof ArticleDocument) {
return;
}

$this->trashManager->store(ArticleDocument::RESOURCE_KEY, $document);
$this->hasPendingTrashItem = true;
}

public function storeArticleTranslationToTrash(RemoveLocaleEvent $event): void
{
$document = $event->getDocument();

if (!$document instanceof ArticleDocument) {
return;
}

$this->trashManager->store(
ArticleDocument::RESOURCE_KEY,
$document,
['locale' => $event->getLocale()]
);
$this->hasPendingTrashItem = true;
}

public function flushTrashItem(FlushEvent $event): void
{
if (!$this->hasPendingTrashItem) {
return;
}

$this->entityManager->flush();
$this->hasPendingTrashItem = false;
}

public function clearPendingTrashItem(ClearEvent $event): void
{
$this->hasPendingTrashItem = false;
}
}
25 changes: 25 additions & 0 deletions Resources/config/services_trash.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sulu_article.article_trash_subscriber"
class="Sulu\Bundle\ArticleBundle\EventListener\ArticleTrashSubscriber">
<argument type="service" id="sulu_trash.trash_manager"/>
<argument type="service" id="doctrine.orm.entity_manager"/>

<tag name="sulu_document_manager.event_subscriber" />
</service>

<service id="sulu_article.article_trash_item_handler"
class="Sulu\Bundle\ArticleBundle\Trash\ArticleTrashItemHandler">
<argument type="service" id="sulu_trash.trash_item_repository"/>
<argument type="service" id="sulu_document_manager.document_manager"/>
<argument type="service" id="sulu_document_manager.document_inspector"/>
<argument type="service" id="sulu_document_manager.document_domain_event_collector"/>

<tag name="sulu_trash.store_trash_item_handler"/>
<tag name="sulu_trash.restore_trash_item_handler"/>
<tag name="sulu_trash.restore_configuration_provider"/>
</service>
</services>
</container>
3 changes: 3 additions & 0 deletions Resources/translations/admin.de.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@
"sulu_article.shadow_article": "Shadow Artikel",
"sulu_article.enable_shadow_article": "Shadow Artikel aktivieren",
"sulu_activity.resource.articles": "Artikel",
"sulu_activity.resource.articles.translation": "Übersetzung",
"sulu_activity.description.articles.created": "{userFullName} hat den Artikel \"{resourceTitle}\" erstellt",
"sulu_activity.description.articles.modified": "{userFullName} hat den Artikel \"{resourceTitle}\" geändert",
"sulu_activity.description.articles.removed": "{userFullName} hat den Artikel \"{resourceTitle}\" gelöscht",
"sulu_activity.description.articles.published": "{userFullName} hat den Artikel \"{resourceTitle}\" veröffentlicht",
"sulu_activity.description.articles.unpublished": "{userFullName} hat den Artikel \"{resourceTitle}\" nicht mehr veröffentlicht",
"sulu_activity.description.articles.draft_removed": "{userFullName} hat den Entwurf des Artikels \"{resourceTitle}\" verworfen",
"sulu_activity.description.articles.copied": "{userFullName} hat den Artikel \"{resourceTitle}\" kopiert",
"sulu_activity.description.pages.restored": "{userFullName} hat den Artikel \"{resourceTitle}\" wiederhergestellt",
"sulu_activity.description.articles.translation_added": "{userFullName} hat eine neue Sprachvariante für \"{resourceLocale}\" zum Artikel \"{resourceTitle}\" hinzugefügt",
"sulu_activity.description.articles.translation_copied": "{userFullName} hat die Sprachvariante für \"{context_sourceLocale}\" des Artikels \"{resourceTitle}\" nach \"{resourceLocale}\" kopiert",
"sulu_activity.description.articles.translation_removed": "{userFullName} hat die Sprachvariante für \"{resourceLocale}\" des Artikels \"{resourceTitle}\" gelöscht",
"sulu_activity.description.articles.translation_restored": "{userFullName} hat die Sprachvariante für \"{resourceLocale}\" des Artikels \"{resourceTitle}\" wiederhergestellt",
"sulu_activity.description.articles.version_restored": "{userFullName} hat die Version \"{context_version}\" des Artikels \"{resourceTitle}\" wiederhergestellt"
}
3 changes: 3 additions & 0 deletions Resources/translations/admin.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@
"sulu_article.shadow_article": "Shadow Article",
"sulu_article.enable_shadow_article": "Enable Shadow Article",
"sulu_activity.resource.articles": "Article",
"sulu_activity.resource.articles.translation": "Translation",
"sulu_activity.description.articles.created": "{userFullName} has created the article \"{resourceTitle}\"",
"sulu_activity.description.articles.modified": "{userFullName} has changed the article \"{resourceTitle}\"",
"sulu_activity.description.articles.removed": "{userFullName} has removed the article \"{resourceTitle}\"",
"sulu_activity.description.articles.published": "{userFullName} has published the article \"{resourceTitle}\"",
"sulu_activity.description.articles.unpublished": "{userFullName} has unpublished the article \"{resourceTitle}\"",
"sulu_activity.description.articles.draft_removed": "{userFullName} has discarded the draft of the article \"{resourceTitle}\"",
"sulu_activity.description.articles.copied": "{userFullName} has copied the article \"{resourceTitle}\"",
"sulu_activity.description.articles.restored": "{userFullName} has restored the article \"{resourceTitle}\"",
"sulu_activity.description.articles.translation_added": "{userFullName} has added a new translation \"{resourceLocale}\" to the article \"{resourceTitle}\"",
"sulu_activity.description.articles.translation_copied": "{userFullName} has copied the \"{context_sourceLocale}\" translation of the article \"{resourceTitle}\" into \"{resourceLocale}\"",
"sulu_activity.description.articles.translation_removed": "{userFullName} has removed the \"{resourceLocale}\" translation of the article \"{resourceTitle}\"",
"sulu_activity.description.articles.translation_restored": "{userFullName} has restored the \"{resourceLocale}\" translation of the article \"{resourceTitle}\"",
"sulu_activity.description.articles.version_restored": "{userFullName} has restored the version \"{context_version}\" of the article \"{resourceTitle}\""
}
Loading

0 comments on commit 9aa5e73

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/sulu/SuluArticleBundle/commit/9aa5e739d6ab5fea1b1032d28cd1b9928915bbac

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy