DeleteSiteCommand.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 delete an existing organization's website
  14. *
  15. * @package Opentalent\OtAdmin\Command
  16. */
  17. class DeleteSiteCommand 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()
  32. {
  33. $this
  34. ->setName("ot:site:delete")
  35. ->setDescription("Delete an organization website")
  36. ->setHelp("Call this method by giving it the organization's id in the Opentalent DB.
  37. By default, it proceed to a soft deletion, marking the records as deleted
  38. and renaming files: this kind of deletion can then be undone
  39. with the ot:site:undelete command.
  40. If the --hard option is passed, the records and files will be permanently deleted,
  41. with no possibility of undoing. A confirmation will be demanded.")
  42. ->addOption(
  43. 'hard',
  44. null,
  45. InputOption::VALUE_NONE,
  46. "Permanently delete the records and files. Use with caution."
  47. )
  48. ->addOption(
  49. 'no-redirect',
  50. 'd',
  51. InputOption::VALUE_REQUIRED,
  52. "If set, the website's url won't be redirected to its parent's website"
  53. )
  54. ->addOption(
  55. 'force',
  56. 'f',
  57. InputOption::VALUE_NONE,
  58. "Force the deletion of website directories, even if they are not empty (this has no effect without the --hard option)"
  59. )
  60. ->addArgument(
  61. 'organization-id',
  62. InputArgument::REQUIRED,
  63. "The organization's id in the opentalent DB"
  64. );
  65. }
  66. /**
  67. * -- This method is expected by Typo3, do not rename ou remove --
  68. *
  69. * @param InputInterface $input
  70. * @param OutputInterface $output
  71. * @return int
  72. * @throws \Exception
  73. */
  74. protected function execute(InputInterface $input, OutputInterface $output)
  75. {
  76. $org_id = $input->getArgument('organization-id');
  77. $hard = $input->getOption('hard');
  78. $force = $input->getOption('force');
  79. $noRedirect = $input->getOption('no-redirect');
  80. $io = new SymfonyStyle($input, $output);
  81. $rootUid = $this->siteController->deleteSiteAction($org_id, $hard, !$noRedirect, $force);
  82. if ($hard) {
  83. $io->success(sprintf("The website with root uid " . $rootUid . " has been permanently deleted"));
  84. } else {
  85. $io->success(sprintf("The website with root uid " . $rootUid . " has been soft-deleted. Use ot:site:undelete to restore it."));
  86. }
  87. return 0;
  88. }
  89. }