UndeleteSiteCommand.php 2.3 KB

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