Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#60 | interdiff-2405757-57-60.txt | 1.51 KB | toncic |
#60 | report_error_if-2405757-60.patch | 6.07 KB | toncic |
| |||
#57 | interdiff-2405757-55-57.txt | 751 bytes | toncic |
#57 | report_error_if-2405757-57.patch | 6.13 KB | toncic |
| |||
#55 | interdiff-2405757-53-55.txt | 3.05 KB | toncic |
Comments
Comment #1
miro_dietikerIf 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.
Comment #2
miro_dietikerIn TMGMT, we have added a "Connect" button right beside where the credentials are configured.
But that's #2409923: Monitor IMAP quota
Comment #3
miro_dietikerComment #4
miro_dietikerPostponed on #2769617: Provide a hook_requirements fed by plugin instances
Comment #5
miro_dietikerThe other issue was committed. Now we can implement the new requirements check methods.
Comment #6
toncic CreditAttribution: toncic at MD Systems GmbH commentedAdded function checkInstanceRequirements() to check the requirements of the current configuration instance.
Comment #7
miro_dietikerI think we should at least warn if it is not available.
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!
I would implode all errors and not just pick the first. Also ['0'] is strange - [0] would be better.
Comment #8
toncic CreditAttribution: toncic at MD Systems GmbH commentedShow message if IMAP is not available, if connection is success and show all message when is error.
Comment #9
miro_dietikerI would prefer it this way:
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
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().
Comment #10
toncic CreditAttribution: toncic at MD Systems GmbH commentedFirst 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.
Comment #11
miro_dietikerDunno if the errors are delimited. Say, they end up with a "." - but we still want to implode them with a space.
Space missing.
return at the end of the method.
Comment #12
toncic CreditAttribution: toncic at MD Systems GmbH commentedYes, it is normal to return just once on the end of function, I made mistake, sorry. I changed delimiter also.
Comment #13
mbovan CreditAttribution: mbovan as a volunteer and for Google Summer of Code commentedWe could use
$plugin->getLabel()
?The URL seems wrong.
This is the same code from
doImap()
method, so with litle refactoring we could callhasValidCredentials()
here.I think we should update
isAvailable
method. Otherwise, it is always true.This part belongs to
checkPluginRequirements()
more thancheckInstanceRequirements()
.Edit: Forget about #3. Found an issue that updates it: #2408957: Fail gracefully if IMAP extension missing
Comment #14
mbovan CreditAttribution: mbovan as a volunteer and for Google Summer of Code commentedAdded a related issue.
Comment #15
miro_dietikerAgree 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.
Comment #16
toncic CreditAttribution: toncic at MD Systems GmbH commentedI checked with Ivan about the function `` checkPluginRequirements() ``. He wrote it on the same way which we need.
Comment #17
miro_dietikerCheckout hook_requirements documentation:
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.
Comment #18
toncic CreditAttribution: toncic at MD Systems GmbH commentedI 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.
Comment #19
miro_dietikerTrying #2: This needs to be asserted on the requirements test.
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.
It overwrites description now. You didn't visit admin reports status page to check the output?
Comment #20
toncic CreditAttribution: toncic at MD Systems GmbH commentedI created two new functions:
getMailbox()
anddo_imap_open()
.Also change in
doImap(callable $callback)
to callldo_imap_open()
.Added test coverage and change description in requirements.
Comment #21
ArlaSwitch to
!empty()
so there won't be an error if the 'description' key does not exist.Did the '@message ...' approach not work out? This concatenation breaks t() because it needs to have a constant string value.
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.
Methods should be in camelCase (even if the related PHP function is named with snake_case). So doImapOpen or just imapOpen.
This method is now missing a doc comment.
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.
Comment #22
toncic CreditAttribution: toncic at MD Systems GmbH commented#2 I thought the better way is to just set $message, but you are in right. t() doesn't work.
Comment #23
miro_dietikerSomething is wrong here. I guess it's untested.
Error: Call to undefined method Drupal\\inmail\\Plugin\\inmail\\Deliverer\\ImapFetcher::do_imap_open()
, space.
Value is only allowed for version number. Message is not adding any value, see image below. Remove.
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.
message?
Comment #24
toncic CreditAttribution: toncic at MD Systems GmbH commented#5. I'm using 'message' to save the previous description that I can concatenate with new description.
Comment #25
miro_dietikerSo yeah, the open and mailbox method looks great. Still some stuff that needs work:
i'm missing the colon ":" after definition label.
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.
Comment #26
toncic CreditAttribution: toncic at MD Systems GmbH commentedImplement comm #25.
Comment #30
miro_dietikerYou are not supposed to place variables inside t().
Comment #31
toncic CreditAttribution: toncic at MD Systems GmbH commentedChanged description.
Comment #33
toncic CreditAttribution: toncic at MD Systems GmbH commentedI didn't see comment, I will make new patch.
Comment #34
toncic CreditAttribution: toncic at MD Systems GmbH commentedI changed description and remove condition because in every case description is not empty, so is point less to ask,
Comment #35
toncic CreditAttribution: toncic at MD Systems GmbH commentedComment #37
toncic CreditAttribution: toncic at MD Systems GmbH commentedComment #38
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedI guess you accidentally changed this.
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".
It's usual to provide the explanation for the return value. At least: "The IMAP resource."
This needs to be in
isAvailable
too? Otherwise, we could think there is a valid IMAP fetcher, which is actually not available because of animap_open()
error?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.One extra space here.
Comment #39
toncic CreditAttribution: toncic at MD Systems GmbH commented#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().
Comment #40
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedSorry 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.
Comment #41
miro_dietikerLet'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.
Doesn't look so much more readable than on one line.
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.
Comment #42
toncic CreditAttribution: toncic at MD Systems GmbH commented#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.
Comment #43
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedCreated a followup (#2795087: Update isAvailable() of IMAP with connection details) for #41.
Try to use
toString()
on the URL object.You don't need to concatenate strings in a t() function.
This looks like an instance.
One more space on the last line here. :)
ProcessorTest::testMessageProcessing()
seems to use assertEquals() instead of deprecated assertEqual() so we should stick with that.Comment #44
toncic CreditAttribution: toncic at MD Systems GmbH commentedtoString()
is working.Comment #45
miro_dietikerWe are near.
We don't do spaces before and after colon. It's...
A: B
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.
Comment #46
toncic CreditAttribution: toncic at MD Systems GmbH commentedFixing coding standards.
Comment #47
toncic CreditAttribution: toncic at MD Systems GmbH commentedComment #48
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedLooks good to me.
Optional: We could move if condition above and use string concatenation instead.
Comment #49
toncic CreditAttribution: toncic at MD Systems GmbH commentedI think that I found better solution. We can just call getFalgs() and the problem is solved. ;)
Comment #50
miro_dietikerI switched to Berdir intentionally, back to him.
I wanted to ask him for a statement, how to best merge/concatenate description.
Comment #51
toncic CreditAttribution: toncic at MD Systems GmbH commentedSorry for switching, I discussed with him and thought that is ok now.
Comment #52
Berdirthe description is fine, we discussed that.
Title not at all, you need to use placeholders.
Comment #53
toncic CreditAttribution: toncic at MD Systems GmbH commentedI switch to use placeholder.
Comment #54
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedOther than some code style issues, looks nice!
Comment #55
toncic CreditAttribution: toncic at MD Systems GmbH commentedI hope that is OK now.
Comment #56
Berdiragain, 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.
Comment #57
toncic CreditAttribution: toncic at MD Systems GmbH commentedComment #58
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedGood to go!
Comment #59
miro_dietikerAlmost. :-)
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.
Comment #60
toncic CreditAttribution: toncic at MD Systems GmbH commentedForamting t().
Comment #61
miro_dietikerI'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.