‪TYPO3CMS  9.5
AutoPublishService.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 
28 {
29  public function ‪__construct()
30  {
31  trigger_error('AutoPublishService will be removed in TYPO3 v10.0. Use the symfony command "workspaces:autopublish" instead.', E_USER_DEPRECATED);
32  }
33 
41  public function ‪autoPublishWorkspaces()
42  {
43  // Temporarily set admin rights
44  // @todo once workspaces are cleaned up a better solution should be implemented
45  $currentAdminStatus = ‪$GLOBALS['BE_USER']->user['admin'];
46  ‪$GLOBALS['BE_USER']->user['admin'] = 1;
47 
48  // Select all workspaces that needs to be published / unpublished:
49  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_workspace');
50  $queryBuilder->getRestrictions()
51  ->removeAll()
52  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
53 
54  $result = $queryBuilder
55  ->select('uid', 'swap_modes', 'publish_time', 'unpublish_time')
56  ->from('sys_workspace')
57  ->where(
58  $queryBuilder->expr()->eq(
59  'pid',
60  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
61  ),
62  $queryBuilder->expr()->orX(
63  $queryBuilder->expr()->andX(
64  $queryBuilder->expr()->neq(
65  'publish_time',
66  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
67  ),
68  $queryBuilder->expr()->lte(
69  'publish_time',
70  $queryBuilder->createNamedParameter(‪$GLOBALS['EXEC_TIME'], \PDO::PARAM_INT)
71  )
72  ),
73  $queryBuilder->expr()->andX(
74  $queryBuilder->expr()->eq(
75  'publish_time',
76  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
77  ),
78  $queryBuilder->expr()->neq(
79  'unpublish_time',
80  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
81  ),
82  $queryBuilder->expr()->lte(
83  'unpublish_time',
84  $queryBuilder->createNamedParameter(‪$GLOBALS['EXEC_TIME'], \PDO::PARAM_INT)
85  )
86  )
87  )
88  )
89  ->execute();
90 
91  $workspaceService = GeneralUtility::makeInstance(WorkspaceService::class);
92  while ($rec = $result->fetch()) {
93  // First, clear start/end time so it doesn't get select once again:
94  $fieldArray = $rec['publish_time'] != 0
95  ? ['publish_time' => 0]
96  : ['unpublish_time' => 0];
97 
98  GeneralUtility::makeInstance(ConnectionPool::class)
99  ->getConnectionForTable('sys_workspace')
100  ->update(
101  'sys_workspace',
102  $fieldArray,
103  ['uid' => (int)$rec['uid']]
104  );
105 
106  // Get CMD array:
107  $cmd = $workspaceService->getCmdArrayForPublishWS($rec['uid'], $rec['swap_modes'] == 1);
108  // $rec['swap_modes']==1 means that auto-publishing will swap versions, not just publish and empty the workspace.
109  // Execute CMD array:
110  $tce = GeneralUtility::makeInstance(DataHandler::class);
111  $tce->start([], $cmd);
112  $tce->process_cmdmap();
113  }
114  // Restore admin status
115  ‪$GLOBALS['BE_USER']->user['admin'] = $currentAdminStatus;
116  }
117 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:81
‪TYPO3\CMS\Workspaces\Service
Definition: AdditionalColumnService.php:2
‪TYPO3\CMS\Workspaces\Service\AutoPublishService\__construct
‪__construct()
Definition: AutoPublishService.php:29
‪TYPO3\CMS\Workspaces\Service\AutoPublishService\autoPublishWorkspaces
‪autoPublishWorkspaces()
Definition: AutoPublishService.php:41
‪$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\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Workspaces\Service\AutoPublishService
Definition: AutoPublishService.php:28