Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / updates / class.tx_coreupdates_installnewsysexts.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008-2011 Benjamin Mack <benni@typo3.org>
6 * (c) 2008-2011 Steffen Kamper <info@sk-typo3.de>
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 * Contains the update class for adding the system extension "simulate static".
31 *
32 * $Id$
33 *
34 * @author Benjamin Mack <benni@typo3.org>
35 * @author Steffen Kamper <info@sk-typo3.de>
36 */
37 class tx_coreupdates_installnewsysexts extends Tx_Install_Updates_Base {
38 protected $title = 'Install New System Extensions';
39 protected $newSystemExtensions = array('recycler', 't3editor', 'reports', 'scheduler');
40
41 /**
42 * Checks if an update is needed
43 *
44 * @param string &$description: The description for the update
45 * @return boolean whether an update is needed (true) or not (false)
46 */
47 public function checkForUpdate(&$description) {
48 $result = false;
49 $description = '
50 <p>
51 Install the following system extensions that are new in TYPO3
52 4.3:
53 </p>
54 ';
55
56 $description .= '
57 <ul>
58 ';
59
60 foreach($this->newSystemExtensions as $_EXTKEY) {
61 if (!t3lib_extMgm::isLoaded($_EXTKEY)) {
62 $EM_CONF = FALSE;
63 // extension may not been loaded at this point, so we can't use an API function from t3lib_extmgm
64 require (PATH_site . 'typo3/sysext/' . $_EXTKEY . '/ext_emconf.php');
65 $description .= '
66 <li>
67 <strong>
68 ' . $EM_CONF[$_EXTKEY]['title'] . ' [' . $_EXTKEY . ']
69 </strong>
70 <br />
71 ' . $EM_CONF[$_EXTKEY]['description'] . '
72 </li>
73 ';
74
75 $result = true;
76 }
77 }
78
79 $description .= '
80 </ul>
81 ';
82
83 return $result;
84 }
85
86 /**
87 * second step: get user input for installing sysextensions
88 *
89 * @param string input prefix, all names of form fields have to start with this. Append custom name in [ ... ]
90 * @return string HTML output
91 */
92 public function getUserInput($inputPrefix) {
93 $content = '
94 <p>
95 <strong>
96 Install the following system extensions that are new in
97 TYPO3 4.3:
98 </strong>
99 </p>
100 ';
101
102 $content .= '
103 <fieldset>
104 <ol>
105 ';
106
107 foreach($this->newSystemExtensions as $_EXTKEY) {
108 if (!t3lib_extMgm::isLoaded($_EXTKEY)) {
109 $EM_CONF = FALSE;
110 // extension may not been loaded at this point, so we can't use an API function from t3lib_extmgm
111 require (PATH_site . 'typo3/sysext/' . $_EXTKEY . '/ext_emconf.php');
112 $content .= '
113 <li class="labelAfter">
114 <input type="checkbox" id="' . $_EXTKEY . '" name="' . $inputPrefix . '[sysext][' . $_EXTKEY . ']" value="1" checked="checked" />
115 <label for="' . $_EXTKEY . '">' . $EM_CONF[$_EXTKEY]['title'] . ' [' . $_EXTKEY . ']</label>
116 </li>
117 ';
118 }
119 }
120
121 $content .= '
122 </ol>
123 </fieldset>
124 ';
125
126 return $content;
127 }
128
129 /**
130 * Adds the extensions "about", "cshmanual" and "simulatestatic" to the extList in TYPO3_CONF_VARS
131 *
132 * @param array &$dbQueries: queries done in this update
133 * @param mixed &$customMessages: custom messages
134 * @return boolean whether it worked (true) or not (false)
135 */
136 public function performUpdate(&$dbQueries, &$customMessages) {
137 $result = false;
138
139 // Get extension keys that were submitted by the used to be installed and that are valid for this update wizard:
140 if (is_array($this->pObj->INSTALL['update']['installNewSystemExtensions']['sysext'])) {
141 $extArray = array_intersect(
142 $this->newSystemExtensions,
143 array_keys($this->pObj->INSTALL['update']['installNewSystemExtensions']['sysext'])
144 );
145 $extList = $this->addExtToList($extArray);
146 if ($extList) {
147 $this->writeNewExtensionList($extList);
148 $result = true;
149 }
150 }
151
152 return $result;
153 }
154
155
156 /**
157 * Adds extension to extension list and returns new list. If -1 is returned, an error happend.
158 * Does NOT check dependencies yet.
159 *
160 * @param array Extension keys to add
161 * @return string New list of installed extensions or -1 if error
162 */
163 function addExtToList(array $extKeys) {
164 // Get list of installed extensions and add this one.
165 $tmpLoadedExt = $GLOBALS['TYPO3_LOADED_EXT'];
166 if (isset($tmpLoadedExt['_CACHEFILE'])) {
167 unset($tmpLoadedExt['_CACHEFILE']);
168 }
169
170 $listArr = array_keys($tmpLoadedExt);
171 $listArr = array_merge($listArr, $extKeys);
172
173 // Implode unique list of extensions to load and return:
174 return implode(',', array_unique($listArr));
175 }
176
177
178 /**
179 * Writes the extension list to "localconf.php" file
180 * Removes the temp_CACHED* files before return.
181 *
182 * @param string List of extensions
183 * @return void
184 */
185 protected function writeNewExtensionList($newExtList) {
186 // Instance of install tool
187 $instObj = new t3lib_install;
188 $instObj->allowUpdateLocalConf = 1;
189 $instObj->updateIdentity = 'TYPO3 Core Update Manager';
190
191 // Get lines from localconf file
192 $lines = $instObj->writeToLocalconf_control();
193 $instObj->setValueInLocalconfFile($lines, '$TYPO3_CONF_VARS[\'EXT\'][\'extList\']', $newExtList);
194 $instObj->writeToLocalconf_control($lines);
195
196 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList'] = $newExtList;
197 t3lib_extMgm::removeCacheFiles();
198 }
199 }
200 ?>