Cleanup: #11153: Determine whether Tx_Workspaces_Service_Stages::encodeStageUid and...
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / Service / Tcemain.php
1 <?php
2
3 /***************************************************************
4 * Copyright notice
5 *
6 * (c) 2010 Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
7 * All rights reserved
8 *
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 * A copy is found in the textfile GPL.txt and important notices to the license
18 * from the author is found in LICENSE.txt distributed with these scripts.
19 *
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28
29 /**
30 * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
31 * @package Workspaces
32 * @subpackage Service
33 */
34 class tx_Workspaces_Service_Tcemain {
35
36 /**
37 * In case a sys_workspace_stage record is deleted we do a hard reset
38 * for all existing records in that stage to avoid that any of these end up
39 * as orphan records.
40 *
41 * @param string $command
42 * @param string $table
43 * @param string $id
44 * @param string $value
45 * @param t3lib_TCEmain $tcemain
46 * @return void
47 */
48 public function processCmdmap_postProcess($command, $table, $id, $value, t3lib_TCEmain $tcemain) {
49 if ($command === 'delete') {
50 if ($table === Tx_Workspaces_Service_Stages::TABLE_STAGE) {
51 $this->resetStageOfElements($id);
52 } elseif ($table === tx_Workspaces_Service_Workspaces::TABLE_WORKSPACE) {
53 $this->flushWorkspaceElements($id);
54 }
55 }
56 }
57
58 /**
59 * In case a sys_workspace_stage record is deleted we do a hard reset
60 * for all existing records in that stage to avoid that any of these end up
61 * as orphan records.
62 *
63 * @param integer $stageId Elements with this stage are resetted
64 * @return void
65 */
66 protected function resetStageOfElements($stageId) {
67 $fields = array('t3ver_stage' => Tx_Workspaces_Service_Stages::STAGE_EDIT_ID);
68
69 foreach ($this->getTcaTables() as $tcaTable) {
70 if (t3lib_BEfunc::isTableWorkspaceEnabled($tcaTable)) {
71
72 $where = 't3ver_stage = ' . intval($stageId);
73 $where .= ' AND t3ver_wsid > 0 AND pid=-1';
74 $where .= t3lib_BEfunc::deleteClause($tcaTable);
75
76 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($tcaTable, $where, $fields);
77 }
78 }
79 }
80
81 /**
82 * Flushes elements of a particular workspace to avoid orphan records.
83 *
84 * @param integer $workspaceId The workspace to be flushed
85 * @return void
86 */
87 protected function flushWorkspaceElements($workspaceId) {
88 $command = array();
89
90 foreach ($this->getTcaTables() as $tcaTable) {
91 if (t3lib_BEfunc::isTableWorkspaceEnabled($tcaTable)) {
92 $where = '1=1';
93 $where .= t3lib_BEfunc::getWorkspaceWhereClause($tcaTable, $workspaceId);
94 $where .= t3lib_BEfunc::deleteClause($tcaTable);
95
96 $records = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', $tcaTable, $where, '', '', '', 'uid');
97 if (is_array($records)) {
98 foreach (array_keys($records) as $recordId) {
99 $command[$tcaTable][$recordId]['version']['action'] = 'flush';
100 }
101 }
102 }
103 }
104
105 if (count($command)) {
106 $tceMain = $this->getTceMain();
107 $tceMain->start(array(), $command);
108 $tceMain->process_cmdmap();
109 }
110 }
111
112 /**
113 * Gets all defined TCA tables.
114 *
115 * @return array
116 */
117 protected function getTcaTables() {
118 return array_keys($GLOBALS['TCA']);
119 }
120
121 /**
122 * Gets a new instance of t3lib_TCEmain.
123 *
124 * @return t3lib_TCEmain
125 */
126 protected function getTceMain() {
127 $tceMain = t3lib_div::makeInstance('t3lib_TCEmain');
128 $tceMain->stripslashes_values = 0;
129 return $tceMain;
130 }
131
132 }
133
134
135 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Service/Tcemain.php'])) {
136 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Service/Tcemain.php']);
137 }
138 ?>