Comments

miro_dietiker’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev

Let's start with this in D8 first.
It should be pretty easy to extend the output and allow the configuration of exclude keys.
Recently, we started to disable requirements sensors for modules due to some unwanted escalation.

Anushka-mp’s picture

Status: Active » Needs review
StatusFileSize
new2.24 KB

Text field added to configure the keys to be excluded. and the keys are displayed in the verbose message.

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/src/Plugin/monitoring/SensorPlugin/CoreRequirementsSensorPlugin.php
    @@ -38,17 +38,28 @@ class CoreRequirementsSensorPlugin extends SensorPluginBase {
    -  public function runSensor(SensorResultInterface $result) {
    -    $requirements = $this->getRequirements($this->sensorConfig->getSetting('module'));
    +  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    +    $form = parent::buildConfigurationForm($form, $form_state);
    

    Can you add the new buildConfigurationForm() method below runSensor() ? This makes it harder to review.

  2. +++ b/src/Plugin/monitoring/SensorPlugin/CoreRequirementsSensorPlugin.php
    @@ -38,17 +38,28 @@ class CoreRequirementsSensorPlugin extends SensorPluginBase {
    +      '#description' => t('Seperate the keys by a semicolan (;)'),
    

    That thing is called semicolon, not colan :)

  3. +++ b/src/Plugin/monitoring/SensorPlugin/CoreRequirementsSensorPlugin.php
    @@ -38,17 +38,28 @@ class CoreRequirementsSensorPlugin extends SensorPluginBase {
    +    if (!$this->sensorConfig->isNew()) {
    +      $form['exclude_keys']['#default_value']  = implode(';', $this->sensorConfig->getSetting('exclude_keys'));
         }
    

    Is the is new check necessary because it is not yet an array then? Maybe do an (array) cast instead?

  4. +++ b/src/Plugin/monitoring/SensorPlugin/CoreRequirementsSensorPlugin.php
    @@ -152,4 +163,17 @@ class CoreRequirementsSensorPlugin extends SensorPluginBase {
    +
    +  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    

    Missing docblock.

  5. +++ b/src/Plugin/monitoring/SensorPlugin/CoreRequirementsSensorPlugin.php
    @@ -152,4 +163,17 @@ class CoreRequirementsSensorPlugin extends SensorPluginBase {
    +    foreach ($keys as $key) {
    +      $key = trim($key);
    +      $exclude_keys[$key] = $key;
    +    }
    +    $this->sensorConfig->settings['exclude_keys'] = $exclude_keys;
    

    You can do this with $keys = array_map('trim', $keys), the current code also doesn't define $exclude_keys, so it could be undefined.

    Also make sure that we are not saving an empty string here, "var_dump(explode(';', '')); returns an array with an empty string inside. So run array_filter() around it.

miro_dietiker’s picture

I do prefer to switch to textarea and split by newline. This is common with Drupal pattern matching.

Plus... did i mention that test coverage is missing... ;-)

Anushka-mp’s picture

Changes made according to above suggestions, tests are pending.

Status: Needs review » Needs work
miro_dietiker’s picture

  1. +++ b/src/Plugin/monitoring/SensorPlugin/CoreRequirementsSensorPlugin.php
    @@ -40,17 +40,30 @@ class CoreRequirementsSensorPlugin extends SensorPluginBase {
    +    $result->setMessage('Excluded keys : ' . implode(', ', $this->sensorConfig->getSetting('exclude_keys')));
    

    This is not relevant for the regular message. Only add the key to the verbose output.

  2. +++ b/src/Plugin/monitoring/SensorPlugin/CoreRequirementsSensorPlugin.php
    @@ -40,17 +40,30 @@ class CoreRequirementsSensorPlugin extends SensorPluginBase {
    -    // Ignore requirements that were explicitly excluded.
    -    foreach ($this->sensorConfig->getSetting('exclude keys', array()) as $exclude_key) {
    -      if (isset($requirements[$exclude_key])) {
    -        unset($requirements[$exclude_key]);
    -      }
    -    }
    

    You dropped the functionality of exclude with this patch...

  3. +++ b/src/Plugin/monitoring/SensorPlugin/CoreRequirementsSensorPlugin.php
    @@ -40,17 +40,30 @@ class CoreRequirementsSensorPlugin extends SensorPluginBase {
    +    if (!$this->sensorConfig->isNew()) {
    

    Check for getSetting('exclude_keys') instead.

Anushka-mp’s picture

Verbose message and the functionality added.
failing tests are corrected.
working on creating new tests for these changes.

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/src/Plugin/monitoring/SensorPlugin/CoreRequirementsSensorPlugin.php
    @@ -38,11 +39,29 @@ class CoreRequirementsSensorPlugin extends SensorPluginBase {
    +    $output['query'] = array(
    +      '#type' => 'item',
    +      '#title' => t('Excluded keys'),
    +      '#markup' => '<pre>' . $excluded_keys . '</pre>',
    +    );
    

    Should be 'exclude_keys' instead of query.

    Also, try making this a list instead now that we can return HTML and render arrays. #type item_list, and then #items as array of string.

  2. +++ b/src/Plugin/monitoring/SensorPlugin/CoreRequirementsSensorPlugin.php
    @@ -152,4 +191,14 @@ class CoreRequirementsSensorPlugin extends SensorPluginBase {
    +    $keys = array_filter(explode("\n", $form_state->getValue(array('settings', 'exclude_keys'))));
    +    $this->sensorConfig->settings['exclude_keys'] = $keys;
    

    I think we still need the trim part here, between explode and array_filter.

miro_dietiker’s picture

Note that the b) from the original issue summary is not started yet.
We need verbose output that shows the key. Otherwise a user never knows what key to exclude.

Anushka-mp’s picture

Table added for verbose output,
tests are also here with this patch.

Status: Needs review » Needs work

Status: Needs work » Needs review

Status: Needs review » Needs work
Anushka-mp’s picture

Core test failure fixed.

miro_dietiker’s picture

Nice verbose improvement.

Reworked the patch a bit, adding more comments.
Improved tests to check more verbose output in core tests.
Switched style for test checks after setRawContent to use assertText. Makes it much more readable.

Will commit when green. :-)

  • miro_dietiker committed dea6420 on 8.x-1.x
    Issue #2189265 by Anushka-mp, miro_dietiker: UI and better (verbose)...
miro_dietiker’s picture

Status: Needs review » Fixed

Awesome. Committed, pushed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.