[TASK] Typo 'boostrap' should be 'bootstrap'
[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 use TYPO3\CMS\Core\Database\ConnectionPool;
18 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
19 use TYPO3\CMS\Core\DataHandling\DataHandler;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22 /**
23 * Automatic publishing of workspaces.
24 *
25 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0. This job is a one-time functionality now built into the "autopublish" functionality.
26 */
27 class AutoPublishService
28 {
29 public function __construct()
30 {
31 trigger_error('AutoPublishService will be removed in TYPO3 v10.0. Use the symfony command "workspaces:autopublish" instead.', E_USER_DEPRECATED);
32 }
33
34 /**
35 * This method is called by the Scheduler task that triggers
36 * the autopublication process
37 * It searches for workspaces whose publication date is in the past
38 * and publishes them
39 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0.
40 */
41 public function autoPublishWorkspaces()
42 {
43 // Temporarily set admin rights
44 // @todo once workspaces are cleaned up a better solution should be implemented
45 $currentAdminStatus = $GLOBALS['BE_USER']->user['admin'];
46 $GLOBALS['BE_USER']->user['admin'] = 1;
47
48 // Select all workspaces that needs to be published / unpublished:
49 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_workspace');
50 $queryBuilder->getRestrictions()
51 ->removeAll()
52 ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
53
54 $result = $queryBuilder
55 ->select('uid', 'swap_modes', 'publish_time', 'unpublish_time')
56 ->from('sys_workspace')
57 ->where(
58 $queryBuilder->expr()->eq(
59 'pid',
60 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
61 ),
62 $queryBuilder->expr()->orX(
63 $queryBuilder->expr()->andX(
64 $queryBuilder->expr()->neq(
65 'publish_time',
66 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
67 ),
68 $queryBuilder->expr()->lte(
69 'publish_time',
70 $queryBuilder->createNamedParameter($GLOBALS['EXEC_TIME'], \PDO::PARAM_INT)
71 )
72 ),
73 $queryBuilder->expr()->andX(
74 $queryBuilder->expr()->eq(
75 'publish_time',
76 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
77 ),
78 $queryBuilder->expr()->neq(
79 'unpublish_time',
80 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
81 ),
82 $queryBuilder->expr()->lte(
83 'unpublish_time',
84 $queryBuilder->createNamedParameter($GLOBALS['EXEC_TIME'], \PDO::PARAM_INT)
85 )
86 )
87 )
88 )
89 ->execute();
90
91 $workspaceService = GeneralUtility::makeInstance(WorkspaceService::class);
92 while ($rec = $result->fetch()) {
93 // First, clear start/end time so it doesn't get select once again:
94 $fieldArray = $rec['publish_time'] != 0
95 ? ['publish_time' => 0]
96 : ['unpublish_time' => 0];
97
98 GeneralUtility::makeInstance(ConnectionPool::class)
99 ->getConnectionForTable('sys_workspace')
100 ->update(
101 'sys_workspace',
102 $fieldArray,
103 ['uid' => (int)$rec['uid']]
104 );
105
106 // Get CMD array:
107 $cmd = $workspaceService->getCmdArrayForPublishWS($rec['uid'], $rec['swap_modes'] == 1);
108 // $rec['swap_modes']==1 means that auto-publishing will swap versions, not just publish and empty the workspace.
109 // Execute CMD array:
110 $tce = GeneralUtility::makeInstance(DataHandler::class);
111 $tce->start([], $cmd);
112 $tce->process_cmdmap();
113 }
114 // Restore admin status
115 $GLOBALS['BE_USER']->user['admin'] = $currentAdminStatus;
116 }
117 }