Problem/Motivation

If ImapDeliverer cannot connect, or the IMAP PHP extension is not installed, then it should produce an error when it is run.

Proposed resolution

Remaining tasks

User interface changes

API changes

CommentFileSizeAuthor
#60 interdiff-2405757-57-60.txt1.51 KBtoncic
#60 report_error_if-2405757-60.patch6.07 KBtoncic
#57 interdiff-2405757-55-57.txt751 bytestoncic
#57 report_error_if-2405757-57.patch6.13 KBtoncic
#55 interdiff-2405757-53-55.txt3.05 KBtoncic
#55 report_error_if-2405757-55.patch6.19 KBtoncic
#53 interdiff-2405757-49-53.txt777 bytestoncic
#53 report_error_if-2405757-53.patch5.71 KBtoncic
#49 interdiff-2405757-46-49.txt1.95 KBtoncic
#49 report_error_if-2405757-49.patch5.59 KBtoncic
#46 interdiff-2405757-44-46.txt1.5 KBtoncic
#46 report_error_if-2405757-46.patch5.61 KBtoncic
#44 interdiff-2405757-42-44.txt1.81 KBtoncic
#44 report_error_if-2405757-44.patch5.83 KBtoncic
#42 interdiff-2405757-39-42.txt4.11 KBtoncic
#42 report_error_if-2405757-42.patch5.8 KBtoncic
#39 interdiff-2405757-34-39.txt0 bytestoncic
#39 report_error_if-2405757-39.patch6.1 KBtoncic
#37 report_error_if-2405757-34.patch5.73 KBtoncic
#35 report_error_if-2405757-34.patch5.73 KBtoncic
#34 interdiff-2405757-31-34.txt2.67 KBtoncic
#31 interdiff-2405757-25-29.txt1.72 KBtoncic
#31 report_error_if-2405757-29.patch4.63 KBtoncic
#26 interdiff-2405757-24-26.txt1.96 KBtoncic
#26 report_error_if-2405757-26.patch4.55 KBtoncic
#24 interdiff-2405757-22-24.txt3.19 KBtoncic
#24 report_error_if-2405757-24.patch4.6 KBtoncic
#23 Screenshot from 2016-08-26 12-29-48.png9.08 KBmiro_dietiker
#22 interdiff-2405757-20-22.txt3.05 KBtoncic
#22 report_error_if-2405757-22.patch4.65 KBtoncic
#20 interdiff-2405757-18-20.txt4.94 KBtoncic
#20 report_error_if-2405757-20.patch4.55 KBtoncic
#18 interdiff-2405757-16-18.txt1.01 KBtoncic
#18 report_error_if-2405757-18.patch2.37 KBtoncic
#16 interdiff-2405757-12-16.txt1001 bytestoncic
#16 report_error_if-2405757-16.patch2.32 KBtoncic
#12 interdiff-2405757-8-10.txt2.81 KBtoncic
#12 report_error_if-2405757-10.patch2.41 KBtoncic
#10 interdiff-2405757-8-10.txt2.81 KBtoncic
#10 report_error_if-2405757-10.patch2.41 KBtoncic
#8 interdiff-2405757-6-8.txt1.12 KBtoncic
#8 report_error_if-2405757-8.patch1.52 KBtoncic
#6 report_error_if-2405757-6.patch1.11 KBtoncic
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

miro_dietiker’s picture

If the IMAP extension is missing, the system currently fails with a fatal error. Uncool.
Running the fetcher should output a message about the missing PHP module.

The situation is not relevant as long as no IMAP deliverer is setup.
A requirement hook could check the critical requirement, if an IMAP deliverer is setup.

There was also the idea to stop retrying to fetch on cron if a connection fails.
This might make sense if username and password are wrong.
However, a network might be temporarily down or a server unavailable.
There is no error code that can be used to identify the exact origin of the issue.
Currently, errors are only logged but not displayed. This needs to change to make the user aware of the problems.

miro_dietiker’s picture

In TMGMT, we have added a "Connect" button right beside where the credentials are configured.
But that's #2409923: Monitor IMAP quota

