Issue #1739808 by Berdir, salvis: Fixed Notice: Undefined index: file in Drupal\Core\Database\Log->findCaller().
parent
316c1f4a7a
commit
a2215bf8b5
|
@ -130,12 +130,11 @@ class Log {
|
||||||
* Determine the routine that called this query.
|
* Determine the routine that called this query.
|
||||||
*
|
*
|
||||||
* We define "the routine that called this query" as the first entry in
|
* 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
|
* 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
|
* does not begin with db_ and does have a file (which excludes
|
||||||
* handles the variable stack depth caused by the query builders.
|
* call_user_func_array(), anonymous functions and similar). That makes the
|
||||||
*
|
* climbing logic very simple, and handles the variable stack depth caused by
|
||||||
* @todo Revisit this logic to not be dependent on file path, so that we can
|
* the query builders.
|
||||||
* split most of the DB layer out of Drupal.
|
|
||||||
*
|
*
|
||||||
* @link http://www.php.net/debug_backtrace
|
* @link http://www.php.net/debug_backtrace
|
||||||
* @return
|
* @return
|
||||||
|
@ -154,7 +153,8 @@ class Log {
|
||||||
if (empty($stack[$i]['class'])) {
|
if (empty($stack[$i]['class'])) {
|
||||||
$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(
|
return array(
|
||||||
'file' => $stack[$i]['file'],
|
'file' => $stack[$i]['file'],
|
||||||
'line' => $stack[$i]['line'],
|
'line' => $stack[$i]['line'],
|
||||||
|
|
|
@ -26,14 +26,17 @@ class LoggingTest extends DatabaseTestBase {
|
||||||
* Test that we can log the existence of a query.
|
* Test that we can log the existence of a query.
|
||||||
*/
|
*/
|
||||||
function testEnableLogging() {
|
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 name FROM {test} WHERE age > :age', array(':age' => 25))->fetchCol();
|
||||||
db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'))->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');
|
$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) {
|
foreach ($queries as $query) {
|
||||||
$this->assertEqual($query['caller']['function'], __FUNCTION__, t('Correct function in query log.'));
|
$this->assertEqual($query['caller']['function'], __FUNCTION__, t('Correct function in query log.'));
|
||||||
|
|
Loading…
Reference in New Issue