ClearSiteCacheCommand.php 2.4 KB

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