CreateSiteCommand.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. * @return int
  53. * @throws \Exception
  54. */
  55. protected function execute(InputInterface $input, OutputInterface $output)
  56. {
  57. $org_id = $input->getArgument('organization-id');
  58. $io = new SymfonyStyle($input, $output);
  59. $siteController = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class);
  60. $rootUid = $siteController->createSiteAction($org_id);
  61. $io->success(sprintf("A new website has been created with root page uid=" . $rootUid));
  62. return 0;
  63. }
  64. }