Delete.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Theme\Controller\Adminhtml\System\Design\Theme;
  8. use Magento\Framework\Controller\ResultFactory;
  9. /**
  10. * Class Delete
  11. * @deprecated 100.2.0
  12. */
  13. class Delete extends \Magento\Theme\Controller\Adminhtml\System\Design\Theme
  14. {
  15. /**
  16. * Delete action
  17. *
  18. * @return \Magento\Backend\Model\View\Result\Redirect
  19. */
  20. public function execute()
  21. {
  22. $themeId = $this->getRequest()->getParam('id');
  23. try {
  24. if ($themeId) {
  25. /** @var $theme \Magento\Framework\View\Design\ThemeInterface */
  26. $theme = $this->_objectManager->create(
  27. \Magento\Framework\View\Design\ThemeInterface::class
  28. )->load($themeId);
  29. if (!$theme->getId()) {
  30. throw new \InvalidArgumentException(sprintf('We cannot find a theme with id "%1".', $themeId));
  31. }
  32. if (!$theme->isVirtual()) {
  33. throw new \InvalidArgumentException(
  34. sprintf('Only virtual theme is possible to delete and theme "%s" isn\'t virtual', $themeId)
  35. );
  36. }
  37. $theme->delete();
  38. $this->messageManager->addSuccess(__('You deleted the theme.'));
  39. }
  40. } catch (\Magento\Framework\Exception\LocalizedException $e) {
  41. $this->messageManager->addError($e->getMessage());
  42. } catch (\Exception $e) {
  43. $this->messageManager->addException($e, __('We cannot delete the theme.'));
  44. $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
  45. }
  46. $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
  47. return $resultRedirect->setPath('adminhtml/*/');
  48. }
  49. }