CreateSiteCommand.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. /**
  11. * This CLI command creates an organization's website
  12. * by fetching its latest data from the Opentalent API
  13. *
  14. * @package Opentalent\OtAdmin\Command
  15. */
  16. class CreateSiteCommand extends Command
  17. {
  18. /**
  19. * -- This method is expected by Typo3, do not rename ou remove --
  20. *
  21. * Allows to configure the command.
  22. * Allows to add a description, a help text, and / or define arguments.
  23. *
  24. */
  25. protected function configure()
  26. {
  27. $this
  28. ->setName("ot:site:create")
  29. ->setDescription("Create an organization's website " .
  30. "by fetching its latest data from the Opentalent API")
  31. ->setHelp("Call this method by giving it the organization's id in the Opentalent DB.
  32. If no site exists, create it;
  33. If a site already exists, do nothing.")
  34. ->addArgument(
  35. 'organization_id',
  36. InputArgument::REQUIRED,
  37. "The organization's id in the opentalent DB"
  38. )->addOption(
  39. 'dev',
  40. null,
  41. InputOption::VALUE_NONE,
  42. "Add this option to get url like 'http://host/subdomain' instead of 'http://subdomain/host'"
  43. );
  44. }
  45. /**
  46. * -- This method is expected by Typo3, do not rename ou remove --
  47. *
  48. * Executes the command for creating the new organization
  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 = new SiteController();
  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. }