filter = $filter; $this->collectionFactory = $collectionFactory; parent::__construct($context); } /** * @inheritdoc * @return ResponseInterface|ResultInterface * @throws LocalizedException */ public function execute() { $commentUpdated = 0; $status = (int)$this->getRequest()->getParam('status'); $collection = $this->filter->getCollection($this->collectionFactory->create()); foreach ($collection as $comment) { try { $comment->setStatus($status)->save(); $this->_eventManager->dispatch('blog_post_comment', ['comment_data' => $comment]); $commentUpdated++; } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); } catch (Exception $e) { $this->_getSession()->addException($e, __('Something went wrong while updating status')); } } if ($commentUpdated) { $this->messageManager->addSuccessMessage(__('A total of %1 record(s) have been updated.', $commentUpdated)); } $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); return $resultRedirect->setPath('*/*/'); } }