Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DeleteWebsitePost.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
11 
15 class DeleteWebsitePost extends \Magento\Backend\Controller\Adminhtml\System\Store implements HttpPostActionInterface
16 {
21  public function execute()
22  {
23  $itemId = $this->getRequest()->getParam('item_id');
24  $model = $this->_objectManager->create(\Magento\Store\Model\Website::class);
25  $model->load($itemId);
26 
28  $redirectResult = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
29 
30  if (!$model) {
31  $this->messageManager->addErrorMessage(__('Something went wrong. Please try again.'));
32  return $redirectResult->setPath('adminhtml/*/');
33  }
34  if (!$model->isCanDelete()) {
35  $this->messageManager->addErrorMessage(__('This website cannot be deleted.'));
36  return $redirectResult->setPath('adminhtml/*/editWebsite', ['website_id' => $model->getId()]);
37  }
38 
39  if (!$this->_backupDatabase()) {
40  return $redirectResult->setPath('*/*/editWebsite', ['website_id' => $itemId]);
41  }
42 
43  try {
44  $model->delete();
45  $this->messageManager->addSuccessMessage(__('You deleted the website.'));
46  return $redirectResult->setPath('adminhtml/*/');
47  } catch (\Magento\Framework\Exception\LocalizedException $e) {
48  $this->messageManager->addErrorMessage($e->getMessage());
49  } catch (\Exception $e) {
50  $this->messageManager->addExceptionMessage($e, __('Unable to delete the website. Please try again later.'));
51  }
52  return $redirectResult->setPath('*/*/editWebsite', ['website_id' => $itemId]);
53  }
54 }
__()
Definition: __.php:13