MassRemove.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 MassRemove 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. $ids = $this->getRequest()->getParam('notification');
  22. if (!is_array($ids)) {
  23. $this->messageManager->addErrorMessage(__('Please select messages.'));
  24. } else {
  25. try {
  26. foreach ($ids as $id) {
  27. $model = $this->_objectManager->create(\Magento\AdminNotification\Model\Inbox::class)->load($id);
  28. if ($model->getId()) {
  29. $model->setIsRemove(1)->save();
  30. }
  31. }
  32. $this->messageManager->addSuccessMessage(__('Total of %1 record(s) have been removed.', count($ids)));
  33. } catch (\Magento\Framework\Exception\LocalizedException $e) {
  34. $this->messageManager->addErrorMessage($e->getMessage());
  35. } catch (\Exception $e) {
  36. $this->messageManager->addExceptionMessage(
  37. $e,
  38. __("We couldn't remove the messages because of an error.")
  39. );
  40. }
  41. }
  42. $this->_redirect('adminhtml/*/');
  43. }
  44. }