Fixed bug #14061: Do not die, be the exception!
authorSteffen Kamper <info@sk-typo3.de>
Tue, 13 Apr 2010 09:54:15 +0000 (09:54 +0000)
committerSteffen Kamper <info@sk-typo3.de>
Tue, 13 Apr 2010 09:54:15 +0000 (09:54 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@7338 709f56b5-9817-0410-a4d7-c38de5d9e867

12 files changed:
ChangeLog
t3lib/class.t3lib_db.php
t3lib/class.t3lib_div.php
t3lib/class.t3lib_extmgm.php
t3lib/class.t3lib_extobjbase.php
t3lib/class.t3lib_install.php
t3lib/class.t3lib_tcemain.php
t3lib/class.t3lib_userauth.php
t3lib/config_default.php
t3lib/thumbs.php
typo3/mod/tools/em/class.em_index.php
typo3/mod/tools/em/class.em_unzip.php

index e82cb54..7502cd8 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -15,6 +15,7 @@
 
 2010-04-13  Steffen Kamper  <info@sk-typo3.de>
 
+       * Fixed bug #14061: Do not die, be the exception!
        * Added Feature #13799: ExtJS driven fading in/out Flashmessages
        * Corrected spelling errors in felogin manual
        * Added Feature #12229: Add stdWrap date/strftime with GMT format property
index 8f3902d..48ee889 100644 (file)
@@ -384,7 +384,7 @@ class t3lib_DB {
 
        /**
         * Truncates a table.
-        * 
+        *
         * @param       string          Database tablename
         * @return      mixed           Result from handler
         */
@@ -514,8 +514,10 @@ class t3lib_DB {
                                return $query;
                        }
                } else {
-                       die('<strong>TYPO3 Fatal Error:</strong> "Where" clause argument for UPDATE ' .
-                               'query was not a string in $this->UPDATEquery() !');
+                       throw new InvalidArgumentException(
+                               'TYPO3 Fatal Error: "Where" clause argument for UPDATE query was not a string in $this->UPDATEquery() !',
+                               1270853880
+                       );
                }
        }
 
@@ -539,8 +541,10 @@ class t3lib_DB {
                        }
                        return $query;
                } else {
-                       die('<strong>TYPO3 Fatal Error:</strong> "Where" clause argument for DELETE ' .
-                               'query was not a string in $this->DELETEquery() !');
+                       throw new InvalidArgumentException(
+                               'TYPO3 Fatal Error: "Where" clause argument for DELETE query was not a string in $this->DELETEquery() !',
+                               1270853881
+                       );
                }
        }
 
