GetSiteStatusCommand.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. * @return int
  51. * @throws \Opentalent\OtCore\Exception\NoSuchWebsiteException
  52. * @throws \TYPO3\CMS\Extbase\Object\Exception
  53. */
  54. protected function execute(InputInterface $input, OutputInterface $output)
  55. {
  56. $org_id = $input->getArgument('organization-id');
  57. $full = $input->getOption('full');
  58. $io = new SymfonyStyle($input, $output);
  59. $siteController = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class);
  60. $status = $siteController->getSiteStatusAction($org_id, $full);
  61. $headers = [];
  62. $values = [];
  63. foreach ($status->toArray() as $key => $value) {
  64. $headers[] = $key;
  65. $value = json_encode(
  66. str_replace("\"", "'", $value),
  67. JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
  68. );
  69. $value = trim($value, "\"");
  70. $values[] = $value;
  71. }
  72. $io->horizontalTable($headers, [$values]);
  73. $io->success('');
  74. return 0;
  75. }
  76. }