UndeleteSiteCommand.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 undoes the soft-deletion an existing organization's website and updates it
  14. *
  15. * @package Opentalent\OtAdmin\Command
  16. */
  17. class UndeleteSiteCommand extends Command
  18. {
  19. public function __construct(
  20. private readonly SiteController $siteController
  21. ) {
  22. parent::__construct();
  23. }
  24. /**
  25. * -- This method is expected by Typo3, do not rename ou remove --
  26. *
  27. * Allows to configure the command.
  28. * Allows to add a description, a help text, and / or define arguments.
  29. *
  30. */
  31. protected function configure(): void
  32. {
  33. $this
  34. ->setName("ot:site:undelete")
  35. ->setDescription("Undo the soft-deletion of an organization website and update it")
  36. ->setHelp("Call this method by giving it the organization's id in the Opentalent DB.
  37. If an organization website has been deleted with the ot:site:delete
  38. command and without the --hard option, you can undo the deletion with
  39. this command.")
  40. ->addArgument(
  41. 'organization-id',
  42. InputArgument::REQUIRED,
  43. "The organization's id in the opentalent DB"
  44. );
  45. }
  46. /**
  47. * -- This method is expected by Typo3, do not rename ou remove --
  48. *
  49. * @param InputInterface $input
  50. * @param OutputInterface $output
  51. * @return int
  52. * @throws \Exception
  53. */
  54. protected function execute(InputInterface $input, OutputInterface $output): int
  55. {
  56. $org_id = $input->getArgument('organization-id');
  57. $io = new SymfonyStyle($input, $output);
  58. $rootUid = $this->siteController->undeleteSiteAction($org_id);
  59. $this->siteController->updateSiteAction($org_id);
  60. $io->success(sprintf("The website with root uid " . $rootUid . " has been restored"));
  61. return 0;
  62. }
  63. }