dfca20a453aa23dcc816a9f8188605812f6671b5
[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 integer $step
45 * @return void
46 */
47 public function execute($step) {
48 t3lib_div::debug($step, 'current step');
49 switch ($step) {
50 case 1:
51 if (!t3lib_extMgm::isLoaded('dbal') && $this->isDbalSupported()) {
52 t3lib_div::debug('activated dbal');
53 $this->activateDbal();
54 }
55 break;
56 }
57 }
58
59 /**
60 * Returns TRUE if PHP modules to run DBAL are loaded.
61 *
62 * @return boolean
63 */
64 protected function isDbalSupported() {
65 return extension_loaded('odbc')
66 || extension_loaded('pdo')
67 || extension_loaded('oci8');
68 }
69
70 /**
71 * Activates DBAL.
72 *
73 * @return void
74 */
75 protected function activateDbal() {
76 $extList = t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList']);
77 if (!t3lib_div::inArray($extList, 'adodb')) {
78 $extList[] = 'adodb';
79 }
80 if (!t3lib_div::inArray($extList, 'dbal')) {
81 $extList[] = 'dbal';
82 }
83 $this->updateExtensionList(implode(',', $extList));
84 }
85
86 /**
87 * Updates the list of extensions.
88 *
89 * @param string $newExtList
90 * @return void
91 */
92 protected function updateExtensionList($newExtList) {
93 // Instance of install tool
94 $instObj = t3lib_div::makeInstance('t3lib_install');
95 $instObj->allowUpdateLocalConf = 1;
96 $instObj->updateIdentity = 'TYPO3 Core Update Manager';
97
98 // Get lines from localconf file
99 $lines = $instObj->writeToLocalconf_control();
100 $instObj->setValueInLocalconfFile($lines, '$TYPO3_CONF_VARS[\'EXT\'][\'extList\']', $newExtList);
101 $instObj->writeToLocalconf_control($lines);
102
103 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList'] = $newExtList;
104 // Make sure to get cache file for backend, not frontend
105 $cacheFilePrefix = $GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE'];
106 $GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE'] = str_replace('temp_CACHED_FE', 'temp_CACHED', $cacheFilePrefix);
107 t3lib_extMgm::removeCacheFiles();
108 }
109
110 }
111
112
113 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dbal/class.tx_dbal_autoloader.php']) {
114 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dbal/class.tx_dbal_autoloader.php']);
115 }
116
117 $installStep = $this->step;
118
119 // Make instance:
120 $SOBE = t3lib_div::makeInstance('tx_dbal_autoloader');
121 $SOBE->execute($installStep);
122 ?>