Issue #1784548 by btopro, Fabianx, Berdir, rbayliss, xaa: DB Log is missing watchdog table after enabling - Need to catch and ignore exceptions thrown in dblog_watchdog()
parent
8e69582fa3
commit
97aa5e1f6b
|
@ -1,6 +1,7 @@
|
|||
|
||||
Drupal 7.51, xxxx-xx-xx (development version)
|
||||
-----------------------
|
||||
- Exceptions thrown in dblog_watchdog() are now caught and ignored.
|
||||
- Numerous API documentation improvements.
|
||||
|
||||
Drupal 7.50, 2016-07-07
|
||||
|
|
|
@ -154,6 +154,15 @@ function dblog_update_7002() {
|
|||
db_add_index('watchdog', 'severity', array('severity'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Account for possible legacy systems where dblog was not installed.
|
||||
*/
|
||||
function dblog_update_7003() {
|
||||
if (!db_table_exists('watchdog')) {
|
||||
db_create_table('watchdog', drupal_get_schema_unprocessed('dblog', 'watchdog'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "addtogroup updates-7.x-extra".
|
||||
*/
|
||||
|
|
|
@ -147,20 +147,27 @@ function dblog_watchdog(array $log_entry) {
|
|||
if (!function_exists('drupal_substr')) {
|
||||
require_once DRUPAL_ROOT . '/includes/unicode.inc';
|
||||
}
|
||||
Database::getConnection('default', 'default')->insert('watchdog')
|
||||
->fields(array(
|
||||
'uid' => $log_entry['uid'],
|
||||
'type' => drupal_substr($log_entry['type'], 0, 64),
|
||||
'message' => $log_entry['message'],
|
||||
'variables' => serialize($log_entry['variables']),
|
||||
'severity' => $log_entry['severity'],
|
||||
'link' => drupal_substr($log_entry['link'], 0, 255),
|
||||
'location' => $log_entry['request_uri'],
|
||||
'referer' => $log_entry['referer'],
|
||||
'hostname' => drupal_substr($log_entry['ip'], 0, 128),
|
||||
'timestamp' => $log_entry['timestamp'],
|
||||
))
|
||||
->execute();
|
||||
try {
|
||||
Database::getConnection('default', 'default')->insert('watchdog')
|
||||
->fields(array(
|
||||
'uid' => $log_entry['uid'],
|
||||
'type' => drupal_substr($log_entry['type'], 0, 64),
|
||||
'message' => $log_entry['message'],
|
||||
'variables' => serialize($log_entry['variables']),
|
||||
'severity' => $log_entry['severity'],
|
||||
'link' => drupal_substr($log_entry['link'], 0, 255),
|
||||
'location' => $log_entry['request_uri'],
|
||||
'referer' => $log_entry['referer'],
|
||||
'hostname' => drupal_substr($log_entry['ip'], 0, 128),
|
||||
'timestamp' => $log_entry['timestamp'],
|
||||
))
|
||||
->execute();
|
||||
}
|
||||
catch (Exception $e) {
|
||||
// Exception is ignored so that watchdog does not break pages during the
|
||||
// installation process or is not able to create the watchdog table during
|
||||
// installation.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -520,6 +520,33 @@ class DBLogTestCase extends DrupalWebTestCase {
|
|||
$this->assertText(t('Database log cleared.'), 'Confirmation message found');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that exceptions are caught in dblog_watchdog().
|
||||
*/
|
||||
protected function testDBLogException() {
|
||||
$log = array(
|
||||
'type' => 'custom',
|
||||
'message' => 'Log entry added to test watchdog handling of Exceptions.',
|
||||
'variables' => array(),
|
||||
'severity' => WATCHDOG_NOTICE,
|
||||
'link' => NULL,
|
||||
'user' => $this->big_user,
|
||||
'uid' => isset($this->big_user->uid) ? $this->big_user->uid : 0,
|
||||
'request_uri' => request_uri(),
|
||||
'referer' => $_SERVER['HTTP_REFERER'],
|
||||
'ip' => ip_address(),
|
||||
'timestamp' => REQUEST_TIME,
|
||||
);
|
||||
|
||||
// Remove watchdog table temporarily to simulate it missing during
|
||||
// installation.
|
||||
db_query("DROP TABLE {watchdog}");
|
||||
|
||||
// Add a watchdog entry.
|
||||
// This should not throw an Exception, but fail silently.
|
||||
dblog_watchdog($log);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the database log event information from the browser page.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue