Feature #23919 ยป 0016225.patch

Administrator Admin, 2010-11-02 21:12

View differences:

typo3/sysext/install/mod/class.tx_install.php (Arbeitskopie)
155 155
require_once(t3lib_extMgm::extPath('install') . 'updates/class.tx_coreupdates_statictemplates.php');
156 156
require_once(t3lib_extMgm::extPath('install') . 'updates/class.tx_coreupdates_t3skin.php');
157 157
require_once(t3lib_extMgm::extPath('install') . 'updates/class.tx_coreupdates_compressionlevel.php');
158
require_once(t3lib_extMgm::extPath('install') . 'updates/class.tx_coreupdates_migrateworkspaces.php');
158 159

  
159 160
/**
160 161
 * Install Tool module
typo3/sysext/install/updates/class.tx_coreupdates_migrateworkspaces.php (Revision 0)
1
<?php
2
/***************************************************************
3
*  Copyright notice
4
*
5
*  (c) 2010 Tolleiv Nietsch <info@tolleiv.de>
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
*  A copy is found in the textfile GPL.txt and important notices to the license
17
*  from the author is found in LICENSE.txt distributed with these scripts.
18
*
19
*
20
*  This script is distributed in the hope that it will be useful,
21
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
*  GNU General Public License for more details.
24
*
25
*  This copyright notice MUST APPEAR in all copies of the script!
26
***************************************************************/
27

  
28

  
29
/**
30
 * Migrates workspaces from TYPO3 versions below 4.5.
31
 *
32
 * @author Tolleiv Nietsch <info@tolleiv.de>
33
 * @version $Id$
34
 */
35
class tx_coreupdates_migrateworkspaces extends tx_coreupdates_installsysexts {
36
	public $versionNumber;	// version number coming from t3lib_div::int_from_ver()
37

  
38
	/**
39
	 * parent object
40
	 *
41
	 * @var tx_install
42
	 */
43
	public $pObj;
44
	public $userInput;	// user input
45
	public $sqlQueries;
46

  
47
	/**
48
	 * Checks if an update is needed
49
	 *
50
	 * @param	string		&$description: The description for the update
51
	 * @return	boolean		whether an update is needed (true) or not (false)
52
	 */
53
	public function checkForUpdate(&$description) {
54
		$result = false;
55
		$description = 'Migrates the old hardcoded draft workspace to be a real workspace element';
56

  
57
		if ($this->versionNumber >= 4005000) {
58
			$this->includeTCA();
59
			$result = $this->isDraftWorkspaceUsed();
60
		}
61

  
62
		return $result;
63
	}
64

  
65
	/**
66
	 * @param string $inputPrefix
67
	 * @return void
68
	 */
69
	public function getUserInput($inputPrefix) {
70
		return;
71
	}
72

  
73
	/**
74
	 * Performs the database update. Changes existing workspaces to use the new custom workspaces
75
	 *
76
	 * @param	array		&$dbQueries: queries done in this update
77
	 * @param	mixed		&$customMessages: custom messages
78
	 * @return	boolean		whether it worked (true) or not (false)
79
	 */
80
	public function performUpdate(&$dbQueries, &$customMessages) {
81
		$result = TRUE;
82

  
83
		if($this->versionNumber < 4005000)	{
84
			return FALSE;
85
		}
86

  
87
			// There's no TCA available yet
88
		$this->includeTCA();
89

  
90
			// install version extension (especially when updating from very old TYPO3 versions
91
		$this->installExtensions(array('version'));
92

  
93
			// create a new dedicated "Draft" workspace and move all records to that new workspace
94
		if ($this->isDraftWorkspaceUsed()) {
95
			$draftWsId = $this->createWorkspace();
96
			if (is_integer($draftWsId)) {
97
				$this->migrateDraftWorkspaceRecordsToWorkspace($draftWsId);
98
			}
99
		}
100

  
101
		if (is_array($this->sqlQueries) && is_array($dbQueries)) {
102
			$dbQueries = array_merge($dbQueries, $this->sqlQueries);
103
		}
104

  
105
		return $result;
106
	}
107

  
108
	/**
109
	 * Install a extensions
110
	 *
111
	 * @param		string		The extension key
112
	 * @return	boolean	Determines whether this was successful or not
113
	 */
114
	protected function installExtensions($extArr) {
115
		if (!is_array($extArr)) {
116
			return false;
117
		}
118

  
119
		$extList = $this->addExtToList($extArr);
120
		if ($extList) {
121
			$this->writeNewExtensionList($extList);
122
			$result = true;
123
		}
124
		return $result;
125
	}
126

  
127
	/**
128
	 * Check if any table contains draft-workspace records
129
	 *
130
	 * @params		void
131
	 * @return bool
132
	 */
133
	protected function isDraftWorkspaceUsed() {
134
		$foundDraftRecords = FALSE;
135

  
136
		$tables = array_keys($GLOBALS['TCA']);
137
		foreach($tables as $table) {
138
			$versioningVer = t3lib_div::intInRange($GLOBALS['TCA'][$table]['ctrl']['versioningWS'], 0, 2, 0);
139
			if ($versioningVer > 0) {
140
				if ($this->hasElementsOnWorkspace($table, -1)) {
141
					$foundDraftRecords = TRUE;
142
					break;
143
				}
144
			}
145
		}
146

  
147
		return $foundDraftRecords;
148
	}
149

  
150
	/**
151
	 * Create a real workspace named "Draft"
152
	 *
153
	 * @param	void
154
	 * @return integer
155
	 */
156
	protected function createWorkspace() {
157
			// @todo who are the reviewers and owners for this workspace?
158
			// In previous versions this was defined in be_groups/be_users with the setting "Edit in Draft"
159
		$data = array(
160
			'title' => 'Draft'
161
		);
162
		$GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_workspace', $data);
163
		$this->sqlQueries[] =  $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery;
164
		return $GLOBALS['TYPO3_DB']->sql_insert_id();
165
	}
166

  
167
	/**
168
	 * Migrates all elements from the old draft workspace to the new one.
169
	 *
170
	 * @param  integer $wsId
171
	 * @return void
172
	 */
173
	protected function migrateDraftWorkspaceRecordsToWorkspace($wsId) {
174
		$tables = array_keys($GLOBALS['TCA']);
175
		$where = 't3ver_wsid=-1 AND deleted=0';
176
		$values = array(
177
			't3ver_wsid' => intval($wsId)
178
		);
179
		foreach($tables as $table) {
180
			$versioningVer = t3lib_div::intInRange($GLOBALS['TCA'][$table]['ctrl']['versioningWS'], 0, 2, 0);
181
			if ($versioningVer > 0 && $this->hasElementsOnWorkspace($table, -1)) {
182
				$GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, $where, $values);
183
				$this->sqlQueries[] =  $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery;
184
			}
185
		}
186
	}
