CreateSiteCommand.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 creates an organization's website
  14. * by fetching its latest data from the Opentalent API
  15. *
  16. * @package Opentalent\OtAdmin\Command
  17. */
  18. class CreateSiteCommand 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:create")
  31. ->setDescription("Create an organization's website " .
  32. "by fetching its latest data from the Opentalent API")
  33. ->setHelp("Call this method by giving it the organization's id in the Opentalent DB.
  34. If no site exists, create it;
  35. If a site already exists, do nothing.")
  36. ->addArgument(
  37. 'organization_id',
  38. InputArgument::REQUIRED,
  39. "The organization's id in the opentalent DB"
  40. )->addOption(
  41. 'dev',
  42. null,
  43. InputOption::VALUE_NONE,
  44. "Add this option to get url like 'http://host/subdomain' instead of 'http://subdomain/host'"
  45. );
  46. }
  47. /**
  48. * -- This method is expected by Typo3, do not rename ou remove --
  49. *
  50. * Executes the command for creating the new organization
  51. *
  52. * @param InputInterface $input
  53. * @param OutputInterface $output
  54. * @throws \Exception
  55. */
  56. protected function execute(InputInterface $input, OutputInterface $output)
  57. {
  58. $org_id = $input->getArgument('organization_id');
  59. $isDev = $input->getOption('dev');
  60. $io = new SymfonyStyle($input, $output);
  61. $siteController = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class);
  62. $rootUid = $siteController->createSiteAction(
  63. $org_id,
  64. $isDev ? $siteController::MODE_DEV : $siteController::MODE_PROD
  65. );
  66. $io->success(sprintf("A new website has been created with root page uid=" . $rootUid));
  67. }
  68. }