1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Superdesk Web Publisher Content Bundle. |
7
|
|
|
* |
8
|
|
|
* Copyright 2017 Sourcefabric z.ú. and contributors. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please see the |
11
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
12
|
|
|
* |
13
|
|
|
* @copyright 2017 Sourcefabric z.ú |
14
|
|
|
* @license http://www.superdesk.org/license |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace SWP\Bundle\ContentBundle\EventListener; |
18
|
|
|
|
19
|
|
|
use SWP\Bundle\ContentBundle\Event\ArticleEvent; |
20
|
|
|
use SWP\Bundle\ContentBundle\Model\ArticleInterface; |
21
|
|
|
use SWP\Bundle\ContentBundle\Service\ArticleServiceInterface; |
22
|
|
|
|
23
|
|
|
final class ArticlePublishListener |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var ArticleServiceInterface |
27
|
|
|
*/ |
28
|
|
|
private $articleService; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* ArticlePublishListener constructor. |
32
|
|
|
* |
33
|
|
|
* @param ArticleServiceInterface $articleService |
34
|
|
|
*/ |
35
|
|
|
public function __construct(ArticleServiceInterface $articleService) |
36
|
|
|
{ |
37
|
|
|
$this->articleService = $articleService; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param ArticleEvent $event |
42
|
|
|
*/ |
43
|
|
|
public function publish(ArticleEvent $event) |
44
|
|
|
{ |
45
|
|
|
$article = $event->getArticle(); |
46
|
|
|
|
47
|
|
|
if ($article->isPublished()) { |
48
|
|
|
return; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$this->articleService->publish($article); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param ArticleEvent $event |
56
|
|
|
*/ |
57
|
|
|
public function unpublish(ArticleEvent $event) |
58
|
|
|
{ |
59
|
|
|
$article = $event->getArticle(); |
60
|
|
|
|
61
|
|
|
if ($article->isPublished()) { |
62
|
|
|
$this->articleService->unpublish($article, ArticleInterface::STATUS_UNPUBLISHED); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param ArticleEvent $event |
68
|
|
|
*/ |
69
|
|
|
public function cancel(ArticleEvent $event) |
70
|
|
|
{ |
71
|
|
|
$this->articleService->unpublish($event->getArticle(), ArticleInterface::STATUS_CANCELED); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|