TYPO3  7.6
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 
21 {
30  public function autoPublishWorkspaces()
31  {
32  // Temporarily set admin rights
33  // @todo once workspaces are cleaned up a better solution should be implemented
34  $currentAdminStatus = $GLOBALS['BE_USER']->user['admin'];
35  $GLOBALS['BE_USER']->user['admin'] = 1;
36  // Select all workspaces that needs to be published / unpublished:
37  $workspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
38  'uid,swap_modes,publish_time,unpublish_time',
39  'sys_workspace',
40  'pid=0
41  AND
42  ((publish_time!=0 AND publish_time<=' . (int)$GLOBALS['EXEC_TIME'] . ')
43  OR (publish_time=0 AND unpublish_time!=0 AND unpublish_time<=' . (int)$GLOBALS['EXEC_TIME'] . '))' . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('sys_workspace')
44  );
45  $workspaceService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\WorkspaceService::class);
46  foreach ($workspaces as $rec) {
47  // First, clear start/end time so it doesn't get select once again:
48  $fieldArray = $rec['publish_time'] != 0 ? array('publish_time' => 0) : array('unpublish_time' => 0);
49  $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_workspace', 'uid=' . (int)$rec['uid'], $fieldArray);
50  // Get CMD array:
51  $cmd = $workspaceService->getCmdArrayForPublishWS($rec['uid'], $rec['swap_modes'] == 1);
52  // $rec['swap_modes']==1 means that auto-publishing will swap versions, not just publish and empty the workspace.
53  // Execute CMD array:
54  $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
55  $tce->stripslashes_values = 0;
56  $tce->start(array(), $cmd);
57  $tce->process_cmdmap();
58  }
59  // Restore admin status
60  $GLOBALS['BE_USER']->user['admin'] = $currentAdminStatus;
61  }
62 }