Fixed bug #11290: PHP notices from XCLASS inclusions
[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 $service = t3lib_div::makeInstance('Tx_Workspaces_Service_Stages');
68 // @todo: remove the encode/decode functionality
69 $pseudoStageId = $service->encodeStageUid($stageId);
70
71 $fields = array('t3ver_stage' => Tx_Workspaces_Service_Stages::STAGE_EDIT_ID);
72
73 foreach ($this->getTcaTables() as $tcaTable) {
74 if (t3lib_BEfunc::isTableWorkspaceEnabled($tcaTable)) {
75
76 $where = 't3ver_stage = ' . intval($pseudoStageId);
77 $where .= ' AND t3ver_wsid > 0 AND pid=-1';
78 $where .= t3lib_BEfunc::deleteClause($tcaTable);
79
80 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($tcaTable, $where, $fields);
81 }
82 }
83 }
84
85 /**
86 * Flushes elements of a particular workspace to avoid orphan records.
87 *
88 * @param integer $workspaceId The workspace to be flushed
89 * @return void
90 */
91 protected function flushWorkspaceElements($workspaceId) {
92 $command = array();
93
94 foreach ($this->getTcaTables() as $tcaTable) {
95 if (t3lib_BEfunc::isTableWorkspaceEnabled($tcaTable)) {
96 $where = '1=1';
97 $where .= t3lib_BEfunc::getWorkspaceWhereClause($tcaTable, $workspaceId);
98 $where .= t3lib_BEfunc::deleteClause($tcaTable);
99
100 $records = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', $tcaTable, $where, '', '', '', 'uid');
101 if (is_array($records)) {
102 foreach (array_keys($records) as $recordId) {
103 $command[$tcaTable][$recordId]['version']['action'] = 'flush';
104 }
105 }
106 }
107 }
108
109 if (count($command)) {
110 $tceMain = $this->getTceMain();
111 $tceMain->start(array(), $command);
112 $tceMain->process_cmdmap();
113 }
114 }
115
116 /**
117 * Gets all defined TCA tables.
118 *
119 * @return array
120 */
121 protected function getTcaTables() {
122 return array_keys($GLOBALS['TCA']);
123 }
124
125 /**
126 * Gets a new instance of t3lib_TCEmain.
127 *
128 * @return t3lib_TCEmain
129 */
130 protected function getTceMain() {
131 $tceMain = t3lib_div::makeInstance('t3lib_TCEmain');
132 $tceMain->stripslashes_values = 0;
133 return $tceMain;
134 }
135
136 }
137
138
139 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Service/Tcemain.php'])) {
140 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Service/Tcemain.php']);
141 }
142 ?>