Skip to content
Snippets Groups Projects
Commit a2215bf8 authored by Angie Byron's avatar Angie Byron
Browse files

Issue #1739808 by Berdir, salvis: Fixed Notice: Undefined index: file in...

Issue #1739808 by Berdir, salvis: Fixed Notice: Undefined index: file in Drupal\Core\Database\Log->findCaller().
parent 316c1f4a
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -130,12 +130,11 @@ public function log(StatementInterface $statement, $args, $time) {
* Determine the routine that called this query.
*
* We define "the routine that called this query" as the first entry in
* the call stack that is not inside the includes/Drupal/Database directory
* and does not begin with db_. That makes the climbing logic very simple, and
* handles the variable stack depth caused by the query builders.
*
* @todo Revisit this logic to not be dependent on file path, so that we can
* split most of the DB layer out of Drupal.
* the call stack that is not inside the includes/Drupal/Database directory,
* does not begin with db_ and does have a file (which excludes
* call_user_func_array(), anonymous functions and similar). That makes the
* climbing logic very simple, and handles the variable stack depth caused by
* the query builders.
*
* @link http://www.php.net/debug_backtrace
* @return
......@@ -154,7 +153,8 @@ public function findCaller() {
if (empty($stack[$i]['class'])) {
$stack[$i]['class'] = '';
}
if (strpos($stack[$i]['class'], __NAMESPACE__) === FALSE && strpos($stack[$i + 1]['function'], 'db_') === FALSE) {
if (strpos($stack[$i]['class'], __NAMESPACE__) === FALSE && strpos($stack[$i + 1]['function'], 'db_') === FALSE && !empty($stack[$i]['file'])) {
$stack[$i] += array('file' => '?', 'line' => '?', 'args' => array());
return array(
'file' => $stack[$i]['file'],
'line' => $stack[$i]['line'],
......
......@@ -26,14 +26,17 @@ public static function getInfo() {
* Test that we can log the existence of a query.
*/
function testEnableLogging() {
Database::startLog('testing');
$log = Database::startLog('testing');
db_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25))->fetchCol();
db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'))->fetchCol();
// Trigger a call that does not have file in the backtrace.
call_user_func_array('db_query', array('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo')))->fetchCol();
$queries = Database::getLog('testing', 'default');
$this->assertEqual(count($queries), 2, t('Correct number of queries recorded.'));
$this->assertEqual(count($queries), 3, t('Correct number of queries recorded.'));
foreach ($queries as $query) {
$this->assertEqual($query['caller']['function'], __FUNCTION__, t('Correct function in query log.'));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment