CreateSiteCommand.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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, it will create it;
  35. If a site already exists, it won't do anything.")
  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. * @param InputInterface $input
  51. * @param OutputInterface $output
  52. * @throws \Exception
  53. */
  54. protected function execute(InputInterface $input, OutputInterface $output)
  55. {
  56. $org_id = $input->getArgument('organization-id');
  57. $isDev = $input->getOption('dev');
  58. $io = new SymfonyStyle($input, $output);
  59. $siteController = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class);
  60. $rootUid = $siteController->createSiteAction(
  61. $org_id,
  62. $isDev ? $siteController::MODE_DEV : $siteController::MODE_PROD
  63. );
  64. $io->success(sprintf("A new website has been created with root page uid=" . $rootUid));
  65. }
  66. }