EnableFeEditingCommand.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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\Output\OutputInterface;
  8. use Symfony\Component\Console\Style\SymfonyStyle;
  9. use TYPO3\CMS\Core\Database\ConnectionPool;
  10. use TYPO3\CMS\Core\Utility\GeneralUtility;
  11. /**
  12. * This CLI command enable front-end editing for all be-users
  13. *
  14. * @package Opentalent\OtAdmin\Command
  15. */
  16. class EnableFeEditingCommand extends Command
  17. {
  18. /**
  19. * -- This method is expected by Typo3, do not rename ou remove --
  20. *
  21. * Allows to configure the command.
  22. * Allows to add a description, a help text, and / or define arguments.
  23. *
  24. */
  25. protected function configure()
  26. {
  27. $this
  28. ->setName("ot:users:enfeedit")
  29. ->setDescription("Enable front-end editing for all be-users");
  30. }
  31. /**
  32. * -- This method is expected by Typo3, do not rename ou remove --
  33. *
  34. * Executes the command for creating the new organization
  35. *
  36. * @param InputInterface $input
  37. * @param OutputInterface $output
  38. */
  39. protected function execute(InputInterface $input, OutputInterface $output)
  40. {
  41. $io = new SymfonyStyle($input, $output);
  42. $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
  43. ->getQueryBuilderForTable('be_users');
  44. $queryBuilder->getRestrictions()->removeAll();
  45. $statement = $queryBuilder
  46. ->select('be_users.*')
  47. ->from('be_users')
  48. ->where(
  49. $queryBuilder->expr()->eq('be_users.usergroup', $queryBuilder->createNamedParameter(3, \PDO::PARAM_INT))
  50. )
  51. ->execute()
  52. ;
  53. while ($row = $statement->fetch()) {
  54. $id = (int)$row['uid'];
  55. $BE_USER = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication');
  56. $user = $BE_USER->getRawUserByUid($id);
  57. $BE_USER->user = $user;
  58. $BE_USER->backendSetUC();
  59. $BE_USER->uc['frontend_editing'] = 1;
  60. $BE_USER->uc['frontend_editing_overlay'] = 1;
  61. $BE_USER->writeUC($BE_USER->uc);
  62. }
  63. $io->success(sprintf("-- done --"));
  64. }
  65. }