|
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 2020 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 2020 Sourcefabric z.ú |
|
14
|
|
|
* @license http://www.superdesk.org/license |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
namespace SWP\Bundle\CoreBundle\MessageHandler; |
|
18
|
|
|
|
|
19
|
|
|
use SWP\Bundle\CoreBundle\AppleNews\AppleNewsPublisher; |
|
20
|
|
|
use SWP\Bundle\CoreBundle\MessageHandler\Message\UnpublishFromAppleNews; |
|
21
|
|
|
use SWP\Bundle\CoreBundle\Model\ArticleInterface; |
|
22
|
|
|
use SWP\Bundle\CoreBundle\Model\TenantInterface; |
|
23
|
|
|
use SWP\Bundle\CoreBundle\Repository\ArticleRepositoryInterface; |
|
24
|
|
|
use SWP\Component\Common\Exception\ArticleNotFoundException; |
|
25
|
|
|
use SWP\Component\MultiTenancy\Exception\TenantNotFoundException; |
|
26
|
|
|
use SWP\Component\MultiTenancy\Repository\TenantRepositoryInterface; |
|
27
|
|
|
use Symfony\Component\Messenger\Handler\MessageHandlerInterface; |
|
28
|
|
|
|
|
29
|
|
View Code Duplication |
class UnpublishFromAppleNewsHandler implements MessageHandlerInterface |
|
30
|
|
|
{ |
|
31
|
|
|
private $appleNewsPublisher; |
|
32
|
|
|
|
|
33
|
|
|
private $articleRepository; |
|
34
|
|
|
|
|
35
|
|
|
private $tenantRepository; |
|
36
|
|
|
|
|
37
|
|
|
public function __construct( |
|
38
|
|
|
AppleNewsPublisher $appleNewsPublisher, |
|
39
|
|
|
ArticleRepositoryInterface $articleRepository, |
|
40
|
|
|
TenantRepositoryInterface $tenantRepository |
|
41
|
|
|
) { |
|
42
|
|
|
$this->appleNewsPublisher = $appleNewsPublisher; |
|
43
|
|
|
$this->articleRepository = $articleRepository; |
|
44
|
|
|
$this->tenantRepository = $tenantRepository; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function __invoke(UnpublishFromAppleNews $unpublishFromAppleNews) |
|
48
|
|
|
{ |
|
49
|
|
|
$articleId = $unpublishFromAppleNews->getArticleId(); |
|
50
|
|
|
$tenantId = $unpublishFromAppleNews->getTenantId(); |
|
51
|
|
|
|
|
52
|
|
|
/** @var ArticleInterface $article */ |
|
53
|
|
|
$article = $this->articleRepository->findOneBy(['id' => $articleId]); |
|
54
|
|
|
|
|
55
|
|
|
if (null === $article) { |
|
56
|
|
|
throw new ArticleNotFoundException(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** @var TenantInterface $tenant */ |
|
60
|
|
|
$tenant = $this->tenantRepository->findOneBy(['id' => $tenantId]); |
|
61
|
|
|
|
|
62
|
|
|
if (null === $tenant) { |
|
63
|
|
|
throw new TenantNotFoundException($tenant->getName()); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$this->appleNewsPublisher->unpublish($article, $tenant); |
|
67
|
|
|
$article->setAppleNewsArticle(null); |
|
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
$this->articleRepository->flush(); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: