|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Superdesk Web Publisher Core 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\CoreBundle\EventSubscriber; |
|
18
|
|
|
|
|
19
|
|
|
use SWP\Bundle\ContentBundle\ArticleEvents; |
|
20
|
|
|
use SWP\Bundle\ContentBundle\Event\ArticleEvent; |
|
21
|
|
|
use SWP\Bundle\CoreBundle\Model\ArticleInterface; |
|
22
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
23
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
24
|
|
|
|
|
25
|
|
|
class ArticlePublishSubscriber implements EventSubscriberInterface |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var ContainerInterface |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $container; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* ArticlePublishSubscriber constructor. |
|
34
|
|
|
* |
|
35
|
|
|
* @param ContainerInterface $container |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct(ContainerInterface $container) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->container = $container; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* {@inheritdoc} |
|
44
|
|
|
*/ |
|
45
|
|
|
public static function getSubscribedEvents() |
|
46
|
|
|
{ |
|
47
|
|
|
return [ |
|
48
|
|
|
ArticleEvents::POST_PUBLISH => 'onPublish', |
|
49
|
|
|
]; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param ArticleEvent $event |
|
54
|
|
|
*/ |
|
55
|
|
View Code Duplication |
public function onPublish(ArticleEvent $event) |
|
|
|
|
|
|
56
|
|
|
{ |
|
57
|
|
|
/** @var ArticleInterface $article */ |
|
58
|
|
|
$article = $event->getArticle(); |
|
59
|
|
|
|
|
60
|
|
|
if (null === $article->getTenantCode()) { |
|
61
|
|
|
$tenantContext = $this->container->get('swp_multi_tenancy.tenant_context'); |
|
62
|
|
|
$article->setTenantCode($tenantContext->getTenant()->getCode()); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.