SetSiteDomainCommand.php 2.7 KB

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