TYPO3 API  SVNRelease
class.tx_dbal_autoloader.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 2010 Xavier Perseguers <typo3@perseguers.ch>
00006  *  All rights reserved
00007  *
00008  *  This script is part of the TYPO3 project. The TYPO3 project is
00009  *  free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  The GNU General Public License can be found at
00015  *  http://www.gnu.org/copyleft/gpl.html.
00016  *  A copy is found in the textfile GPL.txt and important notices to the license
00017  *  from the author is found in LICENSE.txt distributed with these scripts.
00018  *
00019  *
00020  *  This script is distributed in the hope that it will be useful,
00021  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *  GNU General Public License for more details.
00024  *
00025  *  This copyright notice MUST APPEAR in all copies of the script!
00026  ***************************************************************/
00027 
00028 /**
00029  * Autoloader included from Install Tool that lets DBAL load itself
00030  * if it makes sense.
00031  *
00032  * $Id$
00033  *
00034  * @author Xavier Perseguers <typo3@perseguers.ch>
00035  *
00036  * @package TYPO3
00037  * @subpackage dbal
00038  */
00039 class tx_dbal_autoloader {
00040 
00041     /**
00042      * Activates DBAL if it is supported.
00043      *
00044      * @param tx_install $instObj
00045      * @return void
00046      */
00047     public function execute(tx_install $instObj) {
00048         if ($instObj->mode == '123') {
00049             switch ($instObj->step) {
00050                 case 1:
00051                     if (!t3lib_extMgm::isLoaded('dbal') && $this->isDbalSupported()) {
00052                         $this->activateDbal();
00053 
00054                         // Reload page to have Install Tool actually load DBAL
00055                         $redirectUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_URL');
00056                         t3lib_utility_Http::redirect($redirectUrl);
00057                     }
00058                     break;
00059                 case 2:
00060                     if (!t3lib_extMgm::isLoaded('dbal') && $this->isDbalSupported()) {
00061                         $this->activateDbal();
00062                     }
00063                     break;
00064                 case 3:
00065                     $driver = $instObj->INSTALL['localconf.php']['typo_db_driver'];
00066                     if ($driver === 'mysql') {
00067                         $this->deactivateDbal();
00068                     }
00069                     break;
00070             }
00071         }
00072     }
00073 
00074     /**
00075      * Returns TRUE if PHP modules to run DBAL are loaded.
00076      *
00077      * @return boolean
00078      */
00079     protected function isDbalSupported() {
00080         return extension_loaded('odbc')
00081                 || extension_loaded('pdo')
00082                 || extension_loaded('oci8');
00083     }
00084 
00085     /**
00086      * Activates DBAL.
00087      *
00088      * @return void
00089      */
00090     protected function activateDbal() {
00091         $extList = t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList']);
00092         if (!t3lib_div::inArray($extList, 'adodb')) {
00093             $extList[] = 'adodb';
00094         }
00095         if (!t3lib_div::inArray($extList, 'dbal')) {
00096             $extList[] = 'dbal';
00097         }
00098         $this->updateExtensionList(implode(',', $extList));
00099     }
00100 
00101     /**
00102      * Dectivates DBAL.
00103      *
00104      * @return void
00105      */
00106     protected function deactivateDbal() {
00107         $extList = t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList']);
00108         $extList = array_flip($extList);
00109 
00110         // Remove sysext dbal and adodb
00111         if (isset($extList['dbal'])) {
00112             unset($extList['dbal']);
00113         }
00114         if (isset($extList['adodb'])) {
00115             unset($extList['adodb']);
00116         }
00117         $extList = array_flip($extList);
00118 
00119         $this->updateExtensionList(implode(',', $extList));
00120     }
00121 
00122     /**
00123      * Updates the list of extensions.
00124      *
00125      * @param string $newExtList
00126      * @return void
00127      */
00128     protected function updateExtensionList($newExtList) {
00129         // Instance of install tool
00130         $instObj = t3lib_div::makeInstance('t3lib_install');
00131         $instObj->allowUpdateLocalConf = 1;
00132         $instObj->updateIdentity = 'TYPO3 Core Update Manager';
00133 
00134         try {
00135             // Get lines from localconf file
00136             $lines = $instObj->writeToLocalconf_control();
00137             $instObj->setValueInLocalconfFile($lines, '$TYPO3_CONF_VARS[\'EXT\'][\'extList\']', $newExtList);
00138             $result = $instObj->writeToLocalconf_control($lines);
00139             if ($result === 'nochange') {
00140                 $message = 'DBAL was not loaded.';
00141                 if (!@is_writable(PATH_typo3conf)) {
00142                     $message .= ' ' . PATH_typo3conf . ' is not writable!';
00143                 }
00144                 throw new Exception($message);
00145             }
00146 
00147             $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList'] = $newExtList;
00148             // Make sure to get cache file for backend, not frontend
00149             $cacheFilePrefix = $GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE'];
00150             $GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE'] = str_replace('temp_CACHED_FE', 'temp_CACHED', $cacheFilePrefix);
00151             t3lib_extMgm::removeCacheFiles();
00152         } catch (Exception $e) {
00153             $header = 'Error';
00154             $message = $e->getMessage();
00155             t3lib_timeTrack::debug_typo3PrintError($header, $message, FALSE, t3lib_div::getIndpEnv('TYPO3_SITE_URL'));
00156             exit;
00157         }
00158     }
00159 
00160 }
00161 
00162 
00163 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/class.tx_dbal_autoloader.php'])) {
00164     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/class.tx_dbal_autoloader.php']);
00165 }
00166 
00167 // Make instance:
00168 $SOBE = t3lib_div::makeInstance('tx_dbal_autoloader');
00169 $SOBE->execute($this);
00170 ?>