summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Rothstein2012-09-15 20:04:59 (GMT)
committer David Rothstein2012-09-15 20:04:59 (GMT)
commit02cf68de3308d7aa0aa4dc13a573a31f0ee7b34e (patch)
treef5c996dac787ad07f7bdb0e119f3a7407f941281
parentc987bbd4796a89552bc2576f6f0cc3fb96bcf702 (diff)
Issue #1739808 by Berdir, salvis | GrzegorzNowak: Fixed Notice: Undefined index: file in DatabaseLog->findCaller().
-rw-r--r--includes/database/log.inc10
-rw-r--r--modules/simpletest/tests/database_test.test7
2 files changed, 11 insertions, 6 deletions
diff --git a/includes/database/log.inc b/includes/database/log.inc
index ec27ef8..27eae62 100644
--- a/includes/database/log.inc
+++ b/includes/database/log.inc
@@ -128,9 +128,10 @@ class DatabaseLog {
* 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 includes/database. That makes the
- * climbing logic very simple, and handles the variable stack depth caused
- * by the query builders.
+ * the call stack that is not inside includes/database 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
@@ -144,7 +145,8 @@ class DatabaseLog {
$stack = debug_backtrace();
$stack_count = count($stack);
for ($i = 0; $i < $stack_count; ++$i) {
- if (strpos($stack[$i]['file'], 'includes' . DIRECTORY_SEPARATOR . 'database') === FALSE) {
+ if (!empty($stack[$i]['file']) && strpos($stack[$i]['file'], 'includes' . DIRECTORY_SEPARATOR . 'database') === FALSE) {
+ $stack[$i] += array('args' => array());
return array(
'file' => $stack[$i]['file'],
'line' => $stack[$i]['line'],
diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test
index 6608336..13e907c 100644
--- a/modules/simpletest/tests/database_test.test
+++ b/modules/simpletest/tests/database_test.test
@@ -2803,14 +2803,17 @@ class DatabaseLoggingTestCase extends DatabaseTestCase {
* 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.'));