‪TYPO3CMS  9.5
AutoPublishCommand.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Symfony\Component\Console\Command\Command;
19 use Symfony\Component\Console\Input\InputInterface;
20 use Symfony\Component\Console\Output\OutputInterface;
21 use Symfony\Component\Console\Style\SymfonyStyle;
28 
32 class ‪AutoPublishCommand extends Command
33 {
34 
38  public function ‪configure()
39  {
40  $this
41  ->setDescription('Publish a workspace with a publication date.')
42  ->setHelp('Some workspaces can have an auto-publish publication date to put all "ready to publish" content online on a certain date.');
43  }
44 
51  protected function ‪execute(InputInterface $input, OutputInterface ‪$output)
52  {
53  // Make sure the _cli_ user is loaded
55  $io = new SymfonyStyle($input, ‪$output);
56 
57  $workspaceService = GeneralUtility::makeInstance(WorkspaceService::class);
58 
59  // Select all workspaces that needs to be published / unpublished
60  $statement = $this->‪getAffectedWorkspacesToPublish();
61 
62  $affectedWorkspaces = 0;
63  while ($workspaceRecord = $statement->fetch()) {
64  // First, clear start/end time so it doesn't get selected once again
65  $fieldArray = (int)$workspaceRecord['publish_time'] !== 0
66  ? ['publish_time' => 0]
67  : ['unpublish_time' => 0];
68 
69  GeneralUtility::makeInstance(ConnectionPool::class)
70  ->getConnectionForTable('sys_workspace')
71  ->update(
72  'sys_workspace',
73  $fieldArray,
74  ['uid' => (int)$workspaceRecord['uid']]
75  );
76 
77  // Get CMD array
78  $cmd = $workspaceService->getCmdArrayForPublishWS(
79  $workspaceRecord['uid'],
80  (int)$workspaceRecord['swap_modes'] === 1
81  );
82  // $workspaceRecord['swap_modes'] == 1 means that auto-publishing will swap versions,
83  // not just publish and empty the workspace.
84  $tce = GeneralUtility::makeInstance(DataHandler::class);
85  $tce->start([], $cmd);
86  $tce->process_cmdmap();
87  $affectedWorkspaces++;
88  }
89 
90  if ($affectedWorkspaces > 0) {
91  $io->success('Published ' . $affectedWorkspaces . ' workspaces.');
92  } else {
93  $io->note('Nothing to do.');
94  }
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', 'unpublish_time')
110  ->from('sys_workspace')
111  ->where(
112  $queryBuilder->expr()->eq(
113  'pid',
114  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
115  ),
116  $queryBuilder->expr()->orX(
117  $queryBuilder->expr()->andX(
118  $queryBuilder->expr()->neq(
119  'publish_time',
120  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
121  ),
122  $queryBuilder->expr()->lte(
123  'publish_time',
124  $queryBuilder->createNamedParameter(‪$GLOBALS['EXEC_TIME'], \PDO::PARAM_INT)
125  )
126  ),
127  $queryBuilder->expr()->andX(
128  $queryBuilder->expr()->eq(
129  'publish_time',
130  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
131  ),
132  $queryBuilder->expr()->neq(
133  'unpublish_time',
134  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
135  ),
136  $queryBuilder->expr()->lte(
137  'unpublish_time',
138  $queryBuilder->createNamedParameter(‪$GLOBALS['EXEC_TIME'], \PDO::PARAM_INT)
139  )
140  )
141  )
142  )
143  ->execute();
144  }
145 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:81
‪TYPO3\CMS\Workspaces\Command\AutoPublishCommand
Definition: AutoPublishCommand.php:33
‪TYPO3\CMS\Workspaces\Command\AutoPublishCommand\configure
‪configure()
Definition: AutoPublishCommand.php:38
‪TYPO3\CMS\Workspaces\Command\AutoPublishCommand\getAffectedWorkspacesToPublish
‪Doctrine DBAL Driver Statement int getAffectedWorkspacesToPublish()
Definition: AutoPublishCommand.php:101
‪TYPO3\CMS\Workspaces\Command\AutoPublishCommand\execute
‪execute(InputInterface $input, OutputInterface $output)
Definition: AutoPublishCommand.php:51
‪TYPO3\CMS\Workspaces\Command
Definition: AutoPublishCommand.php:3
‪TYPO3\CMS\Core\Core\Bootstrap\initializeBackendAuthentication
‪static Bootstrap null initializeBackendAuthentication($proceedIfNoUserIsLoggedIn=false)
Definition: Bootstrap.php:974
‪TYPO3\CMS\Workspaces\Service\WorkspaceService
Definition: WorkspaceService.php:34
‪$output
‪$output
Definition: annotationChecker.php:113
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:26
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:50
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45