ClearSiteCacheCommand.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 the typo3 caches.
  17. *
  18. * @package Opentalent\OtAdmin\Command
  19. */
  20. class ClearSiteCacheCommand extends Command
  21. {
  22. public function __construct(
  23. private readonly SiteController $siteController
  24. ) {}
  25. /**
  26. * -- This method is expected by Typo3, do not rename ou remove --
  27. *
  28. * Allows to configure the command.
  29. * Allows to add a description, a help text, and / or define arguments.
  30. *
  31. */
  32. protected function configure(): void
  33. {
  34. $this
  35. ->setName("ot:site:clear-cache")
  36. ->setDescription("Clear the cache of an organization website")
  37. ->setHelp("This CLI command clears the cache of an existing organization's website")
  38. ->addArgument(
  39. 'organization-id',
  40. InputArgument::REQUIRED,
  41. "The organization's id in the opentalent DB"
  42. )->addOption(
  43. 'all',
  44. 'a',
  45. InputOption::VALUE_NONE,
  46. 'Use this option to clear all the typo3 caches, and not only the frontend one'
  47. );
  48. }
  49. /**
  50. * -- This method is expected by Typo3, do not rename ou remove --
  51. *
  52. * @param InputInterface $input
  53. * @param OutputInterface $output
  54. * @throws \Exception
  55. */
  56. protected function execute(InputInterface $input, OutputInterface $output): int
  57. {
  58. $org_id = $input->getArgument('organization-id');
  59. $clearAll = $input->getOption('all');
  60. $io = new SymfonyStyle($input, $output);
  61. $rootUid = $this->siteController->clearSiteCacheAction($org_id, $clearAll);
  62. $io->success(sprintf("The cache has been cleared for the website with root uid " . $rootUid . ""));
  63. return 0;
  64. }
  65. }