32af77f48a561c824b5a47228b5d35ca01e77d6c
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / Service / AutoPublish.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Automatic publishing of workspaces.
27 *
28 * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
29 * @package Workspaces
30 * @subpackage Service
31 */
32 class tx_Workspaces_Service_AutoPublish {
33 /**
34 * This method is called by the Scheduler task that triggers
35 * the autopublication process
36 * It searches for workspaces whose publication date is in the past
37 * and publishes them
38 *
39 * @return void
40 */
41 public function autoPublishWorkspaces() {
42 global $TYPO3_CONF_VARS;
43
44 // Temporarily set admin rights
45 // FIXME: once workspaces are cleaned up a better solution should be implemented
46 $currentAdminStatus = $GLOBALS['BE_USER']->user['admin'];
47 $GLOBALS['BE_USER']->user['admin'] = 1;
48
49 // Select all workspaces that needs to be published / unpublished:
50 $workspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
51 'uid,swap_modes,publish_time,unpublish_time',
52 'sys_workspace',
53 'pid=0
54 AND
55 ((publish_time!=0 AND publish_time<=' . intval($GLOBALS['EXEC_TIME']) . ')
56 OR (publish_time=0 AND unpublish_time!=0 AND unpublish_time<=' . intval($GLOBALS['EXEC_TIME']) . '))'.
57 t3lib_BEfunc::deleteClause('sys_workspace')
58 );
59
60 $workspaceService = t3lib_div::makeInstance('tx_Workspaces_Service_Workspaces');
61
62 foreach ($workspaces as $rec) {
63
64 // First, clear start/end time so it doesn't get select once again:
65 $fieldArray = $rec['publish_time'] != 0 ? array('publish_time' => 0) : array('unpublish_time' => 0);
66 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_workspace', 'uid=' . intval($rec['uid']), $fieldArray);
67
68 // Get CMD array:
69 $cmd = $workspaceService->getCmdArrayForPublishWS($rec['uid'], $rec['swap_modes'] == 1); // $rec['swap_modes']==1 means that auto-publishing will swap versions, not just publish and empty the workspace.
70
71 // Execute CMD array:
72 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
73 $tce->stripslashes_values = 0;
74 $tce->start(array(), $cmd);
75 $tce->process_cmdmap();
76 }
77
78 // Restore admin status
79 $GLOBALS['BE_USER']->user['admin'] = $currentAdminStatus;
80 }
81 }
82
83
84 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Service/AutoPublish.php'])) {
85 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Service/AutoPublish.php']);
86 }
87 ?>