UndeleteSiteCommand.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 undo the soft-deletion an existing organization's website
  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")
  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)
  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. $io->success(sprintf("The website with root uid " . $rootUid . " has been restored"));
  56. return 0;
  57. }
  58. }