@@ -582,7 +586,7 @@ class t3lib_DB {
        /**
         * Creates a SELECT SQL-statement to be used as subquery within another query.
         * BEWARE: This method should not be overriden within DBAL to prevent quoting from happening.
-        * 
+        *
         * @param       string          $select_fields: List of fields to select from the table.
         * @param       string          $from_table: Table from which to select.
         * @param       string          $where_clause: Conditional WHERE statement
@@ -604,7 +608,7 @@ class t3lib_DB {
 
        /**
         * Creates a TRUNCATE TABLE SQL-statement
-        * 
+        *
         * @param       string          See exec_TRUNCATEquery()
         * @return      string          Full SQL query for TRUNCATE TABLE
         */
@@ -1319,16 +1323,21 @@ class t3lib_DB {
        function connectDB() {
                if ($this->sql_pconnect(TYPO3_db_host, TYPO3_db_username, TYPO3_db_password)) {
                        if (!TYPO3_db) {
-                               die('No database selected');
-                               exit;
+                               throw new RuntimeException(
+                                       'TYPO3 Fatal Error: No database selected!',
+                                       1270853882
+                               );
                        } elseif (!$this->sql_select_db(TYPO3_db)) {
-                               die('Cannot connect to the current database, "' . TYPO3_db . '"');
-                               exit;
+                               throw new RuntimeException(
+                                       'TYPO3 Fatal Error: Cannot connect to the current database, "' . TYPO3_db . '"!',
+                                       1270853883
+                               );
                        }
                } else {
-                       die('The current username, password or host was not accepted when the ' .
-                               'connection to the database was attempted to be established!');
-                       exit;
+                       throw new RuntimeException(
+                               'TYPO3 Fatal Error: The current username, password or host was not accepted when the connection to the database was attempted to be established!',
+                               1270853884
+                       );
                }
        }
 
index 353d1d2..0f9fc0a 100644 (file)
@@ -1079,8 +1079,18 @@ final class t3lib_div {
         * @return      string          Returns the list without any duplicates of values, space around values are trimmed
         */
        public static function uniqueList($in_list, $secondParameter=NULL)      {
-               if (is_array($in_list)) die('t3lib_div::uniqueList() does NOT support array arguments anymore! Only string comma lists!');
-               if (isset($secondParameter))    die('t3lib_div::uniqueList() does NOT support more than a single argument value anymore. You have specified more than one.');
+               if (is_array($in_list)) {
+                       throw new InvalidArgumentException(
+                               'TYPO3 Fatal Error: t3lib_div::uniqueList() does NOT support array arguments anymore! Only string comma lists!',
+                               1270853885
+                       );
+               }
+               if (isset($secondParameter)) {
+                       throw new InvalidArgumentException(
+                               'TYPO3 Fatal Error: t3lib_div::uniqueList() does NOT support more than a single argument value anymore. You have specified more than one!',
+                               1270853886
+                       );
+               }
 
                return implode(',',array_unique(self::trimExplode(',',$in_list,1)));
        }
@@ -4465,7 +4475,10 @@ final class t3lib_div {
                                include($fileRef);
                                if (!is_array($LOCAL_LANG))     {
                                        $fileName = substr($fileRef, strlen(PATH_site));
-                                       die('\'' . $fileName . '\' is no TYPO3 language file)!');
+                                       throw new RuntimeException(
+                                               'TYPO3 Fatal Error: "' . $fileName . '" is no TYPO3 language file!',
+                                               1270853900
+                                       );
                                }
 
                                        // converting the default language (English)
@@ -4485,7 +4498,12 @@ final class t3lib_div {
                                        // Cache the content now:
                                $serContent = array('origFile'=>$hashSource, 'LOCAL_LANG'=>array('default'=>$LOCAL_LANG['default'], $langKey=>$LOCAL_LANG[$langKey]));
                                $res = self::writeFileToTypo3tempDir($cacheFileName, serialize($serContent));
-                               if ($res)       die('ERROR: '.$res);
+                               if ($res) {
+                                       throw new RuntimeException(
+                                               'TYPO3 Fatal Error: "' . $res,
+                                               1270853901
+                                       );
+                               }
                        } else {
                                        // Get content from cache:
                                $serContent = unserialize(self::getUrl($cacheFileName));
@@ -4542,7 +4560,10 @@ final class t3lib_div {
                                $xmlContent = self::xml2array($xmlString);
                                if (!is_array($xmlContent)) {
                                        $fileName = substr($fileRef, strlen(PATH_site));
-                                       die('The file "' . $fileName . '" is no TYPO3 language file!');
+                                       throw new RuntimeException(
+                                               'TYPO3 Fatal Error: The file "' . $fileName . '" is no TYPO3 language file!',
+                                               1270853902
+                                       );
                                }
 
                                        // Set default LOCAL_LANG array content:
@@ -4581,7 +4602,12 @@ final class t3lib_div {
                                        // Cache the content now:
                                $serContent = array('origFile'=>$hashSource, 'LOCAL_LANG'=>array('default'=>$LOCAL_LANG['default'], $langKey=>$LOCAL_LANG[$langKey]));
                                $res = self::writeFileToTypo3tempDir($cacheFileName, serialize($serContent));
-                               if ($res)       die('ERROR: '.$res);
+                               if ($res) {
+                                       throw new RuntimeException(
+                                               'TYPO3 Fatal Error: ' . $res,
+                                               1270853903
+                                       );
+                               }
                        } else {
                                        // Get content from cache:
                                $serContent = unserialize(self::getUrl($cacheFileName));
@@ -4609,7 +4635,10 @@ final class t3lib_div {
                                                $local_xmlContent = self::xml2array($local_xmlString);
                                                if (!is_array($local_xmlContent)) {
                                                        $fileName = substr($localized_file, strlen(PATH_site));
-                                                       die('The file "' . $fileName . '" is no TYPO3 language file!');
+                                                       throw new RuntimeException(
+                                                               'TYPO3 Fatal Error: The file "' . $fileName . '" is no TYPO3 language file!',
+                                                               1270853904
+                                                       );
                                                }
                                                $LOCAL_LANG[$langKey] = is_array($local_xmlContent['data'][$langKey]) ? $local_xmlContent['data'][$langKey] : array();
 
@@ -4624,7 +4653,10 @@ final class t3lib_div {
                                                $serContent = array('extlang'=>$langKey, 'origFile'=>$hashSource, 'EXT_DATA'=>$LOCAL_LANG[$langKey]);
                                                $res = self::writeFileToTypo3tempDir($cacheFileName, serialize($serContent));
                                                if ($res) {
-                                                       die('ERROR: '.$res);
+                                                       throw new RuntimeException(
+                                                               'TYPO3 Fatal Error: ' . $res,
+                                                               1270853905
+                                                       );
                                                }
                                        } else {
                                                        // Get content from cache:
index e629cb4..528954d 100644 (file)
@@ -131,7 +131,12 @@ final class t3lib_extMgm {
         */
        public static function isLoaded($key, $exitOnError = 0) {
                global $TYPO3_LOADED_EXT;
-               if ($exitOnError && !isset($TYPO3_LOADED_EXT[$key]))    die('Fatal Error: Extension "'.$key.'" was not loaded.');
+               if ($exitOnError && !isset($TYPO3_LOADED_EXT[$key])) {
+                       throw new BadFunctionCallException(
+                               'TYPO3 Fatal Error: Extension "' . $key . '" was not loaded!',
+                               1270853910
+                       );
+               }
                return isset($TYPO3_LOADED_EXT[$key]);
        }
 
@@ -148,8 +153,10 @@ final class t3lib_extMgm {
        public static function extPath($key, $script = '') {
                global $TYPO3_LOADED_EXT;
                if (!isset($TYPO3_LOADED_EXT[$key])) {
-                       #debug(array(debug_backtrace()));
-                       die('TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded! (t3lib_extMgm::extPath)');
+                       throw new BadFunctionCallException(
+                               'TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded!',
+                               1270853878
+                       );
                }
                return PATH_site.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$script;
        }
@@ -166,7 +173,10 @@ final class t3lib_extMgm {
        public static function extRelPath($key) {
                global $TYPO3_LOADED_EXT;
                if (!isset($TYPO3_LOADED_EXT[$key])) {
-                       die('TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded! (t3lib_extMgm::extRelPath)');
+                       throw new BadFunctionCallException(
+                               'TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded!',
+                               1270853879
+                       );
                }
                return $TYPO3_LOADED_EXT[$key]['typo3RelPath'];
        }
index 2b0e017..9c3c290 100644 (file)
@@ -203,7 +203,10 @@ class t3lib_extobjbase {
                        // Path of this script:
                $this->thisPath = dirname($conf['path']);
                if (!@is_dir($this->thisPath))  {
-                       die('Error: '.$this->thisPath.' was not a directory as expected...');
+                       throw new RuntimeException(
+                               'TYPO3 Fatal Error: Extension "' . $this->thisPath . ' was not a directory as expected...',
+                               1270853912
+                       );
                }
 
                        // Local lang:
index 6702b94..fd094cf 100644 (file)
@@ -208,11 +208,17 @@ class t3lib_install {
                $writeToLocalconf_dat['tmpfile'] = $writeToLocalconf_dat['file'].$tmpExt;
 
                        // Checking write state of localconf.php:
-               if (!$this->allowUpdateLocalConf)       {
-                       die('->allowUpdateLocalConf flag in the install object is not set and therefore "localconf.php" cannot be altered.');
+               if (!$this->allowUpdateLocalConf) {
+                       throw new RuntimeException(
+                               'TYPO3 Fatal Error: ->allowUpdateLocalConf flag in the install object is not set and therefore "localconf.php" cannot be altered.',
+                               1270853915
+                       );
                }
                if (!@is_writable($writeToLocalconf_dat['file']))       {
-                       die($writeToLocalconf_dat['file'].' is not writable!');
+                       throw new RuntimeException(
+                               'TYPO3 Fatal Error: ' . $writeToLocalconf_dat['file'] . ' is not writable!',
+                               1270853916
+                       );
                }
 
                                // Splitting localconf.php file into lines:
@@ -465,7 +471,12 @@ class t3lib_install {
                                                }
 
                                                $total[$table]['fields'][$fN] = $sqlParser->compileFieldCfg($fInfo);
-                                               if ($sqlParser->parse_error)    die($sqlParser->parse_error);
+                                               if ($sqlParser->parse_error) {
+                                                       throw new RuntimeException(
+                                                               'TYPO3 Fatal Error: ' . $sqlParser->parse_error,
+                                                               1270853961
+                                                       );
+                                               }
                                        }
                                }
                        }
index c094c35..d53ea4e 100644 (file)
@@ -2712,8 +2712,6 @@ class t3lib_TCEmain       {
                }
 
                $this->accumulateForNotifEmail = array();       // Reset notification array
-
-#              die("REMOVE ME");
        }
 
 
@@ -5713,7 +5711,12 @@ $this->log($table,$id,6,0,0,'Stage raised...',30,array('comment'=>$comment,'stag
                        $perms = intval($perms);
                }
 
-               if (!$perms)    {die('Internal ERROR: no permissions to check for non-admin user.');}
+               if (!$perms) {
+                       throw new RuntimeException(
+                               'Internal ERROR: no permissions to check for non-admin user',
+                               1270853920
+                       );
+               }
 
                        // For all tables: Check if record exists:
                if (is_array($TCA[$table]) && $id>0 && ($this->isRecordInWebMount($table,$id) || $this->admin)) {
@@ -7433,7 +7436,10 @@ State was change by %s (username: %s)
                                                        if (!preg_match('/[^[:alnum:]_]/',$tableName) && substr($tableName,-5)=='cache')        {
                                                                $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery($tableName);
                                                        } else {
-                                                               die('Fatal Error: Trying to flush table "'.$tableName.'" with "Clear All Cache"');
+                                                               throw new RuntimeException(
+                                                                       'TYPO3 Fatal Error: Trying to flush table "' . $tableName . '" with "Clear All Cache"',
+                                                                       1270853922
+                                                               );
                                                        }
                                                }
                                        }
index f45bf9d..ebdd54b 100644 (file)
@@ -485,9 +485,12 @@ class t3lib_userAuth {
                        if ($this->formfield_status && $loginData['uident'] && $loginData['uname'])     {
                                $httpHost = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY');
                                if (!$this->getMethodEnabled && ($httpHost!=$authInfo['refInfo']['host'] && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']))  {
-                                       die('Error: This host address ("'.$httpHost.'") and the referer host ("'.$authInfo['refInfo']['host'].'") mismatches!<br />
+                                       throw new RuntimeException(
+                                               'TYPO3 Fatal Error: Error: This host address ("' . $httpHost . '") and the referer host ("' . $authInfo['refInfo']['host'] . '") mismatches!<br />
                                                It\'s possible that the environment variable HTTP_REFERER is not passed to the script because of a proxy.<br />
-                                               The site administrator can disable this check in the "All Configuration" section of the Install Tool (flag: TYPO3_CONF_VARS[SYS][doNotCheckReferer]).');
+                                               The site administrator can disable this check in the "All Configuration" section of the Install Tool (flag: TYPO3_CONF_VARS[SYS][doNotCheckReferer]).',
+                                               1270853930
+                                       );
                                }
 
                                        // delete old user session if any
@@ -496,7 +499,10 @@ class t3lib_userAuth {
 
                                // Refuse login for _CLI users (used by commandline scripts)
                        if ((strtoupper(substr($loginData['uname'],0,5))=='_CLI_') && (!defined('TYPO3_cliMode') || !TYPO3_cliMode))    {       // although TYPO3_cliMode should never be set when using active login...
-                               die('Error: You have tried to login using a CLI user. Access prohibited!');
+                               throw new RuntimeException(
+                                       'TYPO3 Fatal Error: You have tried to login using a CLI user. Access prohibited!',
+                                       1270853931
+                               );
                        }
                }
 
@@ -874,12 +880,12 @@ class t3lib_userAuth {
         * if the client is flash (e.g. from a flash application inside TYPO3 that does a server request)
         * then don't evaluate with the hashLockClause, as the client/browser is included in this hash
         * and thus, the flash request would be rejected
-        * 
+        *
         * @return DB result object or false on error
         * @access private
         */
        protected function fetchUserSessionFromDB() {
-               
+
                if ($GLOBALS['CLIENT']['BROWSER'] == 'flash') {
                        // if on the flash client, the veri code is valid, then the user session is fetched
                        // from the DB without the hashLock clause
@@ -974,7 +980,7 @@ class t3lib_userAuth {
        public function veriCode() {
                return substr(md5($this->id . $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']), 0, 10);
        }
-       
+
        /**
         * This returns the where-clause needed to lock a user to a hash integer
         *
index e66d011..9a78485 100644 (file)
@@ -395,7 +395,9 @@ $typo_db_tables_script = '';        // The filename of the tables.php script in typo3co
 $typo_db_extTableDef_script = '';      // The filename of an additional script in typo3conf/-folder which is included after tables.php. Code in this script should modify the tables.php-configuration only, and this provides a good way to extend the standard-distributed tables.php file.
 
        // Include localconf.php. Use this file to configure TYPO3 for your needs and database
-if (!@is_file(PATH_typo3conf.'localconf.php')) die('localconf.php is not found!');
+if (!@is_file(PATH_typo3conf . 'localconf.php')) {
+       throw new Exception('localconf.php is not found!');
+}
 require(PATH_typo3conf.'localconf.php');
 
        // Defining the database setup as constants
index cf1b5f0..bbcdf00 100644 (file)
@@ -174,7 +174,10 @@ class SC_t3lib_thumbs {
                        $this->size = $size;
                        $this->mtime = $mtime;
                } else {
-                       die('Error: Image does not exist and/or MD5 checksum did not match.');
+                       throw new RuntimeException(
+                               'TYPO3 Fatal Error: Image does not exist and/or MD5 checksum did not match.',
+                               1270853950
+                       );
                }
        }
 
@@ -277,7 +280,12 @@ class SC_t3lib_thumbs {
        function errorGif($l1,$l2,$l3)  {
                global $TYPO3_CONF_VARS;
 
-               if (!$TYPO3_CONF_VARS['GFX']['gdlib'])  die($l1.' '.$l2.' '.$l3);
+               if (!$TYPO3_CONF_VARS['GFX']['gdlib']) {
+                       throw new RuntimeException(
+                               'TYPO3 Fatal Error: No gdlib. ' . $l1 . ' ' . $l2 . ' ' . $l3,
+                               1270853952
+                       );
+               }
 
                        // Creates the basis for the error image
                if ($TYPO3_CONF_VARS['GFX']['gdlib_png'])       {
@@ -329,7 +337,12 @@ class SC_t3lib_thumbs {
        function fontGif($font) {
                global $TYPO3_CONF_VARS;
 
-               if (!$TYPO3_CONF_VARS['GFX']['gdlib'])  die('');
+               if (!$TYPO3_CONF_VARS['GFX']['gdlib']) {
+                       throw new RuntimeException(
+                               'TYPO3 Fatal Error: No gdlib.',
+                               1270853953
+                       );
+               }
 
                        // Create image and set background color to white.
                $im = imageCreate(250,76);
index 9fb17a8..2c84b2e 100644 (file)
@@ -2321,7 +2321,12 @@ EXTENSION KEYS:
                                        Header('Content-Disposition: attachment; filename='.basename($dlFile));
                                        echo t3lib_div::getUrl($dlFile);
                                        exit;
-                               } else die($GLOBALS['LANG']->getLL('ext_details_error_downloading'));
+                               } else {
+                                       throw new RuntimeException(
+                                               'TYPO3 Fatal Error: ' . $GLOBALS['LANG']->getLL('ext_details_error_downloading'),
+                                               1270853980
+                                       );
+                               }
 
                        } elseif ($this->CMD['editFile'] && !in_array($extKey,$this->requiredExt))      {
 
@@ -2990,7 +2995,12 @@ EXTENSION KEYS:
                                $content = '<table border="0" cellpadding="2" cellspacing="2">'.implode('',$lines).'</table>';
                                return $content;
                        }
-               } else die($GLOBALS['LANG']->getLL('extBackup_unexpected_error'));
+               } else {
+                       throw new RuntimeException(
+                               'TYPO3 Fatal Error: ' . $GLOBALS['LANG']->getLL('extBackup_unexpected_error'),
+                               1270853981
+                       );
+       }
        }
 
        /**
@@ -5314,9 +5324,9 @@ $EM_CONF[$_EXTKEY] = '.$this->arrayToCode($EM_CONF, 0).';
                                                                        $finalDir = PATH_site.$crDirStart;
                                                                }
                                                        } else {
-                                                               die(sprintf($GLOBALS['LANG']->getLL('checkUploadFolder_error'),
-                                                                       PATH_site . $crDir
-                                                                       )
+                                                               throw new RuntimeException(
+                                                                       'TYPO3 Fatal Error: ' . sprintf($GLOBALS['LANG']->getLL('checkUploadFolder_error'), PATH_site . $crDir),
+                                                                       1270853982
                                                                );
                                                        }
                                                }
@@ -5692,7 +5702,10 @@ $EM_CONF[$_EXTKEY] = '.$this->arrayToCode($EM_CONF, 0).';
                                $header.LF.LF.LF.
                                $insertStatements.LF.LF.LF;
                        } else {
-                               die($GLOBALS['LANG']->getLL('dumpStaticTables_table_not_found'));
+                               throw new RuntimeException(
+                                       'TYPO3 Fatal Error: ' . $GLOBALS['LANG']->getLL('dumpStaticTables_table_not_found'),
+                                       1270853983
+                               );
                        }
                }
                return $out;
index 48eb0f3..02fd275 100644 (file)
@@ -123,9 +123,12 @@ class em_unzip {
 
                // Check the zlib
                if (!extension_loaded('zlib')) {
-                       die("The extension 'zlib' couldn't be found.\n".
-                       "Please make sure your version of PHP was built ".
-                       "with 'zlib' support.\n");
+                       throw new RuntimeException(
+                               'TYPO3 Fatal Error: ' . "The extension 'zlib' couldn't be found.\n" .
+                               "Please make sure your version of PHP was built " .
+                               "with 'zlib' support.\n",
+                               1270853984
+                       );
                }
 
                // Set the attributes