9f72e977d66e4e1ae163d1ec56e7714e80735a6a
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / Service / AutoPublishService.php
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
17 /**
18 * Automatic publishing of workspaces.
19 *
20 * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
21 */
22 class AutoPublishService {
23
24 /**
25 * This method is called by the Scheduler task that triggers
26 * the autopublication process
27 * It searches for workspaces whose publication date is in the past
28 * and publishes them
29 *
30 * @return void
31 */
32 public function autoPublishWorkspaces() {
33 // Temporarily set admin rights
34 // FIXME: once workspaces are cleaned up a better solution should be implemented
35 $currentAdminStatus = $GLOBALS['BE_USER']->user['admin'];
36 $GLOBALS['BE_USER']->user['admin'] = 1;
37 // Select all workspaces that needs to be published / unpublished:
38 $workspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
39 'uid,swap_modes,publish_time,unpublish_time',
40 'sys_workspace',
41 'pid=0
42 AND
43 ((publish_time!=0 AND publish_time<=' . (int)$GLOBALS['EXEC_TIME'] . ')
44 OR (publish_time=0 AND unpublish_time!=0 AND unpublish_time<=' . (int)$GLOBALS['EXEC_TIME'] . '))' . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('sys_workspace')
45 );
46 $workspaceService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\WorkspaceService::class);
47 foreach ($workspaces as $rec) {
48 // First, clear start/end time so it doesn't get select once again:
49 $fieldArray = $rec['publish_time'] != 0 ? array('publish_time' => 0) : array('unpublish_time' => 0);
50 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_workspace', 'uid=' . (int)$rec['uid'], $fieldArray);
51 // Get CMD array:
52 $cmd = $workspaceService->getCmdArrayForPublishWS($rec['uid'], $rec['swap_modes'] == 1);
53 // $rec['swap_modes']==1 means that auto-publishing will swap versions, not just publish and empty the workspace.
54 // Execute CMD array:
55 $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
56 $tce->stripslashes_values = 0;
57 $tce->start(array(), $cmd);
58 $tce->process_cmdmap();
59 }
60 // Restore admin status
61 $GLOBALS['BE_USER']->user['admin'] = $currentAdminStatus;
62 }
63
64 }