[TASK] Re-work/simplify copyright header in PHP files - Part 9
[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 * Automatic publishing of workspaces.
18 *
19 * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
20 */
21 class AutoPublishService {
22
23 /**
24 * This method is called by the Scheduler task that triggers
25 * the autopublication process
26 * It searches for workspaces whose publication date is in the past
27 * and publishes them
28 *
29 * @return void
30 */
31 public function autoPublishWorkspaces() {
32 global $TYPO3_CONF_VARS;
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('uid,swap_modes,publish_time,unpublish_time', 'sys_workspace', 'pid=0
39 AND
40 ((publish_time!=0 AND publish_time<=' . (int)$GLOBALS['EXEC_TIME'] . ')
41 OR (publish_time=0 AND unpublish_time!=0 AND unpublish_time<=' . (int)$GLOBALS['EXEC_TIME'] . '))' . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('sys_workspace'));
42 $workspaceService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\WorkspaceService');
43 foreach ($workspaces as $rec) {
44 // First, clear start/end time so it doesn't get select once again:
45 $fieldArray = $rec['publish_time'] != 0 ? array('publish_time' => 0) : array('unpublish_time' => 0);
46 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_workspace', 'uid=' . (int)$rec['uid'], $fieldArray);
47 // Get CMD array:
48 $cmd = $workspaceService->getCmdArrayForPublishWS($rec['uid'], $rec['swap_modes'] == 1);
49 // $rec['swap_modes']==1 means that auto-publishing will swap versions, not just publish and empty the workspace.
50 // Execute CMD array:
51 $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
52 $tce->stripslashes_values = 0;
53 $tce->start(array(), $cmd);
54 $tce->process_cmdmap();
55 }
56 // Restore admin status
57 $GLOBALS['BE_USER']->user['admin'] = $currentAdminStatus;
58 }
59
60 }