187

  
188
	/**
189
	 * Includes the TCA definition of installed extensions.
190
	 *
191
	 * @return void
192
	 */
193
	protected function includeTCA() {
194
		global $TCA; // this is relevant because it's used within the included ext_tables.php files - do NOT remove it
195

  
196
		include_once(TYPO3_tables_script ? PATH_typo3conf . TYPO3_tables_script : PATH_t3lib . 'stddb/tables.php');
197
			// Extension additions
198
		if ($GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE'])	{
199
			include_once(PATH_typo3conf . $GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE'] . '_ext_tables.php');
200
		} else {
201
			include_once(PATH_t3lib . 'stddb/load_ext_tables.php');
202
		}
203
	}
204

  
205
	/**
206
	 * Determines whether a table has elements in a particular workspace.
207
	 *
208
	 * @param string $table Name of the table
209
	 * @param integer $workspaceId Id of the workspace
210
	 * @return boolean
211
	 */
212
	protected function hasElementsOnWorkspace($table, $workspaceId) {
213
		$count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
214
			'uid',
215
			$table,
216
			'deleted=0 AND t3ver_wsid=' . intval($workspaceId)
217
		);
218

  
219
		$this->sqlQueries[] =  $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery;
220

  
221
		return ($count > 0);
222
	}
223
}
224
?>
typo3/sysext/install/ext_localconf.php (Arbeitskopie)
39 39
	// Version 4.4: warn for set CompressionLevel and warn user to update his .htaccess
40 40
$TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['update']['checkForCompressionLevel'] = 'tx_coreupdates_compressionlevel';
41 41

  
42
	// Version 4.5: migrate workspaces to use custom stages and install the required extensions
43
$TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['update']['migrateWorkspaces'] = 'tx_coreupdates_migrateworkspaces';
44

  
42 45
?>
    (1-1/1)