ClearSiteCacheCommand.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace Opentalent\OtAdmin\Command;
  3. use Opentalent\OtAdmin\Controller\SiteController;
  4. use Symfony\Component\Console\Command\Command;
  5. use Symfony\Component\Console\Input\InputArgument;
  6. use Symfony\Component\Console\Input\InputInterface;
  7. use Symfony\Component\Console\Input\InputOption;
  8. use Symfony\Component\Console\Output\OutputInterface;
  9. use Symfony\Component\Console\Style\SymfonyStyle;
  10. use TYPO3\CMS\Core\Utility\GeneralUtility;
  11. use TYPO3\CMS\Extbase\Object\ObjectManager;
  12. /**
  13. * This CLI command clears the cache of an existing organization's website
  14. *
  15. * By default, this command will only clear the frontend cache.
  16. * Pass the '-a / --all' option to clear all of the typo3 caches.
  17. *
  18. * @package Opentalent\OtAdmin\Command
  19. */
  20. class ClearSiteCacheCommand extends Command
  21. {
  22. /**
  23. * -- This method is expected by Typo3, do not rename ou remove --
  24. *
  25. * Allows to configure the command.
  26. * Allows to add a description, a help text, and / or define arguments.
  27. *
  28. */
  29. protected function configure()
  30. {
  31. $this
  32. ->setName("ot:site:clear-cache")
  33. ->setDescription("Clear the cache of an organization website")
  34. ->setHelp("This CLI command clears the cache of an existing organization's website")
  35. ->addArgument(
  36. 'organization-id',
  37. InputArgument::REQUIRED,
  38. "The organization's id in the opentalent DB"
  39. )->addOption(
  40. 'all',
  41. 'a',
  42. InputOption::VALUE_NONE,
  43. 'Use this option to clear all the typo3 caches, and not only the frontend one'
  44. );
  45. }
  46. /**
  47. * -- This method is expected by Typo3, do not rename ou remove --
  48. *
  49. * @param InputInterface $input
  50. * @param OutputInterface $output
  51. * @throws \Exception
  52. */
  53. protected function execute(InputInterface $input, OutputInterface $output)
  54. {
  55. $org_id = $input->getArgument('organization-id');
  56. $clearAll = $input->getOption('all');
  57. $io = new SymfonyStyle($input, $output);
  58. $siteController = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class);
  59. $rootUid = $siteController->clearSiteCacheAction($org_id, $clearAll);
  60. $io->success(sprintf("The cache has been cleared for the website with root uid " . $rootUid . ""));
  61. return 0;
  62. }
  63. }