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