SetSiteDomainCommand.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. /**
  20. * -- This method is expected by Typo3, do not rename ou remove --
  21. *
  22. * Allows to configure the command.
  23. * Allows to add a description, a help text, and / or define arguments.
  24. *
  25. */
  26. protected function configure()
  27. {
  28. $this
  29. ->setName("ot:site:setdomain")
  30. ->setDescription("Set a new domain for the organization website")
  31. ->setHelp("Set a new domain for the organization website. If the --redirect argument is passed, " .
  32. "a redirection will be added from the existing domain to the new one.")
  33. ->addArgument(
  34. 'organization_id',
  35. InputArgument::REQUIRED,
  36. "The organization's id in the opentalent DB"
  37. )
  38. ->addArgument(
  39. 'domain',
  40. InputArgument::REQUIRED,
  41. "The new domain to set up"
  42. )
  43. ->addOption(
  44. 'redirect',
  45. 'r',
  46. InputOption::VALUE_NONE,
  47. 'Use this option to add a redirection from the previous domain to the new one'
  48. );
  49. }
  50. /**
  51. * -- This method is expected by Typo3, do not rename ou remove --
  52. *
  53. * Executes the command for creating the new organization
  54. *
  55. * @param InputInterface $input
  56. * @param OutputInterface $output
  57. * @throws \Exception
  58. */
  59. protected function execute(InputInterface $input, OutputInterface $output)
  60. {
  61. $org_id = $input->getArgument('organization_id');
  62. $domain = $input->getArgument('domain');
  63. $redirect = $input->getOption('redirect');
  64. $io = new SymfonyStyle($input, $output);
  65. $siteController = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class);
  66. $rootUid = $siteController->setSiteDomainAction($org_id, $domain, $redirect);
  67. $io->success(sprintf("The website with root uid " . $rootUid . " domain has been set to " . $domain));
  68. }
  69. }