MarkAsRead.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\AdminNotification\Controller\Adminhtml\Notification;
  8. class MarkAsRead extends \Magento\AdminNotification\Controller\Adminhtml\Notification
  9. {
  10. /**
  11. * Authorization level of a basic admin session
  12. *
  13. * @see _isAllowed()
  14. */
  15. const ADMIN_RESOURCE = 'Magento_AdminNotification::mark_as_read';
  16. /**
  17. * @return void
  18. */
  19. public function execute()
  20. {
  21. $notificationId = (int)$this->getRequest()->getParam('id');
  22. if ($notificationId) {
  23. try {
  24. $this->_objectManager->create(
  25. \Magento\AdminNotification\Model\NotificationService::class
  26. )->markAsRead(
  27. $notificationId
  28. );
  29. $this->messageManager->addSuccessMessage(__('The message has been marked as Read.'));
  30. } catch (\Magento\Framework\Exception\LocalizedException $e) {
  31. $this->messageManager->addErrorMessage($e->getMessage());
  32. } catch (\Exception $e) {
  33. $this->messageManager->addExceptionMessage(
  34. $e,
  35. __("We couldn't mark the notification as Read because of an error.")
  36. );
  37. }
  38. $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl($this->getUrl('*')));
  39. return;
  40. }
  41. $this->_redirect('adminhtml/*/');
  42. }
  43. }