JustMakeItWorkSiteCommand.php 2.7 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. /**
  11. * This CLI command updates the organization's website if it exists, restores
  12. * it if it has been deleted, or creates it if it does not exist.
  13. * It also removes any redirections that may have been set on the domain.
  14. *
  15. * @package Opentalent\OtAdmin\Command
  16. */
  17. class JustMakeItWorkSiteCommand extends Command
  18. {
  19. public function __construct(
  20. private readonly SiteController $siteController
  21. ) {
  22. parent::__construct();
  23. }
  24. /**
  25. * -- This method is expected by Typo3, do not rename ou remove --
  26. *
  27. * Allows to configure the command.
  28. * Allows to add a description, a help text, and / or define arguments.
  29. *
  30. */
  31. protected function configure(): void
  32. {
  33. $this
  34. ->setName("ot:site:just-make-it-work")
  35. ->setDescription("Forces the website to be updated / restored / created, according to its state")
  36. ->setHelp("Call this method by giving it the organization's id in the Opentalent DB.
  37. If no site exists, it will create it;
  38. If the site has been deleted, it will restore it;
  39. If a site already exists, it will update it.
  40. This command will also remove any redirections that may have been set on the domain.")
  41. ->addArgument(
  42. 'organization-id',
  43. InputArgument::REQUIRED,
  44. "The organization's id in the opentalent DB"
  45. )->addOption(
  46. 'dev',
  47. null,
  48. InputOption::VALUE_NONE,
  49. "Add this option to get url like 'http://host/subdomain' instead of 'http://subdomain.host'"
  50. );
  51. }
  52. /**
  53. * -- This method is expected by Typo3, do not rename ou remove --
  54. *
  55. * @param InputInterface $input
  56. * @param OutputInterface $output
  57. * @return int
  58. * @throws \Exception
  59. */
  60. protected function execute(InputInterface $input, OutputInterface $output): int
  61. {
  62. $org_id = $input->getArgument('organization-id');
  63. $io = new SymfonyStyle($input, $output);
  64. $rootUid = $this->siteController->justeMakeItWorkSiteAction($org_id);
  65. $io->success(sprintf("The website has been updated / restored / created (root page uid=" . $rootUid . ')'));
  66. return 0;
  67. }
  68. }