|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Administration\Notification\Subscriber; |
|
4
|
|
|
|
|
5
|
|
|
use Shopware\Administration\Notification\NotificationService; |
|
6
|
|
|
use Shopware\Core\Framework\Api\Context\AdminApiSource; |
|
7
|
|
|
use Shopware\Core\Framework\Log\Package; |
|
8
|
|
|
use Shopware\Core\Framework\Update\Event\UpdatePostFinishEvent; |
|
9
|
|
|
use Shopware\Core\Framework\Uuid\Uuid; |
|
10
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @internal |
|
14
|
|
|
*/ |
|
15
|
|
|
#[Package('system-settings')] |
|
16
|
|
|
class UpdateSubscriber implements EventSubscriberInterface |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @internal |
|
20
|
|
|
*/ |
|
21
|
|
|
public function __construct( |
|
22
|
|
|
private readonly NotificationService $notificationService |
|
23
|
|
|
) { |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>> |
|
|
|
|
|
|
28
|
|
|
*/ |
|
29
|
|
|
public static function getSubscribedEvents(): array |
|
30
|
|
|
{ |
|
31
|
|
|
return [ |
|
32
|
|
|
UpdatePostFinishEvent::class => [ |
|
33
|
|
|
['updateFinishedDone', -9999], |
|
34
|
|
|
], |
|
35
|
|
|
]; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @internal |
|
40
|
|
|
*/ |
|
41
|
|
|
public function updateFinishedDone(UpdatePostFinishEvent $event): void |
|
42
|
|
|
{ |
|
43
|
|
|
$status = 'success'; |
|
44
|
|
|
$message = 'Updated successfully to version ' . $event->getNewVersion(); |
|
45
|
|
|
if ($event->getPostUpdateMessage() !== '') { |
|
46
|
|
|
$status = 'warning'; |
|
47
|
|
|
$message .= \PHP_EOL . $event->getPostUpdateMessage(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$source = $event->getContext()->getSource(); |
|
51
|
|
|
$integrationId = null; |
|
52
|
|
|
$createdByUserId = null; |
|
53
|
|
|
if ($source instanceof AdminApiSource) { |
|
54
|
|
|
$integrationId = $source->getIntegrationId(); |
|
55
|
|
|
$createdByUserId = $source->getUserId(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$this->notificationService->createNotification( |
|
59
|
|
|
[ |
|
60
|
|
|
'id' => Uuid::randomHex(), |
|
61
|
|
|
'status' => $status, |
|
62
|
|
|
'message' => $message, |
|
63
|
|
|
'adminOnly' => true, |
|
64
|
|
|
'requiredPrivileges' => [], |
|
65
|
|
|
'createdByIntegrationId' => $integrationId, |
|
66
|
|
|
'createdByUserId' => $createdByUserId, |
|
67
|
|
|
], |
|
68
|
|
|
$event->getContext() |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|