Closed (fixed)
Project:
Inmail
Version:
8.x-1.x-dev
Component:
Analyzers
Priority:
Critical
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
23 Jun 2016 at 10:11 UTC
Updated:
4 Aug 2016 at 15:14 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
miro_dietikerThe problem here is that
- the analyzers should collaborate with each other, but
- one analyser dominates the process and creates pretty limited result object that can not be extended by others.
this is an architectural conflict with the current setup and asks if we should have a standard result that offers some collaborative interfaces such as adding contextual data...
Promoting to critical since it's significantly shaping the API.
Comment #3
mbovan commentedNot sure why it cannot be extended by others? Analyzers share the same (analyzer result) object and each has an option to set new data or update the data that's already set by other analyzers. We could add a default result object with (standard) properties like: sender, user, processed body, footer, signature...
The problem can be that some analyzers would need to set their results into context (a property on stanard Inmail analyzer result) or work with interfaces as @miro_dietiker mentioned.
Comment #4
miro_dietikerTrying to better explain my argumentation above.
In the current coding pattern, the first processor who create a result is the Winner.
All other processors can not create a different result with a different more specific interface to them. They need to collaborate with prior analysers through extending the result. What means, the result is fixed in type.
(As soon a more specific analyser result is wanted, we risk dropping data of earlier analyser when the result is replaced.)
This means, as soon as we have a default result object, basically no analyser ever has the opportunity to create an other more specific result.
It also means that the API of the default result should be feature complete and ready for all cases.
Comment #5
mbovan commentedAdding
InmaiilAnalyzerResultbased onMailhandlerAnalyzerResultextended with context data.Comment #6
primsi commentedMissing ending dot.
This might not be relevant for all message types. Move to a context?
Same as above.
Comment #7
berdirDiscussed this with Miro quickly.
My suggestion was to use the Context classes of the plugin system. They have a type, a definition and a value and are integrated with typed data (make sure you use the one in Drupal\Core, not component).
Then you are just a few steps away from Plugins that can define what contexts they need (See \Drupal\node\Plugin\Condition\NodeType as an example) and I think rules also uses that or at least builds on top of it.
So you'd have a method like addContext($name, ContextInterface $context), hasContext(), getContexts(), maybe also something like getContextsWithType() or similar helper methods.
Comment #8
mbovan commentedThank you for the feedback, Sascha!
Fixed the points from #6 and implemented suggested methods in #7.
\Drupal\node\Plugin\Condition\NodeTypehas "node" context key in annotations. Does it mean it requires the context with "node" name to be present at time when this plugin runs?Comment #9
mbovan commentedSmall cleanup and documentation updates.
Comment #10
primsi commentedSouldn't is be ContextInterface[] ?
Type hint?
Just sender and subject? Should we at least mention that other contexts are attached?
Has no default value.
So the subsequent parts of the system need to know the name? Should we support getting contexts by type? Is there a nomenclature for naming contexts?
Also: what happens if two analysers want to add the same context type. The last one overrides all? Hm... is there even a use case for it....
Comment #11
primsi commentedComment #12
mbovan commentedAddressed the points from #10 and added
getContextsWithType()method.Hmm, no? Any suggestions on this? Maybe we can use a module name as a prefix, e.g.
mailhandler_entity_type.Yes. It's overridden in case of the same name.
Comment #13
miro_dietikerUnsure if this should be Account or user?
How about "Default Result"?
getAllContexts() or so?
I don't like that +s to fetch all. Core also adds the +Multiple.
IMHO this should throw an exception when the context with $name is not existing, expecially since we have a hasContext($name)
This issue neither uses the result in inmail nor tests it.
I think we need this and can not simply commit the result for later use.
Comment #14
miro_dietikerAlso i'm missing the application of the context definition.
Through the definition it should be possibly to enumerate all existing contexts accross all context providers.
We need a discovery / plugin manager for that?
One question would be, will we simply put account/user into a named context and use the same API?
Comment #15
mbovan commentedApplied suggestions from #13.
Added Inmail application in this patch and relevant tests. Also, there is an implemented suggestion to ensure/create
InmailAnalyzerResultby default. It would allow us to prefill some properties (AnonymousUseras the default account) that can be overridden by analyzers later. Btw, to pre-set the user we would need "user" dependency or to check if user module is enabled. Not sure what is the proposed way in this sort of situations.Added a test analyzer context example. Hm, didn't we describe context "plugins" as parts of analyzers?
Comment #17
miro_dietikerAnonymous is the default. There is no reason to load an anonymous user and attach it to the user context. Attaching NULL or not attaching anything at all needs to have the same effect. We should really only attach an account if we should switch to a specific account from anonymous.
Not sure about your other question...
Comment #18
miro_dietikerSome thoughts from a quick review.
Why not name it DefaultAnalyzerResult?
Hm yeah, we kindof have double extensibility here with result topics.
The whole bounce case could also be handled with a simple single result and some context data instead of a bounce topic and a separate result. We need to carefully think about this situation and decide if we will drop the multi result concept as a whole if we have contextual typed data on the result. Not yet sure.
Happy to discuss and separate this problem into a follow-up. For now i would just introduce the standard result and offer the new methods and avoid overlaps with the bounce cases as much as possible.
Unsure here. My idea was to only set this if it's different than anonymous. But i see, we could also simply initialise it to anonymous.
Why do we need to set the default result sender here? Why overwrite it in Verp?
Comment #19
mbovan commentedRe #18.1: Fixed.
Re #18.2: Created a followup #2769061: Replace bounce analyzer result with default one.
Re #18.3: Yes, I was thinking that we'll have the situation e.g.
getAccount()->hasPermission()Re #18.4: Ah, I've just updated VERP as an example where we can merge properties with default result object. Reverted the changes.
AnalyzerTest passes locally, not sure why it's failing on testbot.
Comment #21
miro_dietikerAlso another follow-up: Even the user context (and many others) should then be exposed through the same context definition interface and internally use those. So the same system can be used to build a UI.
What if the context already exists? We should also throw exception here.
I think this should throw an exception if undefined.
No need to check. In real installations, user module always exists. (Except kernel tests)
Test fails: Plz check core and contrib module versions of testbot to reproduce the same condition locally.
Another Follow-up will be to declare the potential analyzer contexts through annotation so we can build a UI.
Comment #22
mbovan commentedAddressed the points (1, 2, 3) from #21 and created follow-ups: #2769671: Expose contexts through Context definition interface, #2769673: Use annotations to declare potential analyzer contexts.
Comment #23
berdirprotected
Also remove the @todo.
(miro will do that on commit)
Comment #24
miro_dietikerThx, committed. :-)
And created a follow-up about converting the internals of the standard result to context data too...
#2770553: Expose defaultAnalyzerResult properties as contexts
Comment #26
arla commentedOh no, I'm too slow :) Commenting anyway, for discussion's sake (here or in followups).
IS is not very clear about the relation between this issue and #2743921: Create Mailhandler analyzer. I suppose that it was simply the second analyzer result class created, and therefore triggered the need of this issue?
I'm looking forward to that followup!
Indeed, I thought the point was to only use context already in this issue. That is, no sender/account/body/footer/subject properties in DefaultAnalyzerResult, only contexts.
Is there really a point in a new interface for the new result class? If yes, why doesn't it extend AnalyzerResultInterface?
AFAIK it's customary to use setX() when the structure is associative (and addX() when it's a list). IMHO, that would also make the exception unnecessary, because "set" implies that overwriting may occur. (If the caller wants to avoid overwriting, it should first check the result of hasContext()).
Comment #27
arla commentedCreated followups based on my last comment:
#2770567: Remove ability to extend results by "topic" now that there are contexts (highly related to, almost a duplicate of #2769061: Replace bounce analyzer result with default one)
#2770667: Remove DefaultAnalyzerResultInterface
#2770679: Rename addContext() to setContext()