ClearSiteCacheCommand.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. /**
  11. * This CLI command clears the cache of an existing organization's website
  12. *
  13. * By default, this command will only clear the frontend cache.
  14. * Pass the '-a / --all' option to clear all of the typo3 caches.
  15. *
  16. * @package Opentalent\OtAdmin\Command
  17. */
  18. class ClearSiteCacheCommand extends Command
  19. {
  20. /**
  21. * -- This method is expected by Typo3, do not rename ou remove --
  22. *
  23. * Allows to configure the command.
  24. * Allows to add a description, a help text, and / or define arguments.
  25. *
  26. */
  27. protected function configure()
  28. {
  29. $this
  30. ->setName("ot:site:clear-cache")
  31. ->setDescription("Clear the cache of an organization website")
  32. ->setHelp("This CLI command clears the cache of an existing organization's website")
  33. ->addArgument(
  34. 'organization_id',
  35. InputArgument::REQUIRED,
  36. "The organization's id in the opentalent DB"
  37. )->addOption(
  38. 'all',
  39. 'a',
  40. InputOption::VALUE_NONE,
  41. 'Use this option to clear all the typo3 caches, and not only the frontend one'
  42. );
  43. }
  44. /**
  45. * -- This method is expected by Typo3, do not rename ou remove --
  46. *
  47. * Executes the command for clearing the cache of the organization's website
  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 = new SiteController();
  59. $rootUid = $siteController->clearSiteCacheAction($org_id, $clearAll);
  60. $io->success(sprintf("The cache has been cleared for the website with root uid " . $rootUid . ""));
  61. }
  62. }