‪TYPO3CMS  10.4
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;
30 
34 class ‪AutoPublishCommand extends Command
35 {
36 
40  public function ‪configure()
41  {
42  $this
43  ->setDescription('Publish a workspace with a publication date.')
44  ->setHelp('Some workspaces can have an auto-publish publication date to put all "ready to publish" content online on a certain date.');
45  }
46 
54  protected function ‪execute(InputInterface $input, OutputInterface ‪$output)
55  {
56  // Make sure the _cli_ user is loaded
58  $io = new SymfonyStyle($input, ‪$output);
59 
60  $workspaceService = GeneralUtility::makeInstance(WorkspaceService::class);
61 
62  // Select all workspaces that needs to be published / unpublished
63  $statement = $this->‪getAffectedWorkspacesToPublish();
64 
65  $affectedWorkspaces = 0;
66  while ($workspaceRecord = $statement->fetch()) {
67  // First, clear start/end time so it doesn't get selected once again
68  GeneralUtility::makeInstance(ConnectionPool::class)
69  ->getConnectionForTable('sys_workspace')
70  ->update(
71  'sys_workspace',
72  ['publish_time' => 0],
73  ['uid' => (int)$workspaceRecord['uid']]
74  );
75 
76  // Get CMD array
77  $cmd = $workspaceService->getCmdArrayForPublishWS(
78  $workspaceRecord['uid'],
79  (int)$workspaceRecord['swap_modes'] === 1
80  );
81  // $workspaceRecord['swap_modes'] == 1 means that auto-publishing will swap versions,
82  // not just publish and empty the workspace.
83  $tce = GeneralUtility::makeInstance(DataHandler::class);
84  $tce->start([], $cmd);
85  $tce->process_cmdmap();
86  $affectedWorkspaces++;
87  }
88 
89  if ($affectedWorkspaces > 0) {
90  $io->success('Published ' . $affectedWorkspaces . ' workspaces.');
91  } else {
92  $io->note('Nothing to do.');
93  }
94  return 0;
95  }
96 
102  {
103  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_workspace');
104  $queryBuilder->getRestrictions()
105  ->removeAll()
106  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
107 
108  return $queryBuilder
109  ->select('uid', 'swap_modes', 'publish_time')
110  ->from('sys_workspace')
111  ->where(
112  $queryBuilder->expr()->eq(
113  'pid',
114  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
115  ),
116  $queryBuilder->expr()->neq(
117  'publish_time',
118  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
119  ),
120  $queryBuilder->expr()->lte(
121  'publish_time',
122  $queryBuilder->createNamedParameter(‪$GLOBALS['EXEC_TIME'], \PDO::PARAM_INT)
123  )
124  )
125  ->execute();
126  }
127 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:84
‪TYPO3\CMS\Workspaces\Command\AutoPublishCommand\execute
‪int execute(InputInterface $input, OutputInterface $output)
Definition: AutoPublishCommand.php:54
‪TYPO3\CMS\Workspaces\Command\AutoPublishCommand
Definition: AutoPublishCommand.php:35
‪TYPO3\CMS\Workspaces\Command\AutoPublishCommand\configure
‪configure()
Definition: AutoPublishCommand.php:40
‪TYPO3\CMS\Core\Core\Bootstrap\initializeBackendAuthentication
‪static initializeBackendAuthentication($proceedIfNoUserIsLoggedIn=false)
Definition: Bootstrap.php:607
‪TYPO3\CMS\Workspaces\Command\AutoPublishCommand\getAffectedWorkspacesToPublish
‪Doctrine DBAL Driver Statement int getAffectedWorkspacesToPublish()
Definition: AutoPublishCommand.php:101
‪TYPO3\CMS\Workspaces\Command
Definition: AutoPublishCommand.php:18
‪TYPO3\CMS\Workspaces\Service\WorkspaceService
Definition: WorkspaceService.php:36
‪$output
‪$output
Definition: annotationChecker.php:119
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:28
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:66
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46