GetSiteStatusCommand.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 returns the status and some useful informations
  14. * about the given website
  15. *
  16. * @package Opentalent\OtAdmin\Command
  17. */
  18. class GetSiteStatusCommand 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:status")
  36. ->setDescription("Displays the current state of a given website")
  37. ->setHelp("This CLI command returns a status code representing the current state of a given website")
  38. ->addOption(
  39. 'full',
  40. null,
  41. InputOption::VALUE_NONE,
  42. "Performs a full scan (with warnings)"
  43. )
  44. ->addArgument(
  45. 'organization-id',
  46. InputArgument::REQUIRED,
  47. "The organization's id in the opentalent DB"
  48. );
  49. }
  50. /**
  51. * -- This method is expected by Typo3, do not rename ou remove --
  52. *
  53. * @param InputInterface $input
  54. * @param OutputInterface $output
  55. * @return int
  56. * @throws \Opentalent\OtCore\Exception\NoSuchWebsiteException
  57. * @throws \TYPO3\CMS\Extbase\Object\Exception
  58. */
  59. protected function execute(InputInterface $input, OutputInterface $output): int
  60. {
  61. $org_id = $input->getArgument('organization-id');
  62. $full = $input->getOption('full');
  63. $io = new SymfonyStyle($input, $output);
  64. $status = $this->siteController->getSiteStatusAction($org_id, $full);
  65. $headers = [];
  66. $values = [];
  67. foreach ($status->toArray() as $key => $value) {
  68. $headers[] = $key;
  69. $value = json_encode(
  70. str_replace("\"", "'", $value),
  71. JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
  72. );
  73. $value = trim($value, "\"");
  74. $values[] = $value;
  75. }
  76. $io->horizontalTable($headers, [$values]);
  77. $io->success('');
  78. return 0;
  79. }
  80. }