DownloadCss.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 DownloadCss
  12. * @deprecated 100.2.0
  13. */
  14. class DownloadCss extends \Magento\Theme\Controller\Adminhtml\System\Design\Theme
  15. {
  16. /**
  17. * Download css file
  18. *
  19. * @return ResponseInterface|void
  20. */
  21. public function execute()
  22. {
  23. $themeId = $this->getRequest()->getParam('theme_id');
  24. $file = $this->getRequest()->getParam('file');
  25. /** @var $urlDecoder \Magento\Framework\Url\DecoderInterface */
  26. $urlDecoder = $this->_objectManager->get(\Magento\Framework\Url\DecoderInterface::class);
  27. $fileId = $urlDecoder->decode($file);
  28. try {
  29. /** @var $theme \Magento\Framework\View\Design\ThemeInterface */
  30. $theme = $this->_objectManager->create(
  31. \Magento\Framework\View\Design\ThemeInterface::class
  32. )->load($themeId);
  33. if (!$theme->getId()) {
  34. throw new \InvalidArgumentException(sprintf('Theme not found: "%1".', $themeId));
  35. }
  36. $asset = $this->_assetRepo->createAsset($fileId, ['themeModel' => $theme]);
  37. $relPath = $this->_appFileSystem->getDirectoryRead(DirectoryList::ROOT)
  38. ->getRelativePath($asset->getSourceFile());
  39. return $this->_fileFactory->create(
  40. $relPath,
  41. [
  42. 'type' => 'filename',
  43. 'value' => $relPath
  44. ],
  45. DirectoryList::ROOT
  46. );
  47. } catch (\Exception $e) {
  48. $this->messageManager->addException($e, __('File not found: "%1".', $fileId));
  49. $this->getResponse()->setRedirect($this->_redirect->getRefererUrl());
  50. $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
  51. }
  52. }
  53. }