ThemeUninstaller.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Theme\Model\Theme;
  7. use Magento\Framework\Composer\Remove;
  8. use Symfony\Component\Console\Output\OutputInterface;
  9. class ThemeUninstaller
  10. {
  11. /**
  12. * @var ThemePackageInfo
  13. */
  14. private $themePackageInfo;
  15. /**
  16. * @var Remove
  17. */
  18. private $remove;
  19. /**
  20. * @var ThemeProvider
  21. */
  22. private $themeProvider;
  23. /**
  24. * Constructor
  25. *
  26. * @param ThemePackageInfo $themePackageInfo
  27. * @param Remove $remove
  28. * @param ThemeProvider $themeProvider
  29. */
  30. public function __construct(ThemePackageInfo $themePackageInfo, Remove $remove, ThemeProvider $themeProvider)
  31. {
  32. $this->themePackageInfo = $themePackageInfo;
  33. $this->remove = $remove;
  34. $this->themeProvider = $themeProvider;
  35. }
  36. /**
  37. * Uninstall theme from database registry
  38. *
  39. * @param OutputInterface $output
  40. * @param array $themePaths
  41. * @return void
  42. */
  43. public function uninstallRegistry(OutputInterface $output, array $themePaths)
  44. {
  45. $output->writeln('<info>Removing ' . implode(', ', $themePaths) . ' from database');
  46. foreach ($themePaths as $themePath) {
  47. $this->themeProvider->getThemeByFullPath($themePath)->delete();
  48. }
  49. }
  50. /**
  51. * Uninstall theme from code base
  52. *
  53. * @param OutputInterface $output
  54. * @param array $themePaths
  55. * @return void
  56. */
  57. public function uninstallCode(OutputInterface $output, array $themePaths)
  58. {
  59. $output->writeln('<info>Removing ' . implode(', ', $themePaths) . ' from Magento codebase');
  60. $packageNames = [];
  61. foreach ($themePaths as $themePath) {
  62. $packageNames[] = $this->themePackageInfo->getPackageName($themePath);
  63. }
  64. $output->writeln($this->remove->remove($packageNames));
  65. }
  66. }