DeleteSiteCommand.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. ->addArgument(
  44. 'organization_id',
  45. InputArgument::REQUIRED,
  46. "The organization's id in the opentalent DB"
  47. );
  48. }
  49. /**
  50. * -- This method is expected by Typo3, do not rename ou remove --
  51. *
  52. * Executes the command for creating the new organization
  53. *
  54. * @param InputInterface $input
  55. * @param OutputInterface $output
  56. * @throws \Exception
  57. */
  58. protected function execute(InputInterface $input, OutputInterface $output)
  59. {
  60. $org_id = $input->getArgument('organization_id');
  61. $hard = $input->getOption('hard');
  62. $io = new SymfonyStyle($input, $output);
  63. $siteController = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class);
  64. $rootUid = $siteController->deleteSiteAction($org_id, $hard);
  65. if ($hard) {
  66. $io->success(sprintf("The website with root uid " . $rootUid . " has been permanently deleted"));
  67. } else {
  68. $io->success(sprintf("The website with root uid " . $rootUid . " has been soft-deleted. Use ot:site:undelete to restore it."));
  69. }
  70. }
  71. }