CreateOrganizationCommand.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\Output\OutputInterface;
  8. use Symfony\Component\Console\Style\SymfonyStyle;
  9. /**
  10. * This CLI command creates an organization's website
  11. * by fetching its latest data from the Opentalent API
  12. *
  13. * @package Opentalent\OtAdmin\Command
  14. */
  15. class CreateOrganizationCommand extends Command
  16. {
  17. /**
  18. * -- This method is expected by Typo3, do not rename ou remove --
  19. *
  20. * Allows to configure the command.
  21. * Allows to add a description, a help text, and / or define arguments.
  22. *
  23. */
  24. protected function configure()
  25. {
  26. $this
  27. ->setName("ot:site:create")
  28. ->setDescription("Create an organization's website " .
  29. "by fetching its latest data from the Opentalent API")
  30. ->setHelp("Call this method by giving it the organization's id in the Opentalent DB.
  31. If no site exists, create it;
  32. If a site already exists, do nothing.")
  33. ->addArgument(
  34. 'organization_id',
  35. InputArgument::REQUIRED,
  36. "The organization's id in the opentalent DB"
  37. );
  38. }
  39. /**
  40. * -- This method is expected by Typo3, do not rename ou remove --
  41. *
  42. * Executes the command for creating the new organization
  43. *
  44. * @param InputInterface $input
  45. * @param OutputInterface $output
  46. */
  47. protected function execute(InputInterface $input, OutputInterface $output)
  48. {
  49. // Make sure the _cli_ user is loaded
  50. // TYPO3\CMS\Core\Core\Bootstrap::initializeBackendAuthentication();
  51. $org_id = $input->getArgument('organization_id');
  52. $io = new SymfonyStyle($input, $output);
  53. $siteController = new SiteController();
  54. $rootUid = $siteController->createSiteAction($org_id);
  55. $io->success(sprintf("A new website has been created with root page uid=" . $rootUid));
  56. }
  57. }