AbstractCacheSetCommand.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Console\Command;
  7. use Symfony\Component\Console\Input\InputInterface;
  8. use Symfony\Component\Console\Output\OutputInterface;
  9. /**
  10. * @api
  11. * @since 100.0.2
  12. */
  13. abstract class AbstractCacheSetCommand extends AbstractCacheManageCommand
  14. {
  15. /**
  16. * Is enable cache or not
  17. *
  18. * @return bool
  19. */
  20. abstract protected function isEnable();
  21. /**
  22. * {@inheritdoc}
  23. */
  24. protected function execute(InputInterface $input, OutputInterface $output)
  25. {
  26. $isEnable = $this->isEnable();
  27. $types = $this->getRequestedTypes($input);
  28. $changedTypes = $this->cacheManager->setEnabled($types, $isEnable);
  29. if ($changedTypes) {
  30. $output->writeln('Changed cache status:');
  31. foreach ($changedTypes as $type) {
  32. $output->writeln(sprintf('%30s: %d -> %d', $type, !$isEnable, $isEnable));
  33. }
  34. } else {
  35. $output->writeln('There is nothing to change in cache status');
  36. }
  37. if (!empty($changedTypes) && $isEnable) {
  38. $this->cacheManager->clean($changedTypes);
  39. $output->writeln('Cleaned cache types:');
  40. $output->writeln(join(PHP_EOL, $changedTypes));
  41. }
  42. }
  43. }