/**
  * @return string
  */
 public static function getDebugTrail()
 {
     tx_rnbase::load('tx_rnbase_util_TYPO3');
     if (tx_rnbase_util_TYPO3::isTYPO62OrHigher()) {
         return \TYPO3\CMS\Core\Utility\DebugUtility::debugTrail();
     } else {
         return t3lib_utility_Debug::debugTrail();
     }
 }
 /**
  * Logs a call to a deprecated function.
  * The log message will be taken from the annotation.
  *
  * @return void
  */
 public static function logDeprecatedFunction()
 {
     if (!$GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog']) {
         return;
     }
     // This require_once is needed for deprecation calls
     // thrown early during bootstrap, if the autoloader is
     // not instantiated yet. This can happen for example if
     // ext_localconf triggers a deprecation.
     require_once 'DebugUtility.php';
     $trail = debug_backtrace();
     if ($trail[1]['type']) {
         $function = new \ReflectionMethod($trail[1]['class'], $trail[1]['function']);
     } else {
         $function = new \ReflectionFunction($trail[1]['function']);
     }
     $msg = '';
     if (preg_match('/@deprecated\\s+(.*)/', $function->getDocComment(), $match)) {
         $msg = $match[1];
     }
     // Write a longer message to the deprecation log: <function> <annotion> - <trace> (<source>)
     $logMsg = $trail[1]['class'] . $trail[1]['type'] . $trail[1]['function'];
     $logMsg .= '() - ' . $msg . ' - ' . \TYPO3\CMS\Core\Utility\DebugUtility::debugTrail();
     $logMsg .= ' (' . \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($function->getFileName()) . '#' . $function->getStartLine() . ')';
     self::deprecationLog($logMsg);
 }
