CreateSiteCommand.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. public function __construct(
  21. private readonly SiteController $siteController
  22. ) {
  23. parent::__construct();
  24. }
  25. /**
  26. * -- This method is expected by Typo3, do not rename ou remove --
  27. *
  28. * Allows to configure the command.
  29. * Allows to add a description, a help text, and / or define arguments.
  30. *
  31. */
  32. protected function configure(): void
  33. {
  34. $this
  35. ->setName("ot:site:create")
  36. ->setDescription("Create an organization's website " .
  37. "by fetching its latest data from the Opentalent API")
  38. ->setHelp("Call this method by giving it the organization's id in the Opentalent DB.
  39. If no site exists, it will create it;
  40. If a site already exists, it won't do anything.")
  41. ->addArgument(
  42. 'organization-id',
  43. InputArgument::REQUIRED,
  44. "The organization's id in the opentalent DB"
  45. )->addOption(
  46. 'dev',
  47. null,
  48. InputOption::VALUE_NONE,
  49. "Add this option to get url like 'http://host/subdomain' instead of 'http://subdomain.host'"
  50. );
  51. }
  52. /**
  53. * -- This method is expected by Typo3, do not rename ou remove --
  54. *
  55. * @param InputInterface $input
  56. * @param OutputInterface $output
  57. * @return int
  58. * @throws \Exception
  59. */
  60. protected function execute(InputInterface $input, OutputInterface $output): int
  61. {
  62. $org_id = $input->getArgument('organization-id');
  63. $io = new SymfonyStyle($input, $output);
  64. $rootUid = $this->siteController->createSiteAction($org_id);
  65. $io->success(sprintf("A new website has been created with root page uid=" . $rootUid));
  66. return 0;
  67. }
  68. }