‪TYPO3CMS  ‪main
AutoPublishCommand.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Symfony\Component\Console\Command\Command;
21 use Symfony\Component\Console\Input\InputInterface;
22 use Symfony\Component\Console\Output\OutputInterface;
23 use Symfony\Component\Console\Style\SymfonyStyle;
31 
35 class ‪AutoPublishCommand extends Command
36 {
37  public function ‪__construct(
38  private readonly ‪WorkspaceService $workspaceService,
39  private readonly ‪ConnectionPool $connectionPool
40  ) {
41  parent::__construct();
42  }
43 
47  public function ‪configure()
48  {
49  $this->setHelp('Some workspaces can have an auto-publish publication date to put all "ready to publish" content online on a certain date.');
50  }
51 
55  protected function ‪execute(InputInterface $input, OutputInterface ‪$output): int
56  {
57  // Make sure the _cli_ user is loaded
59  $io = new SymfonyStyle($input, ‪$output);
60 
61  // Select all workspaces that needs to be published / unpublished
62  $statement = $this->‪getAffectedWorkspacesToPublish();
63 
64  $affectedWorkspaces = 0;
65  while ($workspaceRecord = $statement->fetchAssociative()) {
66  // First, clear start/end time so it doesn't get selected once again
67  $this->connectionPool
68  ->getConnectionForTable('sys_workspace')
69  ->update(
70  'sys_workspace',
71  ['publish_time' => 0],
72  ['uid' => (int)$workspaceRecord['uid']]
73  );
74 
75  // Get CMD array
76  $cmd = $this->workspaceService->getCmdArrayForPublishWS((int)$workspaceRecord['uid']);
77  $tce = GeneralUtility::makeInstance(DataHandler::class);
78  $tce->start([], $cmd);
79  $tce->process_cmdmap();
80  $affectedWorkspaces++;
81  }
82 
83  if ($affectedWorkspaces > 0) {
84  $io->success('Published ' . $affectedWorkspaces . ' workspaces.');
85  } else {
86  $io->note('Nothing to do.');
87  }
88  return Command::SUCCESS;
89  }
90 
95  protected function ‪getAffectedWorkspacesToPublish()
96  {
97  $queryBuilder = $this->connectionPool->getQueryBuilderForTable('sys_workspace');
98  $queryBuilder->getRestrictions()
99  ->removeAll()
100  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
101 
102  return $queryBuilder
103  ->select('uid', 'publish_time')
104  ->from('sys_workspace')
105  ->where(
106  $queryBuilder->expr()->eq(
107  'pid',
108  $queryBuilder->createNamedParameter(0, ‪Connection::PARAM_INT)
109  ),
110  $queryBuilder->expr()->neq(
111  'publish_time',
112  $queryBuilder->createNamedParameter(0, ‪Connection::PARAM_INT)
113  ),
114  $queryBuilder->expr()->lte(
115  'publish_time',
116  $queryBuilder->createNamedParameter(‪$GLOBALS['EXEC_TIME'], ‪Connection::PARAM_INT)
117  )
118  )
119  ->executeQuery();
120  }
121 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:95
‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:50
‪TYPO3\CMS\Workspaces\Command\AutoPublishCommand
Definition: AutoPublishCommand.php:36
‪TYPO3\CMS\Workspaces\Command\AutoPublishCommand\configure
‪configure()
Definition: AutoPublishCommand.php:47
‪TYPO3\CMS\Workspaces\Command\AutoPublishCommand\__construct
‪__construct(private readonly WorkspaceService $workspaceService, private readonly ConnectionPool $connectionPool)
Definition: AutoPublishCommand.php:37
‪TYPO3\CMS\Workspaces\Command\AutoPublishCommand\execute
‪execute(InputInterface $input, OutputInterface $output)
Definition: AutoPublishCommand.php:55
‪TYPO3\CMS\Workspaces\Command
Definition: AutoPublishCommand.php:18
‪TYPO3\CMS\Workspaces\Service\WorkspaceService
Definition: WorkspaceService.php:35
‪$output
‪$output
Definition: annotationChecker.php:119
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:39
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:28
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:64
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:48
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Core\Core\Bootstrap\initializeBackendAuthentication
‪static initializeBackendAuthentication()
Definition: Bootstrap.php:529
‪TYPO3\CMS\Workspaces\Command\AutoPublishCommand\getAffectedWorkspacesToPublish
‪Doctrine DBAL Result getAffectedWorkspacesToPublish()
Definition: AutoPublishCommand.php:95