Example #3
0
 /**
  * Logs a call to a deprecated function.
  * The log message will be taken from the annotation.
  *
  * @return void
  */
 public static function logDeprecatedFunction()
 {
     if (!$GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog']) {
         return;
     }
     $trail = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
     if ($trail[1]['type']) {
         $function = new \ReflectionMethod($trail[1]['class'], $trail[1]['function']);
     } else {
         $function = new \ReflectionFunction($trail[1]['function']);
     }
     $msg = '';
     if (preg_match('/@deprecated\\s+(.*)/', $function->getDocComment(), $match)) {
         $msg = $match[1];
     }
     // Write a longer message to the deprecation log: <function> <annotion> - <trace> (<source>)
     $logMsg = $trail[1]['class'] . $trail[1]['type'] . $trail[1]['function'];
     $logMsg .= '() - ' . $msg . ' - ' . DebugUtility::debugTrail();
     $logMsg .= ' (' . PathUtility::stripPathSitePrefix($function->getFileName()) . '#' . $function->getStartLine() . ')';
     self::deprecationLog($logMsg);
 }
 /**
  * Explain select queries
  * If $this->explainOutput is set, SELECT queries will be explained here. Only queries with more than one possible result row will be displayed.
  * The output is either printed as raw HTML output or embedded into the TS admin panel (checkbox must be enabled!)
  *
  * @todo Feature is not DBAL-compliant
  *
  * @param string $query SQL query
  * @param string $from_table Table(s) from which to select. This is what comes right after "FROM ...". Required value.
  * @param int $row_count Number of resulting rows
  * @return bool TRUE if explain was run, FALSE otherwise
  */
 protected function explain($query, $from_table, $row_count)
 {
     $debugAllowedForIp = GeneralUtility::cmpIP(GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask']);
     if ((int) $this->explainOutput == 1 || (int) $this->explainOutput == 2 && $debugAllowedForIp) {
         // Raw HTML output
         $explainMode = 1;
     } elseif ((int) $this->explainOutput == 3 && is_object($GLOBALS['TT'])) {
         // Embed the output into the TS admin panel
         $explainMode = 2;
     } else {
         return false;
     }
     $error = $this->sql_error();
     $trail = \TYPO3\CMS\Core\Utility\DebugUtility::debugTrail();
     $explain_tables = array();
     $explain_output = array();
     $res = $this->sql_query('EXPLAIN ' . $query, $this->link);
     if (is_a($res, '\\mysqli_result')) {
         while ($tempRow = $this->sql_fetch_assoc($res)) {
             $explain_output[] = $tempRow;
             $explain_tables[] = $tempRow['table'];
         }
         $this->sql_free_result($res);
     }
     $indices_output = array();
     // Notice: Rows are skipped if there is only one result, or if no conditions are set
     if ($explain_output[0]['rows'] > 1 || GeneralUtility::inList('ALL', $explain_output[0]['type'])) {
         // Only enable output if it's really useful
         $debug = true;
         foreach ($explain_tables as $table) {
             $tableRes = $this->sql_query('SHOW TABLE STATUS LIKE \'' . $table . '\'');
             $isTable = $this->sql_num_rows($tableRes);
             if ($isTable) {
                 $res = $this->sql_query('SHOW INDEX FROM ' . $table, $this->link);
                 if (is_a($res, '\\mysqli_result')) {
                     while ($tempRow = $this->sql_fetch_assoc($res)) {
                         $indices_output[] = $tempRow;
                     }
                     $this->sql_free_result($res);
                 }
             }
             $this->sql_free_result($tableRes);
         }
     } else {
         $debug = false;
     }
     if ($debug) {
         if ($explainMode) {
             $data = array();
             $data['query'] = $query;
             $data['trail'] = $trail;
             $data['row_count'] = $row_count;
             if ($error) {
                 $data['error'] = $error;
             }
             if (!empty($explain_output)) {
                 $data['explain'] = $explain_output;
             }
             if (!empty($indices_output)) {
                 $data['indices'] = $indices_output;
             }
             if ($explainMode == 1) {
                 \TYPO3\CMS\Core\Utility\DebugUtility::debug($data, 'Tables: ' . $from_table, 'DB SQL EXPLAIN');
             } elseif ($explainMode == 2) {
                 $GLOBALS['TT']->setTSselectQuery($data);
             }
         }
         return true;
     }
     return false;
 }
Example #5
0
 /**
  * Logs a call to a deprecated function.
  * The log message will be taken from the annotation.
  *
  * @return void
  */
 public static function logDeprecatedFunction()
 {
     if (!$GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog']) {
         return;
     }
     $trail = debug_backtrace();
     if ($trail[1]['type']) {
         $function = new \ReflectionMethod($trail[1]['class'], $trail[1]['function']);
     } else {
         $function = new \ReflectionFunction($trail[1]['function']);
     }
     $msg = '';
     if (preg_match('/@deprecated\\s+(.*)/', $function->getDocComment(), $match)) {
         $msg = $match[1];
     }
     // Trigger PHP error with a short message: <function> is deprecated (called from <source>, defined in <source>)
     $errorMsg = 'Function ' . $trail[1]['function'];
     if ($trail[1]['class']) {
         $errorMsg .= ' of class ' . $trail[1]['class'];
     }
     $errorMsg .= ' is deprecated (called from ' . $trail[1]['file'] . '#' . $trail[1]['line'] . ', defined in ' . $function->getFileName() . '#' . $function->getStartLine() . ')';
     // Write a longer message to the deprecation log: <function> <annotion> - <trace> (<source>)
     $logMsg = $trail[1]['class'] . $trail[1]['type'] . $trail[1]['function'];
     $logMsg .= '() - ' . $msg . ' - ' . \TYPO3\CMS\Core\Utility\DebugUtility::debugTrail();
     $logMsg .= ' (' . substr($function->getFileName(), strlen(PATH_site)) . '#' . $function->getStartLine() . ')';
     self::deprecationLog($logMsg);
 }