DownloadCustomCss.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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\App\ResponseInterface;
  9. use Magento\Framework\App\Filesystem\DirectoryList;
  10. /**
  11. * Class DownloadCustomCss
  12. * @deprecated 100.2.0
  13. */
  14. class DownloadCustomCss extends \Magento\Theme\Controller\Adminhtml\System\Design\Theme
  15. {
  16. /**
  17. * Download custom css file
  18. *
  19. * @return ResponseInterface|void
  20. */
  21. public function execute()
  22. {
  23. $themeId = $this->getRequest()->getParam('theme_id');
  24. try {
  25. /** @var $themeFactory \Magento\Framework\View\Design\Theme\FlyweightFactory */
  26. $themeFactory = $this->_objectManager->create(\Magento\Framework\View\Design\Theme\FlyweightFactory::class);
  27. $theme = $themeFactory->create($themeId);
  28. if (!$theme) {
  29. throw new \InvalidArgumentException(sprintf('We cannot find a theme with id "%1".', $themeId));
  30. }
  31. $customCssFiles = $theme->getCustomization()->getFilesByType(
  32. \Magento\Theme\Model\Theme\Customization\File\CustomCss::TYPE
  33. );
  34. /** @var $customCssFile \Magento\Framework\View\Design\Theme\FileInterface */
  35. $customCssFile = reset($customCssFiles);
  36. if ($customCssFile && $customCssFile->getContent()) {
  37. return $this->_fileFactory->create(
  38. $customCssFile->getFileName(),
  39. ['type' => 'filename', 'value' => $customCssFile->getFullPath()],
  40. DirectoryList::ROOT
  41. );
  42. }
  43. } catch (\Exception $e) {
  44. $this->messageManager->addException($e, __('We can\'t find file.'));
  45. $this->getResponse()->setRedirect($this->_redirect->getRefererUrl());
  46. $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
  47. }
  48. }
  49. }