TYPO3 CMS  TYPO3_8-7
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 
20 
25 {
32  public function autoPublishWorkspaces()
33  {
34  // Temporarily set admin rights
35  // @todo once workspaces are cleaned up a better solution should be implemented
36  $currentAdminStatus = $GLOBALS['BE_USER']->user['admin'];
37  $GLOBALS['BE_USER']->user['admin'] = 1;
38 
39  // Select all workspaces that needs to be published / unpublished:
40  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_workspace');
41  $queryBuilder->getRestrictions()
42  ->removeAll()
43  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
44 
45  $result = $queryBuilder
46  ->select('uid', 'swap_modes', 'publish_time', 'unpublish_time')
47  ->from('sys_workspace')
48  ->where(
49  $queryBuilder->expr()->eq(
50  'pid',
51  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
52  ),
53  $queryBuilder->expr()->orX(
54  $queryBuilder->expr()->andX(
55  $queryBuilder->expr()->neq(
56  'publish_time',
57  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
58  ),
59  $queryBuilder->expr()->lte(
60  'publish_time',
61  $queryBuilder->createNamedParameter($GLOBALS['EXEC_TIME'], \PDO::PARAM_INT)
62  )
63  ),
64  $queryBuilder->expr()->andX(
65  $queryBuilder->expr()->eq(
66  'publish_time',
67  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
68  ),
69  $queryBuilder->expr()->neq(
70  'unpublish_time',
71  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
72  ),
73  $queryBuilder->expr()->lte(
74  'unpublish_time',
75  $queryBuilder->createNamedParameter($GLOBALS['EXEC_TIME'], \PDO::PARAM_INT)
76  )
77  )
78  )
79  )
80  ->execute();
81 
82  $workspaceService = GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\WorkspaceService::class);
83  while ($rec = $result->fetch()) {
84  // First, clear start/end time so it doesn't get select once again:
85  $fieldArray = $rec['publish_time'] != 0
86  ? ['publish_time' => 0]
87  : ['unpublish_time' => 0];
88 
89  GeneralUtility::makeInstance(ConnectionPool::class)
90  ->getConnectionForTable('sys_workspace')
91  ->update(
92  'sys_workspace',
93  $fieldArray,
94  ['uid' => (int)$rec['uid']]
95  );
96 
97  // Get CMD array:
98  $cmd = $workspaceService->getCmdArrayForPublishWS($rec['uid'], $rec['swap_modes'] == 1);
99  // $rec['swap_modes']==1 means that auto-publishing will swap versions, not just publish and empty the workspace.
100  // Execute CMD array:
101  $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
102  $tce->start([], $cmd);
103  $tce->process_cmdmap();
104  }
105  // Restore admin status
106  $GLOBALS['BE_USER']->user['admin'] = $currentAdminStatus;
107  }
108 }
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']