123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- <?php
- use Drupal\Core\Form\FormStateInterface;
- use Drupal\Core\Routing\RouteMatchInterface;
- use Drupal\Core\StringTranslation\TranslatableMarkup;
- use Drupal\views\ViewEntityInterface;
- use Drupal\views\ViewExecutable;
- function dblog_help($route_name, RouteMatchInterface $route_match) {
- switch ($route_name) {
- case 'help.page.dblog':
- $output = '';
- $output .= '<h3>' . t('About') . '</h3>';
- $output .= '<p>' . t('The Database Logging module logs system events in the Drupal database. For more information, see the <a href=":dblog">online documentation for the Database Logging module</a>.', [':dblog' => 'https://www.drupal.org/documentation/modules/dblog']) . '</p>';
- $output .= '<h3>' . t('Uses') . '</h3>';
- $output .= '<dl>';
- $output .= '<dt>' . t('Monitoring your site') . '</dt>';
- $output .= '<dd>' . t('The Database Logging module allows you to view an event log on the <a href=":dblog">Recent log messages</a> page. The log is a chronological list of recorded events containing usage data, performance data, errors, warnings and operational information. Administrators should check the log on a regular basis to ensure their site is working properly.', [':dblog' => \Drupal::url('dblog.overview')]) . '</dd>';
- $output .= '<dt>' . t('Debugging site problems') . '</dt>';
- $output .= '<dd>' . t('In case of errors or problems with the site, the <a href=":dblog">Recent log messages</a> page can be useful for debugging, since it shows the sequence of events. The log messages include usage information, warnings, and errors.', [':dblog' => \Drupal::url('dblog.overview')]) . '</dd>';
- $output .= '</dl>';
- return $output;
- case 'dblog.overview':
- return '<p>' . t('The Database Logging module logs system events in the Drupal database. Monitor your site or debug site problems on this page.') . '</p>';
- }
- }
- function dblog_menu_links_discovered_alter(&$links) {
- if (\Drupal::moduleHandler()->moduleExists('search')) {
- $links['dblog.search'] = [
- 'title' => new TranslatableMarkup('Top search phrases'),
- 'route_name' => 'dblog.search',
- 'description' => new TranslatableMarkup('View most popular search phrases.'),
- 'parent' => 'system.admin_reports',
- ];
- }
- return $links;
- }
- function dblog_cron() {
-
- $row_limit = \Drupal::config('dblog.settings')->get('row_limit');
-
-
-
- if ($row_limit > 0) {
- $min_row = db_select('watchdog', 'w')
- ->fields('w', ['wid'])
- ->orderBy('wid', 'DESC')
- ->range($row_limit - 1, 1)
- ->execute()->fetchField();
-
- if ($min_row) {
- db_delete('watchdog')
- ->condition('wid', $min_row, '<')
- ->execute();
- }
- }
- }
- function _dblog_get_message_types() {
- return db_query('SELECT DISTINCT(type) FROM {watchdog} ORDER BY type')
- ->fetchAllKeyed(0, 0);
- }
- function dblog_form_system_logging_settings_alter(&$form, FormStateInterface $form_state) {
- $row_limits = [100, 1000, 10000, 100000, 1000000];
- $form['dblog_row_limit'] = [
- '#type' => 'select',
- '#title' => t('Database log messages to keep'),
- '#default_value' => \Drupal::configFactory()->getEditable('dblog.settings')->get('row_limit'),
- '#options' => [0 => t('All')] + array_combine($row_limits, $row_limits),
- '#description' => t('The maximum number of messages to keep in the database log. Requires a <a href=":cron">cron maintenance task</a>.', [':cron' => \Drupal::url('system.status')])
- ];
- $form['#submit'][] = 'dblog_logging_settings_submit';
- }
- function dblog_logging_settings_submit($form, FormStateInterface $form_state) {
- \Drupal::configFactory()->getEditable('dblog.settings')->set('row_limit', $form_state->getValue('dblog_row_limit'))->save();
- }
- function dblog_view_presave(ViewEntityInterface $view) {
-
- if ($view->get('base_table') != 'watchdog') {
- return;
- }
- $displays = $view->get('display');
- $update = FALSE;
- foreach ($displays as $display_name => $display) {
-
- if (isset($display['display_options']['fields'])) {
- foreach ($display['display_options']['fields'] as $field_name => $field) {
-
-
- if (isset($field['table']) &&
- $field['table'] === 'watchdog' &&
- $field['plugin_id'] == 'numeric' &&
- in_array($field['field'], ['wid', 'uid'], TRUE)) {
- $displays[$display_name]['display_options']['fields'][$field_name]['plugin_id'] = 'standard';
-
- unset(
- $displays[$display_name]['display_options']['fields'][$field_name]['set_precision'],
- $displays[$display_name]['display_options']['fields'][$field_name]['precision'],
- $displays[$display_name]['display_options']['fields'][$field_name]['decimal'],
- $displays[$display_name]['display_options']['fields'][$field_name]['separator'],
- $displays[$display_name]['display_options']['fields'][$field_name]['format_plural'],
- $displays[$display_name]['display_options']['fields'][$field_name]['format_plural_string'],
- $displays[$display_name]['display_options']['fields'][$field_name]['prefix'],
- $displays[$display_name]['display_options']['fields'][$field_name]['suffix']
- );
- $update = TRUE;
- @trigger_error("The numeric plugin for watchdog.$field_name field is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Must use standard plugin instead. See https://www.drupal.org/node/2876378.", E_USER_DEPRECATED);
- }
- }
- }
-
- if (isset($display['display_options']['filters'])) {
- foreach ($display['display_options']['filters'] as $filter_name => $filter) {
- if (isset($filter['table']) &&
- $filter['table'] === 'watchdog' &&
- $filter['plugin_id'] == 'in_operator' &&
- $filter['field'] == 'type') {
- $displays[$display_name]['display_options']['filters'][$filter_name]['plugin_id'] = 'dblog_types';
- $update = TRUE;
- @trigger_error("The in_operator plugin for watchdog.type filter is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Must use dblog_types plugin instead. See https://www.drupal.org/node/2876378.", E_USER_DEPRECATED);
- }
- }
- }
- }
- if ($update) {
- $view->set('display', $displays);
- }
- }
- function dblog_views_pre_render(ViewExecutable $view) {
- if (isset($view) && ($view->storage->get('base_table') == 'watchdog')) {
- $view->element['#attached']['library'][] = 'dblog/drupal.dblog';
- }
- }
|