diff --git a/src/Plugin/monitoring/SensorPlugin/DatabaseAggregatorSensorPlugin.php b/src/Plugin/monitoring/SensorPlugin/DatabaseAggregatorSensorPlugin.php index 6746f51..09c7a5e 100644 --- a/src/Plugin/monitoring/SensorPlugin/DatabaseAggregatorSensorPlugin.php +++ b/src/Plugin/monitoring/SensorPlugin/DatabaseAggregatorSensorPlugin.php @@ -443,7 +443,7 @@ class DatabaseAggregatorSensorPlugin extends DatabaseAggregatorSensorPluginBase // Update the verbose output fields. $settings['verbose_fields'] = []; - foreach ($form_state->getValue('verbose_fields') as $field) { + foreach ($form_state->getValue('verbose_fields', []) as $field) { if (!empty($field['field_key'])) { $settings['verbose_fields'][] = $field['field_key']; } @@ -544,6 +544,23 @@ class DatabaseAggregatorSensorPlugin extends DatabaseAggregatorSensorPluginBase t('The specified time interval field %name does not exist in table %table.', array('%name' => $field_name, '%table' => $table))); } } + + // Validate verbose_fields. + $fields = $form_state->getValue('verbose_fields'); + foreach ($fields as $key => $field) { + $query = $database->select($table); + $field_name = $field['field_key']; + if (!empty($field_name) && !$database->schema()->fieldExists($table, $field_name)) { + $query->addField($table, $field_name); + try { + $query->range(0, 1)->execute(); + } + catch (\Exception $e) { + $form_state->setErrorByName("verbose_fields][$key][field_key", t('The field %field does not exist in the table "%table".', ['%field' => $field_name, '%table' => $table])); + continue; + } + } + } } } diff --git a/src/Plugin/monitoring/SensorPlugin/PhpNoticesSensorPlugin.php b/src/Plugin/monitoring/SensorPlugin/PhpNoticesSensorPlugin.php index a9c60a5..c7075e9 100644 --- a/src/Plugin/monitoring/SensorPlugin/PhpNoticesSensorPlugin.php +++ b/src/Plugin/monitoring/SensorPlugin/PhpNoticesSensorPlugin.php @@ -10,6 +10,7 @@ use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\Xss; use Drupal\Core\Form\FormStateInterface; use Drupal\monitoring\Result\SensorResultInterface; +use Drupal\monitoring\SensorPlugin\DatabaseAggregatorSensorPluginBase; /** * Displays the most frequent PHP notices and errors. @@ -122,4 +123,11 @@ class PhpNoticesSensorPlugin extends WatchdogAggregatorSensorPlugin { return str_replace(DRUPAL_ROOT . '/', '', $filename); } + /** + * {@inheritdoc} + */ + public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { + } + + } diff --git a/src/Tests/MonitoringCoreWebTest.php b/src/Tests/MonitoringCoreWebTest.php index bd1d825..86ebb6a 100644 --- a/src/Tests/MonitoringCoreWebTest.php +++ b/src/Tests/MonitoringCoreWebTest.php @@ -63,9 +63,6 @@ class MonitoringCoreWebTest extends MonitoringTestBase { $message = (string) $xpath[0]->td[1]; $this->assertTrue($wid == 14, 'Found WID in verbose output'); $this->assertTrue($message == 'Session opened for %name.', 'Found unreplaced message in output.'); - // Test field validation. - $this->drupalPostForm('admin/config/system/monitoring/sensors/user_successful_logins', ['verbose_fields[2][field_key]' => 'horstname'], t('Save')); - $this->assertText('The field horstname does not exist in the table "watchdog".'); } /** @@ -247,7 +244,6 @@ class MonitoringCoreWebTest extends MonitoringTestBase { // Check out sensor result page. $this->drupalPostForm('/admin/reports/monitoring/sensors/dblog_php_notices', [], t('Run now')); $xpath = $this->xpath('//table[@id="edit-result"]'); - debug($xpath); $header = (array) $xpath[0]->thead->tr->th; $body = (array) $xpath[0]->tbody; $this->assertEqual($expected_header, $header, 'The header is correct.');