SetSiteDomainCommand.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 sets a new domain for the organization website
  14. *
  15. * @package Opentalent\OtAdmin\Command
  16. */
  17. class SetSiteDomainCommand 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:setdomain")
  35. ->setDescription("Set a new custom domain for the organization website")
  36. ->setHelp("Set a new domain for the organization website. A new redirection will " .
  37. "be added from the existing domain to the new one. Use the --no-redirection option " .
  38. "to prevent this.")
  39. ->addArgument(
  40. 'organization-id',
  41. InputArgument::REQUIRED,
  42. "The organization's id in the opentalent DB"
  43. )
  44. ->addArgument(
  45. 'domain',
  46. InputArgument::REQUIRED,
  47. "The new domain to set up"
  48. )
  49. ->addOption(
  50. 'no-redirection',
  51. 'r',
  52. InputOption::VALUE_NONE,
  53. 'Use this option to prevent the creation of a redirection from the previous domain to the new one'
  54. );
  55. }
  56. /**
  57. * -- This method is expected by Typo3, do not rename ou remove --
  58. *
  59. * Executes the command for creating the new organization
  60. *
  61. * @param InputInterface $input
  62. * @param OutputInterface $output
  63. * @return int
  64. * @throws \Exception
  65. */
  66. protected function execute(InputInterface $input, OutputInterface $output): int
  67. {
  68. $org_id = $input->getArgument('organization-id');
  69. $domain = $input->getArgument('domain');
  70. $redirect = ($input->getOption('no-redirection') == null);
  71. $io = new SymfonyStyle($input, $output);
  72. $rootUid = $this->siteController->setSiteCustomDomainAction($org_id, $domain, $redirect);
  73. $io->success(sprintf("The website with root uid " . $rootUid . " domain has been set to " . $domain));
  74. return 0;
  75. }
  76. }