miro_dietiker’s picture

Related issues: +#2409923: Monitor IMAP quota
miro_dietiker’s picture

miro_dietiker’s picture

Status: Postponed » Needs work

The other issue was committed. Now we can implement the new requirements check methods.

toncic’s picture

Assigned: Unassigned » toncic
Status: Needs work » Needs review
FileSize
1.11 KB

Added function checkInstanceRequirements() to check the requirements of the current configuration instance.

miro_dietiker’s picture

Status: Needs review » Needs work
  1. +++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
    @@ -283,4 +283,24 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
    +    if ($this->isAvailable()) {
    

    I think we should at least warn if it is not available.

  2. +++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
    @@ -283,4 +283,24 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
    +          'value' => $this->t('IMAP'),
    +          'description' => $this->t('Deliverer connection failed: @error.', ['@error' =>  imap_errors()['0']]),
    +          'severity' => REQUIREMENT_ERROR,
    

    If we provide an Error, i think we should also provide an OK message such as "Connection successful"?

    Also for all messages, you need to mention the instance name as a reference!

+++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
@@ -283,4 +283,24 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
+          'description' => $this->t('Deliverer connection failed: @error.', ['@error' =>  imap_errors()['0']]),

I would implode all errors and not just pick the first. Also ['0'] is strange - [0] would be better.

toncic’s picture

Status: Needs work » Needs review
FileSize
1.52 KB
1.12 KB

Show message if IMAP is not available, if connection is success and show all message when is error.

miro_dietiker’s picture

Status: Needs review » Needs work
+++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
@@ -283,4 +283,38 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
+    $password = $this->getConfiguration()['password'];
+    if ($this->isAvailable()) {
+      $imap_res = @imap_open($mailbox, $username, $password);
+      if (!$imap_res) {
+        return [
+          'value' => $this->t('IMAP'),
+          'description' => $this->t('Deliverer connection failed: @error.', ['@error' => implode('', imap_errors())]),

I would prefer it this way:

+++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
@@ -283,4 +283,38 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
+    $password = $this->getConfiguration()['password'];
+    $requirements = [
+      'value' => $this->t('IMAP'),
+      'status' => REQUIREMENT_OK,
+    ]

And then in the if() you just add a description and switch the severity if needed.
And at the end you return $requirements.

Note this code in inmail.install

        $requirements[$entity_key] = $plugin->checkInstanceRequirements();
        // Add title in case requirements are not empty.
        if (!empty($requirements[$entity_key])) {
          $requirements[$entity_key]['title'] = $entity->label() . ' (' . $entity->id() . ')';
        }

This titling is very poor. A user neither knows if this e origin of the labels is Inmail nor what plugin (deliverer, handler, ..)
I think inmail default title should contain Inmail + the plugin label + instance label. (no machine / id)
Then the title on the right side is just the message, no "IMAP".

Please update inmail.install accordingly.

Also, the message on the right side should contain the link to configure the plugin instance. Let's do this for now specific to imap, but in general it should apply to all plugins, thus could be added in inmail_get_requirements().

toncic’s picture

Status: Needs work » Needs review
FileSize
2.41 KB
2.81 KB

First I make the array $requirements and after that just added description and severity. After that I added new title on left side and changed title and message on right side and put link on right side.

miro_dietiker’s picture

Status: Needs review » Needs work
  1. +++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
    @@ -283,4 +283,35 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
    +        $requirements['description'] = $this->t('Deliverer connection failed: @error.', ['@error' => implode('', imap_errors())]);
    

    Dunno if the errors are delimited. Say, they end up with a "." - but we still want to implode them with a space.

  2. +++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
    @@ -283,4 +283,35 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
    +        $requirements['severity'] =REQUIREMENT_ERROR;
    

    Space missing.

  3. +++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
    @@ -283,4 +283,35 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
    +        return $requirements;
    ...
    +        return $requirements;
    ...
    +      return $requirements;
    

    return at the end of the method.

toncic’s picture

Status: Needs work » Needs review
FileSize
2.41 KB
2.81 KB

Yes, it is normal to return just once on the end of function, I made mistake, sorry. I changed delimiter also.

mbovan’s picture

Status: Needs review » Needs work
  1. +++ b/inmail.install
    @@ -45,7 +45,9 @@ function inmail_get_requirements() {
    +         $requirements[$entity_key]['title'] = 'Inmail ' . $plugin->getPluginDefinition()['label'] . ' (' . $entity->label() . ' )';
    

    We could use $plugin->getLabel()?

  2. +++ b/inmail.install
    @@ -45,7 +45,9 @@ function inmail_get_requirements() {
    +         $requirements[$entity_key]['value'] = t('<a href=":url">Configure the plugin instance</a>.', [':url' => 'http://d8.dev/admin/config/system/inmail/deliverers/' .
    

    The URL seems wrong.

  3. +++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
    @@ -283,4 +283,35 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
    +    $mailbox_flags = $this->configuration['ssl'] ? '/ssl' : '';
    +    $mailbox = '{' . $this->configuration['host'] . ':' . $this->configuration['port'] . $mailbox_flags . '}';
    +    $username = $this->getConfiguration()['username'];
    +    $password = $this->getConfiguration()['password'];
    

    This is the same code from doImap() method, so with litle refactoring we could call hasValidCredentials() here.

  4. +++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
    @@ -283,4 +283,35 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
    +    if ($this->isAvailable()) {
    

    I think we should update isAvailable method. Otherwise, it is always true.

  5. +++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
    @@ -283,4 +283,35 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
    +      $requirements['description'] = $this->t('The PHP IMAP extension is missing, it must be enabled.');
    

    This part belongs to checkPluginRequirements() more than checkInstanceRequirements().

Edit: Forget about #3. Found an issue that updates it: #2408957: Fail gracefully if IMAP extension missing

mbovan’s picture

Added a related issue.

miro_dietiker’s picture

This part belongs to checkPluginRequirements() more than
checkInstanceRequirements().

Agree but we can also not have an empty message and set warning. We could say "Check skipped, PHP module missing."
So we need to mention a bit why.

toncic’s picture

Status: Needs work » Needs review
FileSize
2.32 KB
1001 bytes

I checked with Ivan about the function `` checkPluginRequirements() ``. He wrote it on the same way which we need.

miro_dietiker’s picture

Status: Needs review » Needs work
+++ b/inmail.install
@@ -45,7 +45,9 @@ function inmail_get_requirements() {
+         $requirements[$entity_key]['value'] = t('Configure the <a href=":url">plugin instance</a>.', [':url' => '/admin/config/system/inmail/deliverers/' .

Checkout hook_requirements documentation:

value: The current value (e.g., version, time, level, etc). During install phase, this should only be used for version numbers, do not set it if not applicable.

So, we would need to append the configuration link to the description.

Also we are changing the label of requirements. Since this doesn't break tests, you should make sure tests with the UnavailableAnalyzer cover the requirements label.

toncic’s picture

Status: Needs work » Needs review
FileSize
2.37 KB
1.01 KB

I changed in $requirements[$entity_key]['value'] = t('Configure the <a href=":url">plugin instance</a>.', [':url' => '/admin/config/system/inmail/deliverers/' . instead of value to use description.

Second part of comment I didn't understand.

miro_dietiker’s picture

Status: Needs review » Needs work
  1. +++ b/inmail.install
    @@ -45,7 +45,9 @@ function inmail_get_requirements() {
    +         $requirements[$entity_key]['title'] = 'Inmail ' . $plugin->getLabel() . ' (' . $entity->label() . ' )';
    

    Trying #2: This needs to be asserted on the requirements test.

  2. +++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
    @@ -306,6 +306,31 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
    +    $mailbox_flags = $this->configuration['ssl'] ? '/ssl' : '';
    +    $mailbox = '{' . $this->configuration['host'] . ':' . $this->configuration['port'] . $mailbox_flags . '}';
    ...
    +      $imap_res = @imap_open($mailbox, $username, $password);
    

    Getting the $mailbox URL should be outsourced into a function and called on the other location of imap_open too. We might do even a $fetcher->imapOpen() that returns the result.

  3. +++ b/inmail.install
    @@ -45,7 +45,9 @@ function inmail_get_requirements() {
    +         $requirements[$entity_key]['description'] = t('Configure the <a href=":url">plugin instance</a>.', [':url' => '/admin/config/system/inmail/deliverers/' .
    
    +++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
    @@ -306,6 +306,31 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
    +        $requirements['description'] = $this->t('Deliverer connection failed: @error.', ['@error' => implode(' ', imap_errors())]);
    ...
    +      $requirements['description'] = $this->t('The PHP IMAP extension is missing, it must be enabled.');
    

    It overwrites description now. You didn't visit admin reports status page to check the output?

toncic’s picture

Status: Needs work » Needs review
FileSize
4.55 KB
4.94 KB

I created two new functions: getMailbox() and do_imap_open().
Also change in doImap(callable $callback) to calll do_imap_open().
Added test coverage and change description in requirements.

Arla’s picture

Status: Needs review » Needs work
  1. +++ b/inmail.install
    @@ -45,7 +45,13 @@ function inmail_get_requirements() {
    +          if ($requirements[$entity_key]['description'] != NULL) {
    

    Switch to !empty() so there won't be an error if the 'description' key does not exist.

  2. +++ b/inmail.install
    @@ -45,7 +45,13 @@ function inmail_get_requirements() {
    +          $requirements[$entity_key]['description'] = t($message . ' Configure the <a href=":url">plugin instance</a>.', [':url' => '/admin/config/system/inmail/deliverers/' . $entity->id()]);
    

    Did the '@message ...' approach not work out? This concatenation breaks t() because it needs to have a constant string value.

  3. +++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
    @@ -304,8 +298,54 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
       /**
    +   * Returns the mailbox URL.
    +   *
    +   * @return string|Drupal\inmail\Plugin\inmail\Deliverer\ImapFetcher
    +   */
    +  public function getMailbox() {
    

    This is not a "URL", just a string, and does not return an ImapFetcher object.

    @return should always have a second line describing in words what is returned.

  4. +++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
    @@ -304,8 +298,54 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
    +  /**
    +   * Run imap_open() and return result.
    +   *
    +   * @return resource
    +   */
    +  public function do_imap_open() {
    

    Methods should be in camelCase (even if the related PHP function is named with snake_case). So doImapOpen or just imapOpen.

  5. +++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
    @@ -304,8 +298,54 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
    +  }
    +
       public function isAvailable() {
    

    This method is now missing a doc comment.

  6. +++ b/tests/src/Kernel/ProcessorTest.php
    @@ -97,6 +97,12 @@ EOF;
    +    $requirements = inmail_get_requirements();
    +    inmail_get_requirements();
    

    What is the second call for?

Btw I'm not really familiar with hook_requirements(). I cannot tell if the $requirements structure is correct here. It seems to me that the test coverage is a bit low.

toncic’s picture

Status: Needs work » Needs review
FileSize
4.65 KB
3.05 KB

#2 I thought the better way is to just set $message, but you are in right. t() doesn't work.

miro_dietiker’s picture

Status: Needs review » Needs work
FileSize
9.08 KB
  1. +++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
    @@ -108,13 +108,7 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
    +    $imap_res = $this->do_imap_open();
    
    @@ -304,6 +298,56 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
       /**
    ...
    +  public function doImapOpen() {
    ...
    +      if (!$this->do_imap_open()) {
    

    Something is wrong here. I guess it's untested.
    Error: Call to undefined method Drupal\\inmail\\Plugin\\inmail\\Deliverer\\ImapFetcher::do_imap_open()

  2. +++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
    @@ -304,6 +298,56 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
    +    return @imap_open($this->getMailbox(), $this->getConfiguration()['username'],$this->getConfiguration()['password']);
    

    , space.

  3. +++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
    @@ -304,6 +298,56 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
    +      'value' => $this->t('Message'),
    

    Value is only allowed for version number. Message is not adding any value, see image below. Remove.

  4. +++ b/tests/src/Kernel/ProcessorTest.php
    @@ -97,6 +97,11 @@ EOF;
    +   $this->assertEqual($requirements['analyzer_entity_unavailable_analyzer']['title'], 'Inmail Unavailable Analyzer (Unavailable Analyzer)');
    

    Please remove the brackets, instead:
    Inmail Unavailable Analyzer: Unavailable Analyzer

    The label is misleading, see image how it looks in real life:

    Please pick a different label for the instance so it is not ambiguous.

  5. +++ b/inmail.install
    @@ -45,7 +45,14 @@ function inmail_get_requirements() {
    +            $requirements[$entity_key]['description'] = t('message' .  ' Configure the <a href=":url">plugin instance</a>.', ['message' => $requirements[$entity_key]['description'], ':url' => '/admin/config/system/inmail/deliverers/' . $entity->id()]);
    

    message?

toncic’s picture

Status: Needs work » Needs review
FileSize
4.6 KB
3.19 KB

#5. I'm using 'message' to save the previous description that I can concatenate with new description.

miro_dietiker’s picture

Status: Needs review » Needs work

So yeah, the open and mailbox method looks great. Still some stuff that needs work:

  1. +++ b/inmail.install
    @@ -45,7 +45,14 @@ function inmail_get_requirements() {
    +          $requirements[$entity_key]['title'] = 'Inmail ' . $plugin->getPluginDefinition()['label'] . ' ' .  $entity->label();
    

    i'm missing the colon ":" after definition label.

  2. +++ b/inmail.install
    @@ -45,7 +45,14 @@ function inmail_get_requirements() {
    +            $requirements[$entity_key]['description'] = t('message' .  ' Configure the <a href=":url">plugin instance</a>.', ['message' => $requirements[$entity_key]['description'], ':url' => '/admin/config/system/inmail/deliverers/' . $entity->id()]);
    

    Ah i see, but 'message' is not an acceptable placeholder. Anyway, we don't concatenate things like that. Use .= or a temporary array variable and later implode them.

toncic’s picture

Implement comm #25.

Status: Needs review » Needs work

The last submitted patch, 26: report_error_if-2405757-26.patch, failed testing.

The last submitted patch, 26: report_error_if-2405757-26.patch, failed testing.

The last submitted patch, 26: report_error_if-2405757-26.patch, failed testing.

miro_dietiker’s picture

+++ b/inmail.install
@@ -45,10 +45,9 @@ function inmail_get_requirements() {
+            $requirements[$entity_key]['description'] = t($requirements[$entity_key]['description'] . ' Configure the <a href=":url">plugin instance</a>.', [':url' => '/admin/config/system/inmail/deliverers/' . $entity->id()]);

You are not supposed to place variables inside t().

toncic’s picture

Status: Needs work » Needs review
FileSize
4.63 KB
1.72 KB

Changed description.

Status: Needs review » Needs work

The last submitted patch, 31: report_error_if-2405757-29.patch, failed testing.

toncic’s picture

I didn't see comment, I will make new patch.

toncic’s picture

Status: Needs work » Needs review
FileSize
2.67 KB

I changed description and remove condition because in every case description is not empty, so is point less to ask,

toncic’s picture

Status: Needs review » Needs work

The last submitted patch, 35: report_error_if-2405757-34.patch, failed testing.

toncic’s picture

Status: Needs work » Needs review
FileSize
5.73 KB
mbovan’s picture

Status: Needs review » Needs work
  1. +++ b/inmail.install
    @@ -30,7 +31,8 @@ function inmail_get_requirements() {
    -    $entities = $entity_type_manager->getStorage("inmail_$plugin_type")->loadByProperties(['status' => TRUE]);
    +    $entities = $entity_type_manager->getStorage("inmail_$plugin_type")
    +      ->loadByProperties(['status' => TRUE]);
    
    +++ b/inmail.install
    @@ -56,7 +66,8 @@ function inmail_get_requirements() {
    -          'description' => t('Inmail @type plugin @id is missing and cannot be used.', ['@type' => $plugin_type, '@id' => $plugin_id]),
    +          'description' => t('Inmail @type plugin @id is missing and cannot be used.',
    +            ['@type' => $plugin_type, '@id' => $plugin_id]),
    

    I guess you accidentally changed this.

  2. +++ b/inmail.install
    @@ -45,8 +47,16 @@ function inmail_get_requirements() {
    +          $requirements[$entity_key]['description'] = [
    +            'de' => ['#markup' => $requirements[$entity_key]['description']],
    +            'dd' => ['#markup' => t( 'Configure the <a href=":url">plugin instance</a>.', [
    +             ':url' => Url::fromRoute('entity.inmail_deliverer.edit_form',
    +               ['inmail_deliverer' => $entity->id()])])],
    +          ];
    

    Can't we put the old description in a variable and use it in a new t() wrapper? This way, we could easily make a space between two sentences.

    Also, I'm getting some errors (Reports page) when this case occurs:
    "Warning: strpos() expects parameter 1 to be string" and "Warning: htmlspecialchars() expects parameter 1 to be string".

  3. +++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
    @@ -317,6 +311,55 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
    +   * @return resource
    

    It's usual to provide the explanation for the return value. At least: "The IMAP resource."

  4. +++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
    @@ -317,6 +311,55 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
    +      if (!$this->doImapOpen()) {
    

    This needs to be in isAvailable too? Otherwise, we could think there is a valid IMAP fetcher, which is actually not available because of an imap_open() error?

  5. +++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
    @@ -317,6 +311,55 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
    +    else {
    +      $requirements['description'] = $this->t('The PHP IMAP extension is missing, it must be enabled.');
    

    I see Miro said we should explain that instance is not available because of the plugin requirements. Let's synchronize the messages then (link PHP IMAP).

    Note: we could say point out the user to the plugin requirements instead of copying the message. However, it seems less explanatory but shorter in case we extend checkPluginRequirements() at some point.

  6. +++ b/tests/src/Kernel/ProcessorTest.php
    @@ -98,6 +98,11 @@ EOF;
    +   $this->assertEqual($requirements['analyzer_entity_unavailable_analyzer']['title'], 'Inmail Unavailable Analyzer: Unavailable Analyzer');
    

    One extra space here.

toncic’s picture

Status: Needs work » Needs review
FileSize
6.1 KB
0 bytes

#1 The line is to long, so I think is better to be shorter. I've not found some rule in coding standards which say what is the best way to split the long line, so from my point of view maybe something like that.
#2.Miro said that do not use variable in t().

mbovan’s picture

Status: Needs review » Needs work

Sorry for commenting again. :)

Re #39.1: Just want to point out that only change we are doing here is shortening the lines, which is not really related to the issue title? I guess we could find more cases like those, but is it the goal of the issue?

Re #39.2: I think he meant (#30) we can't put the variables directly in the t() wrapper, but using placeholders that would be possible. Sorry for being unclear.

What about #38.2, do you get those errors?

Discussed yesterday with @toncic92, and we agreed to wait for a comment from @miro_dietiker about #38.4.

It seems #38.6 still applies.

Btw, the interdiff above is empty.

miro_dietiker’s picture

Let's keep complexity low of isAvailable() in this issue.

Open a separate issue about connecting in isAvailable to see it it works.
Note the hook_requirements already do this and this is a slow operation.
We can not call isAvailable when building lists if it connects. It would make things very slow.
So first we need to outline the purpose of this API and discuss directions.

We can complete this issue easily without that complexity added.

  1. +++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
    @@ -317,6 +311,77 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
    +      $mailbox = '{'
    +        . $this->configuration['host']
    +        . ':'
    +        . $this->configuration['port']
    +        . '/pop3'
    +        . $mailbox_flags
    +        . '}';
    

    Doesn't look so much more readable than on one line.

  2. +++ b/tests/src/Kernel/ProcessorTest.php
    @@ -98,6 +98,14 @@ EOF;
    +     'Inmail Unavailable Analyzer : Unavailable Analyzer'
    

    You still have ambiguous naming as in twice the same "Unavailable Analyzer". Change one to make it clear what is the instance and what is the plugin label.

toncic’s picture

Status: Needs work » Needs review
FileSize
5.8 KB
4.11 KB

#38.2 Yes. I got the warning Notice: Undefined index: title in Drupal\system\SystemManager->Drupal\system\{closure}() (line 116 of core/modules/system/src/SystemManager.php). . I tried to find what is happening but I didn't find.

#41.1 I am trying to find the best way to split the long line because I've not found any rule in documentation. What I did is wrong, yeah, is more readable when is inline in this case.

mbovan’s picture

Status: Needs review » Needs work

Created a followup (#2795087: Update isAvailable() of IMAP with connection details) for #41.

#38.2 Yes. I got the warning Notice: Undefined index: title in Drupal\system\SystemManager->Drupal\system\{closure}() (line 116 of core/modules/system/src/SystemManager.php). . I tried to find what is happening but I didn't find.

Try to use toString() on the URL object.

  1. +++ b/inmail.install
    @@ -45,8 +46,19 @@ function inmail_get_requirements() {
    +          $requirements[$entity_key]['description'] = t('@old_description' . ' '
    +            . 'Configure the <a href=":url">plugin instance</a>.',
    

    You don't need to concatenate strings in a t() function.

  2. +++ b/tests/src/Kernel/ProcessorTest.php
    @@ -66,7 +66,7 @@ EOF;
         $unavailable_analyzer = AnalyzerConfig::create([
    ...
    -      'label' => 'Unavailable Analyzer',
    +      'label' => 'Unavailable analyzer plugin',
    

    This looks like an instance.

  3. +++ b/tests/src/Kernel/ProcessorTest.php
    @@ -98,6 +98,13 @@ EOF;
    +    $this->assertEqual(
    +      $requirements['analyzer_entity_unavailable_analyzer']['title'],
    +     'Inmail Unavailable Analyzer : Unavailable analyzer plugin'
    +   );
    

    One more space on the last line here. :)
    ProcessorTest::testMessageProcessing() seems to use assertEquals() instead of deprecated assertEqual() so we should stick with that.

toncic’s picture

Status: Needs work » Needs review
FileSize
5.83 KB
1.81 KB

toString() is working.

miro_dietiker’s picture

Assigned: toncic » Berdir
Status: Needs review » Needs work

We are near.

  1. +++ b/inmail.install
    @@ -45,8 +46,20 @@ function inmail_get_requirements() {
    +          $requirements[$entity_key]['title'] ='Inmail ' . $plugin->getPluginDefinition()['label'] . ' : ' . $entity->label();
    
    +++ b/tests/src/Kernel/ProcessorTest.php
    @@ -98,6 +98,13 @@ EOF;
    +      'Inmail Unavailable Analyzer : Unavailable analyzer instance'
    

    We don't do spaces before and after colon. It's...
    A: B

  2. +++ b/inmail.install
    @@ -45,8 +46,20 @@ function inmail_get_requirements() {
    +            '@old_description' . ' '
    +            . 'Configure the <a href=":url">plugin instance</a>.',
    ...
    +              '@old_description' => $requirements[$entity_key]['description'],
    

    This is ugly concatenation plus it's not how a t() likes to get static text (a string without any separator). Assigning to Berdir for some cleaner concatenation proposal.

toncic’s picture

Status: Needs work » Needs review
FileSize
5.61 KB
1.5 KB

Fixing coding standards.

toncic’s picture

Assigned: Berdir » toncic
mbovan’s picture

Looks good to me.

+++ b/src/Plugin/inmail/Deliverer/ImapFetcher.php
@@ -349,6 +344,66 @@ class ImapFetcher extends FetcherBase implements ContainerFactoryPluginInterface
+    $mailbox = '{' . $this->configuration['host'] . ':' . $this->configuration['port'] . $mailbox_flags . '}';
+    if ($this->configuration['protocol'] === 'pop3') {
+      $mailbox = '{' . $this->configuration['host'] . ':' . $this->configuration['port'] . '/pop3' . $mailbox_flags . '}';
+    }

Optional: We could move if condition above and use string concatenation instead.

toncic’s picture

I think that I found better solution. We can just call getFalgs() and the problem is solved. ;)

miro_dietiker’s picture

Assigned: toncic » Berdir

I switched to Berdir intentionally, back to him.
I wanted to ask him for a statement, how to best merge/concatenate description.

toncic’s picture

Sorry for switching, I discussed with him and thought that is ok now.

Berdir’s picture

Assigned: Berdir » Unassigned
Status: Needs review » Needs work

the description is fine, we discussed that.

Title not at all, you need to use placeholders.

toncic’s picture

Assigned: Unassigned » toncic
Status: Needs work » Needs review
FileSize
5.71 KB
777 bytes

I switch to use placeholder.

mbovan’s picture

+++ b/inmail.install
@@ -3,6 +3,7 @@
+use Drupal\Core\Url;

@@ -45,8 +46,24 @@ function inmail_get_requirements() {
+          $requirements[$entity_key]['title'] =t(
...
+          $requirements[$entity_key]['description'] = t(
...
+            ]
+          );
+         }

@@ -56,7 +73,10 @@ function inmail_get_requirements() {
-          'description' => t('Inmail @type plugin @id is missing and cannot be used.', ['@type' => $plugin_type, '@id' => $plugin_id]),
+          'description' => t(
+            'Inmail @type plugin @id is missing and cannot be used.',
+            ['@type' => $plugin_type, '@id' => $plugin_id]
+          ),

+++ b/tests/src/Kernel/ProcessorTest.php
@@ -98,6 +98,13 @@ EOF;
+    $this->assertEquals(
...
+   );

Other than some code style issues, looks nice!

toncic’s picture

Berdir’s picture

Status: Needs review » Needs work
+++ b/inmail.install
@@ -56,7 +73,11 @@ function inmail_get_requirements() {
       catch (\Drupal\Component\Plugin\Exception\PluginException $e) {
         $requirements[$plugin_key] = [
           'title' => t('Missing plugin @id', ['@id' => $plugin_id]),
-          'description' => t('Inmail @type plugin @id is missing and cannot be used.', ['@type' => $plugin_type, '@id' => $plugin_id]),
+          'description' => t(
+            'Inmail @type plugin @id is missing and cannot be used.', [
+              '@type' => $plugin_type, '@id' => $plugin_id,
+            ]
+          ),
           'severity' => REQUIREMENT_ERROR,

again, there is nothing (almost nothing) wrong with t() lines being longer than 80 characters. IMHO, the old version is more readable and more importantly, this is an unrelated change, there is no actual change here but this forces reviewers to read this and look for a change.

toncic’s picture

Status: Needs work » Needs review
FileSize
6.13 KB
751 bytes
mbovan’s picture

Status: Needs review » Reviewed & tested by the community

Good to go!

miro_dietiker’s picture

Status: Reviewed & tested by the community » Needs work

Almost. :-)

+++ b/inmail.install
@@ -45,7 +46,23 @@ function inmail_get_requirements() {
+          $requirements[$entity_key]['description'] = t(
+            '@old_description Configure the <a href=":url">plugin instance</a>.', [
+              '@old_description' => $requirements[$entity_key]['description'],

As of Berdir, this supports render arrays, so we should be able to simply do [] here.
We could even define that the description is always an array from the plugins and then things are easier to merge.

And again, Berdir said you should not wrap lines, this means t( stands on the same line as the static text.

toncic’s picture

Status: Needs work » Needs review
FileSize
6.07 KB
1.51 KB

Foramting t().

miro_dietiker’s picture

Assigned: toncic » miro_dietiker
Status: Needs review » Needs work

I'll complete the remaining parts after 60+ comments.

The way how we compile requirements and add the configure link is still not clean.
The other IMAP specific parts are fine.