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