1
votes
class RemoveHiddenPages extends Symfony\Component\Console\Command\Command 
{

  protected function execute(InputInterface $input, OutputInterface $output)
  {
      Bootstrap::initializeBackendAuthentication();
      $uid = someuid;
      $cmd['pages'][$uid]['delete'] = 1;
      $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
      $dataHandler->start([], $cmd);
      $dataHandler->process_cmdmap(); 
      // ....

I try to run the command from the command line. This results in an exception:

Tue, 17 Mar 2020 10:14:15 +0100 [CRITICAL] request="684c29a15bc6b" component="TYPO3.CMS.Core.Error.DebugExceptionHandler": 
Core: Exception handler (CLI): Uncaught TYPO3 Exception: Argument 1 passed to
TYPO3\CMS\Core\Session\Backend\DatabaseSessionBackend::update() must be of the type string, null given, 
called in /site/typo3/sysext/core/Classes/Authentication/AbstractUserAuthentication.php on line 1311 
| TypeError thrown in file /site/typo3/sysext/core/Classes/Session/Backend/DatabaseSessionBackend.php in line 159 
- {"exception":{"xdebug_message":"\nTypeError: Argument 1 passed to 
TYPO3\\CMS\\Core\\Session\\Backend\\DatabaseSessionBackend::update()
must be of the type string, null given, called in ....

In DataHandler::deletePages() a flash message is sent. This seems to cause the problem, as the session is not initialized. Is it possible to use the DataHandler in command controllers?

The example is based on:

I am using TYPO3 9.5.14

1
The flash message is only rendered if there was an error, so you need to debug and fix that first. - Mathias Brodala
Yes, you are right. If the error does not occur, this seems to work fine. It looks like the bug is related to forge.typo3.org/issues/85824 - Sybille Peters

1 Answers

0
votes

You can have a look into in2code/migration. There is a DataHandler call to move pages via symfony command: https://github.com/einpraegsam/migration/blob/master/Classes/Command/DataHandlerCommand.php

protected function execute(InputInterface $input, OutputInterface $output): int 
{
    $command = [];
    $command['pages'][(int)$input->getArgument('startPid')][$input->getArgument('action')]
        = (int)$input->getArgument('targetPid');
    /** @var DataHandler $dataHandler */
    $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
    $dataHandler->BE_USER = $GLOBALS['BE_USER'];
    $dataHandler->BE_USER->user['admin'] = 1;
    $dataHandler->userid = $GLOBALS['BE_USER']->user['uid'];
    $dataHandler->admin = true;
    $dataHandler->bypassAccessCheckForRecords = true;
    $dataHandler->copyTree = $input->getArgument('recursion');
    $dataHandler->deleteTree = true;
    $dataHandler->neverHideAtCopy = true;
    $dataHandler->start([], $command);
    $dataHandler->process_cmdmap();
    $output->writeln($this->getMessage($dataHandler));
    return 0;
}