[BUGFIX] PHP warnings may show up in the List module
authorDmitry Dulepov <dmitry@typo3.org>
Thu, 24 Nov 2011 15:19:02 +0000 (17:19 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 30 Jul 2012 16:21:41 +0000 (18:21 +0200)
If the table is defined in $TCA but it misses "columns" array,
there will be a warning in the List module when searching for
any phrase. Implement a check that "columns" entry exists and
write a log message if it does not.

Change-Id: I0cba20e3b45ef78eb926042cc8ff09ea255c33ec
Resolves: #22152
Releases: 4.7, 4.6, 4.5
Reviewed-on: http://review.typo3.org/12824
Reviewed-by: Marcus Schwemer
Tested-by: Marcus Schwemer
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/class.db_list.inc

index 9335fd2..72c3a9f 100644 (file)
@@ -767,38 +767,55 @@ class recordList extends t3lib_recordList {
                if (is_array($TCA[$table]))     {
                        t3lib_div::loadTCA($table);
 
-                               // Traverse configured columns and add them to field array, if available for user.
-                       foreach($TCA[$table]['columns'] as $fN => $fieldValue)  {
-                               if ($dontCheckUser ||
-                                       ((!$fieldValue['exclude'] || $BE_USER->check('non_exclude_fields',$table.':'.$fN)) && $fieldValue['config']['type']!='passthrough'))    {
-                                       $fieldListArr[]=$fN;
+                       if (isset($GLOBALS['TCA'][$table]['columns']) && is_array($GLOBALS['TCA'][$table]['columns'])) {
+                                       // Traverse configured columns and add them to field array, if available for user.
+                               foreach ($GLOBALS['TCA'][$table]['columns'] as $fN => $fieldValue) {
+                                       if ($dontCheckUser ||
+                                                       ((!$fieldValue['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', $table . ':' . $fN))
+                                                                       && $fieldValue['config']['type']!='passthrough')) {
+                                               $fieldListArr[]=$fN;
+                                       }
                                }
-                       }
 
-                               // Add special fields:
-                       if ($dontCheckUser || $BE_USER->isAdmin())      {
-                               $fieldListArr[]='uid';
-                               $fieldListArr[]='pid';
-                       }
+                                       // Add special fields:
+                               if ($dontCheckUser || $GLOBALS['BE_USER']->isAdmin()) {
+                                       $fieldListArr[]='uid';
+                                       $fieldListArr[]='pid';
+                               }
 
-                               // Add date fields
-                       if ($dontCheckUser || $BE_USER->isAdmin() || $addDateFields)    {
-                               if ($TCA[$table]['ctrl']['tstamp'])     $fieldListArr[]=$TCA[$table]['ctrl']['tstamp'];
-                               if ($TCA[$table]['ctrl']['crdate'])     $fieldListArr[]=$TCA[$table]['ctrl']['crdate'];
-                       }
+                                       // Add date fields
+                               if ($dontCheckUser || $GLOBALS['BE_USER']->isAdmin() || $addDateFields) {
+                                       if ($GLOBALS['TCA'][$table]['ctrl']['tstamp']) {
+                                               $fieldListArr[]=$GLOBALS['TCA'][$table]['ctrl']['tstamp'];
+                                       }
+                                       if ($GLOBALS['TCA'][$table]['ctrl']['crdate']) {
+                                               $fieldListArr[]=$GLOBALS['TCA'][$table]['ctrl']['crdate'];
+                                       }
+                               }
 
-                               // Add more special fields:
-                       if ($dontCheckUser || $BE_USER->isAdmin())      {
-                               if ($TCA[$table]['ctrl']['cruser_id'])  $fieldListArr[]=$TCA[$table]['ctrl']['cruser_id'];
-                               if ($TCA[$table]['ctrl']['sortby'])     $fieldListArr[]=$TCA[$table]['ctrl']['sortby'];
-                               if ($TCA[$table]['ctrl']['versioningWS'])       {
-                                       $fieldListArr[]='t3ver_id';
-                                       $fieldListArr[]='t3ver_state';
-                                       $fieldListArr[]='t3ver_wsid';
-                                       if ($table==='pages')   {
-                                               $fieldListArr[]='t3ver_swapmode';
+                                       // Add more special fields:
+                               if ($dontCheckUser || $GLOBALS['BE_USER']->isAdmin()) {
+                                       if ($GLOBALS['TCA'][$table]['ctrl']['cruser_id']) {
+                                               $fieldListArr[]=$GLOBALS['TCA'][$table]['ctrl']['cruser_id'];
+                                       }
+                                       if ($GLOBALS['TCA'][$table]['ctrl']['sortby']) {
+                                               $fieldListArr[]=$GLOBALS['TCA'][$table]['ctrl']['sortby'];
+                                       }
+                                       if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
+                                               $fieldListArr[]='t3ver_id';
+                                               $fieldListArr[]='t3ver_state';
+                                               $fieldListArr[]='t3ver_wsid';
+                                               if ($table==='pages') {
+                                                       $fieldListArr[]='t3ver_swapmode';
+                                               }
                                        }
                                }
+                       } else {
+                               t3lib_div::sysLog(
+                                       sprintf('$TCA is broken for the table "%s": no required "columns" entry in $TCA.', $table),
+                                       'core',
+                                       t3lib_div::SYSLOG_SEVERITY_ERROR
+                               );
                        }
                }
                return $fieldListArr;
@@ -863,4 +880,4 @@ if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLA
        include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/class.db_list.inc']);
 }
 
-?>
\ No newline at end of file
+?>