Follow-up to #15045: Trailing newlines after php closing tag. (Thanks to Nikolas...
[Packages/TYPO3.CMS.git] / typo3 / sysext / dbal / class.tx_dbal_autoloader.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 Xavier Perseguers <typo3@perseguers.ch>
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 * Autoloader included from Install Tool that lets DBAL load itself
30 * if it makes sense.
31 *
32 * $Id$
33 *
34 * @author Xavier Perseguers <typo3@perseguers.ch>
35 *
36 * @package TYPO3
37 * @subpackage dbal
38 */
39 class tx_dbal_autoloader {
40
41 /**
42 * Activates DBAL if it is supported.
43 *
44 * @param tx_install $instObj
45 * @return void
46 */
47 public function execute(tx_install $instObj) {
48 switch ($instObj->step) {
49 case 1:
50 case 2:
51 if (!t3lib_extMgm::isLoaded('dbal') && $this->isDbalSupported()) {
52 $this->activateDbal();
53 }
54 break;
55 case 3:
56 $driver = $instObj->INSTALL['localconf.php']['typo_db_driver'];
57 if ($driver === 'mysql') {
58 $this->deactivateDbal();
59 }
60 break;
61 }
62 }
63
64 /**
65 * Returns TRUE if PHP modules to run DBAL are loaded.
66 *
67 * @return boolean
68 */
69 protected function isDbalSupported() {
70 return extension_loaded('odbc')
71 || extension_loaded('pdo')
72 || extension_loaded('oci8');
73 }
74
75 /**
76 * Activates DBAL.
77 *
78 * @return void
79 */
80 protected function activateDbal() {
81 $extList = t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList']);
82 if (!t3lib_div::inArray($extList, 'adodb')) {
83 $extList[] = 'adodb';
84 }
85 if (!t3lib_div::inArray($extList, 'dbal')) {
86 $extList[] = 'dbal';
87 }
88 $this->updateExtensionList(implode(',', $extList));
89 }
90
91 /**
92 * Dectivates DBAL.
93 *
94 * @return void
95 */
96 protected function deactivateDbal() {
97 $extList = t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList']);
98 $extList = array_flip($extList);
99
100 // Remove sysext dbal and adodb
101 if (isset($extList['dbal'])) {
102 unset($extList['dbal']);
103 }
104 if (isset($extList['adodb'])) {
105 unset($extList['adodb']);
106 }
107 $extList = array_flip($extList);
108
109 $this->updateExtensionList(implode(',', $extList));
110 }
111
112 /**
113 * Updates the list of extensions.
114 *
115 * @param string $newExtList
116 * @return void
117 */
118 protected function updateExtensionList($newExtList) {
119 // Instance of install tool
120 $instObj = t3lib_div::makeInstance('t3lib_install');
121 $instObj->allowUpdateLocalConf = 1;
122 $instObj->updateIdentity = 'TYPO3 Core Update Manager';
123
124 try {
125 // Get lines from localconf file
126 $lines = $instObj->writeToLocalconf_control();
127 $instObj->setValueInLocalconfFile($lines, '$TYPO3_CONF_VARS[\'EXT\'][\'extList\']', $newExtList);
128 $result = $instObj->writeToLocalconf_control($lines);
129 if ($result === 'nochange') {
130 $message = 'DBAL was not loaded.';
131 if (!@is_writable(PATH_typo3conf)) {
132 $message .= ' ' . PATH_typo3conf . ' is not writable!';
133 }
134 throw new Exception($message);
135 }
136
137 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList'] = $newExtList;
138 // Make sure to get cache file for backend, not frontend
139 $cacheFilePrefix = $GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE'];
140 $GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE'] = str_replace('temp_CACHED_FE', 'temp_CACHED', $cacheFilePrefix);
141 t3lib_extMgm::removeCacheFiles();
142 } catch (Exception $e) {
143 $header = 'Error';
144 $message = $e->getMessage();
145 t3lib_timeTrack::debug_typo3PrintError($header, $message, FALSE, t3lib_div::getIndpEnv('TYPO3_SITE_URL'));
146 exit;
147 }
148 }
149
150 }
151
152
153 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dbal/class.tx_dbal_autoloader.php']) {
154 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dbal/class.tx_dbal_autoloader.php']);
155 }
156
157 // Make instance:
158 $SOBE = t3lib_div::makeInstance('tx_dbal_autoloader');
159 $SOBE->execute($this);
160 ?>