vendor/shopware/administration/Notification/Subscriber/UpdateSubscriber.php line 41

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