From 17e2eefbbba082c2e660414f7a0c3710bc18c635 Mon Sep 17 00:00:00 2001 From: Nathanael Dewhurst Date: Sat, 25 Jan 2014 14:40:10 -0500 Subject: [PATCH] Issue #733054 by mkalkbrenner, ndewhurst: Making watchdog logging of searches a configurable option --- core/modules/search/config/schema/search.schema.yml | 7 +++++++ core/modules/search/config/search.settings.yml | 2 ++ .../lib/Drupal/search/Controller/SearchController.php | 6 ++++-- .../lib/Drupal/search/SearchPageListController.php | 16 ++++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/core/modules/search/config/schema/search.schema.yml b/core/modules/search/config/schema/search.schema.yml index 68e6877..3a76f10 100644 --- a/core/modules/search/config/schema/search.schema.yml +++ b/core/modules/search/config/schema/search.schema.yml @@ -10,6 +10,13 @@ search.settings: default_page: type: string label: 'Default search page' + logging: + type: mapping + label: 'Logging settings' + mapping: + log_searches_to_watchdog: + type: boolean + label: 'Log searches to watchdog' index: type: mapping label: 'Indexing settings' diff --git a/core/modules/search/config/search.settings.yml b/core/modules/search/config/search.settings.yml index 09c09cb..6404eee 100644 --- a/core/modules/search/config/search.settings.yml +++ b/core/modules/search/config/search.settings.yml @@ -1,5 +1,7 @@ and_or_limit: 7 default_page: node_search +logging: + log_searches_to_watchdog: true index: cron_limit: 100 overlap_cjk: true diff --git a/core/modules/search/lib/Drupal/search/Controller/SearchController.php b/core/modules/search/lib/Drupal/search/Controller/SearchController.php index 83ca3b5..574c5fe 100644 --- a/core/modules/search/lib/Drupal/search/Controller/SearchController.php +++ b/core/modules/search/lib/Drupal/search/Controller/SearchController.php @@ -80,8 +80,10 @@ public function view(Request $request, SearchPageInterface $entity, $keys = '') if ($request->request->has('form_id') || $request->request->get('form_id') != 'search_form') { // Only search if there are keywords or non-empty conditions. if ($plugin->isSearchExecutable()) { - // Log the search keys. - watchdog('search', 'Searched %type for %keys.', array('%keys' => $keys, '%type' => $entity->label()), WATCHDOG_NOTICE, $this->l(t('results'), 'search.view_' . $entity->id(), array('keys' => $keys))); + // Log the search keys if this option has been enabled. + if (\Drupal::config('search.settings')->get('logging.log_searches_to_watchdog')) { + watchdog('search', 'Searched %type for %keys.', array('%keys' => $keys, '%type' => $entity->label()), WATCHDOG_NOTICE, $this->l(t('results'), 'search.view_' . $entity->id(), array('keys' => $keys))); + } // Collect the search results. $results = $plugin->buildResults(); diff --git a/core/modules/search/lib/Drupal/search/SearchPageListController.php b/core/modules/search/lib/Drupal/search/SearchPageListController.php index e7a7d8b..90b8619 100644 --- a/core/modules/search/lib/Drupal/search/SearchPageListController.php +++ b/core/modules/search/lib/Drupal/search/SearchPageListController.php @@ -235,6 +235,18 @@ public function buildForm(array $form, array &$form_state) { '#limit_validation_errors' => array(array('search_type')), ); + // Logging settings: + $form['logging'] = array( + '#type' => 'details', + '#title' => $this->t('Logging') + ); + $form['logging']['log_searches_to_watchdog'] = array( + '#type' => 'checkbox', + '#title' => $this->t('Log searches to watchdog'), + '#default_value' => $search_settings->get('logging.log_searches_to_watchdog'), + '#description' => $this->t('If checked, all searches will be logged to watchdog. If you are using Drupal\'s standard database logging, this will allow you to view a record of each search via the "Recent log messages" report, but it will also increase the database size and the number of database interactions.') + ); + // Move the listing into the search_pages element. $form['search_pages'][$this->entitiesKey] = $form[$this->entitiesKey]; $form['search_pages'][$this->entitiesKey]['#empty'] = $this->t('No search pages have been configured.'); @@ -300,6 +312,10 @@ public function submitForm(array &$form, array &$form_state) { ->set('index.cron_limit', $form_state['values']['cron_limit']) ->save(); + $search_settings + ->set('logging.log_searches_to_watchdog', $form_state['values']['log_searches_to_watchdog']) + ->save(); + drupal_set_message($this->t('The configuration options have been saved.')); } -- 1.8.3.4 (Apple Git-47)