DeleteSiteCommand.php 3.4 KB

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