GetSiteInfosCommand.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. use TYPO3\CMS\Core\Utility\GeneralUtility;
  10. use TYPO3\CMS\Extbase\Object\ObjectManager;
  11. /**
  12. * Display the main informations about the organization's website
  13. *
  14. * @package Opentalent\OtAdmin\Command
  15. */
  16. class GetSiteInfosCommand 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:infos")
  29. ->setDescription("Display the main informations about the organization's website")
  30. ->addArgument(
  31. 'organization_id',
  32. InputArgument::REQUIRED,
  33. "The organization's id in the opentalent DB"
  34. );
  35. }
  36. /**
  37. * -- This method is expected by Typo3, do not rename ou remove --
  38. *
  39. * @param InputInterface $input
  40. * @param OutputInterface $output
  41. * @throws \Exception
  42. */
  43. protected function execute(InputInterface $input, OutputInterface $output)
  44. {
  45. $org_id = $input->getArgument('organization_id');
  46. $io = new SymfonyStyle($input, $output);
  47. $siteController = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class);
  48. $infos = $siteController->getSiteInfosAction($org_id);
  49. $io->title(sprintf("Informations about the organization " . $org_id . ' typo3 website'));
  50. $headers = [];
  51. $values = [];
  52. foreach ($infos as $key => $value) {
  53. $headers[] = $key;
  54. $values[] = json_encode(
  55. str_replace("\"", "'", $value),
  56. JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
  57. );
  58. }
  59. $io->horizontalTable($headers, [$values]);
  60. $io->success(sprintf('Informations retrieved'));
  61. }
  62. }