Remove.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 Remove 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::adminnotification_remove';
  16. /**
  17. * @return void
  18. */
  19. public function execute()
  20. {
  21. if ($id = $this->getRequest()->getParam('id')) {
  22. $model = $this->_objectManager->create(\Magento\AdminNotification\Model\Inbox::class)->load($id);
  23. if (!$model->getId()) {
  24. $this->_redirect('adminhtml/*/');
  25. return;
  26. }
  27. try {
  28. $model->setIsRemove(1)->save();
  29. $this->messageManager->addSuccessMessage(__('The message has been removed.'));
  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 remove the messages because of an error.")
  36. );
  37. }
  38. $this->_redirect('adminhtml/*/');
  39. return;
  40. }
  41. $this->_redirect('adminhtml/*/');
  42. }
  43. }