Skip to content

Commit 73e11a5

Browse files
author
vpaladiychuk
committed
MAGETWO-34995: Refactor controllers from the list (Part2)
1 parent 8c352a7 commit 73e11a5

File tree

2 files changed

+26
-25
lines changed
  • app/code/Magento

2 files changed

+26
-25
lines changed

app/code/Magento/Tax/Controller/Adminhtml/Rule/Delete.php

100644100755
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,19 @@ public function execute()
2424
$this->messageManager->addError(__('This rule no longer exists.'));
2525
$this->_redirect('tax/*/');
2626
return;
27-
} catch (\Magento\Framework\Exception\LocalizedException $e) {
28-
$this->messageManager->addError($e->getMessage());
29-
} catch (\Exception $e) {
30-
$this->messageManager->addError(__('Something went wrong deleting this tax rule.'));
3127
}
3228

33-
$this->getResponse()->setRedirect($this->_redirect->getRedirectUrl($this->getUrl('*')));
29+
return $this->getDefaultRedirect();
30+
}
31+
32+
/**
33+
* @inheritdoc
34+
*
35+
* @return \Magento\Framework\Controller\Result\Redirect
36+
*/
37+
public function getDefaultRedirect()
38+
{
39+
$resultRedirect = $this->resultRedirectFactory->create();
40+
return $resultRedirect->setUrl($this->_redirect->getRedirectUrl($this->getUrl('*')));
3441
}
3542
}

app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Delete.php

100644100755
Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,23 @@ class Delete extends \Magento\Theme\Controller\Adminhtml\System\Design\Theme
1515
*/
1616
public function execute()
1717
{
18-
$redirectBack = (bool)$this->getRequest()->getParam('back', false);
1918
$themeId = $this->getRequest()->getParam('id');
20-
try {
21-
if ($themeId) {
22-
/** @var $theme \Magento\Framework\View\Design\ThemeInterface */
23-
$theme = $this->_objectManager->create('Magento\Framework\View\Design\ThemeInterface')->load($themeId);
24-
if (!$theme->getId()) {
25-
throw new \InvalidArgumentException(sprintf('We cannot find a theme with id "%1".', $themeId));
26-
}
27-
if (!$theme->isVirtual()) {
28-
throw new \InvalidArgumentException(
29-
sprintf('Only virtual theme is possible to delete and theme "%s" isn\'t virtual', $themeId)
30-
);
31-
}
32-
$theme->delete();
33-
$this->messageManager->addSuccess(__('You deleted the theme.'));
19+
if ($themeId) {
20+
/** @var $theme \Magento\Framework\View\Design\ThemeInterface */
21+
$theme = $this->_objectManager->create('Magento\Framework\View\Design\ThemeInterface')->load($themeId);
22+
if (!$theme->getId()) {
23+
throw new \InvalidArgumentException(sprintf('We cannot find a theme with id "%1".', $themeId));
24+
}
25+
if (!$theme->isVirtual()) {
26+
throw new \InvalidArgumentException(
27+
sprintf('Only virtual theme is possible to delete and theme "%s" isn\'t virtual', $themeId)
28+
);
3429
}
35-
} catch (\Magento\Framework\Exception\LocalizedException $e) {
36-
$this->messageManager->addError($e->getMessage());
37-
} catch (\Exception $e) {
38-
$this->messageManager->addException($e, __('We cannot delete the theme.'));
39-
$this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e);
30+
$theme->delete();
31+
$this->messageManager->addSuccess(__('You deleted the theme.'));
4032
}
33+
34+
$redirectBack = (bool)$this->getRequest()->getParam('back', false);
4135
/**
4236
* @todo Temporary solution. Theme module should not know about the existence of editor module.
4337
*/

0 commit comments

Comments
 (0)