GetSiteStatusCommand.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. /**
  21. * -- This method is expected by Typo3, do not rename ou remove --
  22. *
  23. * Allows to configure the command.
  24. * Allows to add a description, a help text, and / or define arguments.
  25. *
  26. */
  27. protected function configure()
  28. {
  29. $this
  30. ->setName("ot:site:status")
  31. ->setDescription("Displays the current state of a given website")
  32. ->setHelp("This CLI command returns a status code representing the current state of a given website")
  33. ->addOption(
  34. 'full',
  35. null,
  36. InputOption::VALUE_NONE,
  37. "Performs a full scan (with warnings)"
  38. )
  39. ->addArgument(
  40. 'organization-id',
  41. InputArgument::REQUIRED,
  42. "The organization's id in the opentalent DB"
  43. );
  44. }
  45. /**
  46. * -- This method is expected by Typo3, do not rename ou remove --
  47. *
  48. * @param InputInterface $input
  49. * @param OutputInterface $output
  50. * @throws \Exception
  51. */
  52. protected function execute(InputInterface $input, OutputInterface $output)
  53. {
  54. $org_id = $input->getArgument('organization-id');
  55. $full = $input->getOption('full');
  56. $io = new SymfonyStyle($input, $output);
  57. $siteController = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class);
  58. $status = $siteController->getSiteStatusAction($org_id, $full);
  59. $headers = [];
  60. $values = [];
  61. foreach ($status->toArray() as $key => $value) {
  62. $headers[] = $key;
  63. $value = json_encode(
  64. str_replace("\"", "'", $value),
  65. JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
  66. );
  67. $value = trim($value, "\"");
  68. $values[] = $value;
  69. }
  70. $io->horizontalTable($headers, [$values]);
  71. $io->success('');
  72. }
  73. }