When subscribing to an event subscriber it is likely you will need to display messages to the migration system. The correct migrate message service is dependent on the calling code not a generic service though so this needs to be provided with the event so the subscriber can correctly display messages. Think of a subscriber receiving an event in drush vs a batch.
| Comment | File | Size | Author |
|---|---|---|---|
| #46 | add_message_service_to-2546004-46.patch | 14.22 KB | neclimdul |
| #46 | add_message_service_to-2546004-46.interdiff.txt | 1.27 KB | neclimdul |
| #9 | 2546004-6.interdiff.txt | 5.38 KB | neclimdul |
| #6 | add_message_service_to-2546004-6.patch | 7.75 KB | hussainweb |
| #3 | 2546004-3.interdiff.txt | 1.04 KB | neclimdul |
Comments
Comment #3
neclimdulComment #4
neclimdulComment #5
benjy commentedIt's likely many migrate events are going to need to be able to log. I wonder if we should just add a logMessage() method to a base migrate event class rather than exposing the service?
Comment #6
hussainwebI added a common event base class for all migrate events and put the message interface on that directly. I also added a logMessage() method on this base class as described in #5. I lost the interdiff I created but it was around the size of the patch itself, so, I hope it's okay.
Comment #7
mikeryanShould be in the Drupal\migrate\Event namespace.
I think it would be clearer to name this MigrationEvent.
I'm not sure it's really worthwhile to have a convenience function for this -
$event->logMessage()isn't exactly a huge improvement over$event->getMessageService()->display(). And I think having a different function name (logMessage vs. display) obscures what it's doing - a migration developer familiar with the API will immediately recognize what display() is doing, and will hesitate over using a different name to do the exactly same thing just because the context is an event listener.Besides which, we're not logging here (which implies persisting the message somewhere such as the message table), we are displaying the message in a front end.
Best practice is to extend the parent class signature (the arguments being passed through should be in the order of the base constructor). Applies to all the events.
Should call the parent constructor. Applies to all the events.
The map events are quietly changed to use the new base class, but the message service is not being passed, so a consumer of the event trying to use the message service will blow up. The problem, of course, is these events are dispatched from the Sql id map plugin, which does not have access to the MigrateExecutable or its message service. So, if the map events are to use the message service, it will need to be passed to ID map plugins. If not, then they should continue to extend the Symfony event.
Comment #8
hussainweb#7:
1. Actually, it should be in Drupal\migrate namespace itself so that FQCN is
\Drupal\migrate\Event.2. I am mixed on that. I think there is merit in it being
\Drupal\migrate\Eventrather than\Drupal\migrate\MigrateEvent. Also, consider that this base class would not be used in itself, only extended (we could mark it abstract).3. I agree with you here. I just added it to see if it was worthwhile. It doesn't look like it.
4. and 5. Agreed.
6. I couldn't find where those events were being invoked. I will look for them again to make sure.
@mikeryan: I'd like to hear your thoughts on the above, especially points 1 and 2.
Comment #9
neclimdul1) I think Mike is right. Drupal\migrate\Event also references 2 things in the patch which isn't illegal but is confusing.
2) EventBase. I'm a fan of letting the namespace clarify the rest and not duplicating.
3) yeah, we can get rid of that.
4) sure
5) yeah, fixed.
6) I didn't do these because they required some more refactoring. Moved them back to symfony events for now. so we can unblock #2545632: [PP1] Move memory reclamation out of migrate executable
Still needs tests. Will take a look.
Comment #10
neclimdulNot a lot to test but here it is. Tossed in the other methods on the events just because its quick but am willing to remove the tests.
Comment #11
neclimdulComment #15
neclimdulphpunit was perfectly happy not failing on this namespace mistake which is why I couldn't figure out why it was failing.
Comment #16
benjy commented$event->logMessage() isn't exactly a huge improvement over $event->getMessageService()->display()
The point is that the consuming code is decoupled from the message service.
I actually think we should rename to log() or logMessage() everywhere, they much better describe what we're doing than display(). Given the message service is swappable, it could be logged to syslog, or it could be logged to the screen. display() only works in the latter.
As I mentioned on the other issue, i'd rather the order of the params were the same as MigrateExecutable
Comment #17
neclimdul1) so... log something method? should maybe be follow up to just cleanup the message system?
2) That was set in response to #7.4
Comment #18
benjy commentedYes, i think a logMessage() method on the event and then a follow-up to rename that it the message system.
Shame about the constructor args, IMO the base class was wrong, we had MigrateExecutable as precedent for the order of those two args, and consistency is important for me. I'd vote for re-ordering those params in the base event class as well to match up with MigrateExecutable.
Comment #19
neclimdulMiss-understanding with benjy. Discussed and we decided to push migration down to the base class and match executable signature.
Also convert getMessage() to logMessage() shortcut method.
Comment #20
neclimdulits way to late... here's the interdiff i meant to click on.
Comment #21
webchickThis is blocking #2545632: [PP1] Move memory reclamation out of migrate executable so tagging. However, that is also a normal task clean-up issue so I don't think we need any priority changes here.
Comment #22
quietone commentedShouldn't [1,2,3] be [1, 2, 3]? This appears twice in each Unit test.
The only comment that I don't see agreement on is mikeryan's second point in comment #7 about
I noticed the rollback events are not tested. Does that need to be done?
Comment #23
neclimdulLets see what drupalci things about this.
Comment #24
dawehnerThis this supposed to be an abstract base class?
Comment #25
neclimdulIt looks like maybe... 3 months is hard to remember...
Comment #26
benjy commentedWhy do we need the as SymfonyEvent here? and also I think @dawehners feedback is valid in #24 and then this looks good to me.
Comment #27
neclimdulSo looking deeper, I'm going to say I probably didn't make it abstract because its not abstract and Symfony's Event class isn't abstract either. I'm not sure there's really a point to making it abstract and all it would do is make the test implement an non-abstract implementation.
The reason for extending Symfony's even class is because it contains all the methods expected by dispatchers. There is no interface but you could call it the defacto interface. Also, this is the code we're changing, we where already using it.
Comment #28
benjy commentedI think @neclimdul is right, I was getting confused with the abstract final class that provides the event names, not the event class itself.
Comment #29
tvb commentedI could apply the patch, so no reroll is needed.
Comment #31
mikeryanComment #33
mikeryanComment #34
quietone commentedReroll.
Comment #36
quietone commentedNot sure why a comment test is failing, and this passes locally so retesting.
Comment #37
quietone commentedThats better. Back to needs review.
Comment #38
neclimdulOne little fix to remove @file dockblock. Still applies and works.
Comment #39
neclimdulman I've had a hard time with the issue queue today...
better patches. interdiff vs #34.
Comment #41
phenaproximaMigrations are no longer entities. :) This should also be fixed in the other events while we're at it.
Ditto.
Ditto.
Should we perhaps define constants in MigrateMessageInterface to set the levels?
Needs a description. And why would bool ever be allowed here?
This method has no assertions in it.
Neither does this one.
Comment #42
neclimdulThanks!
4) Yeah it should really follow the PSR-3 logger interface which would define those. I was trying not to leak the scope of this outside of injecting the service.
5)
Got me, that behavior was already defined in the constructor. I just hit ctrl-enter because the property wasn't defined I think. Suggestions on comment welcome.
6 and 7)
These are fine actually, the mocks contain the assertions.
Comment #43
phenaproximaRe #5, how about something like "The row's destination ID"?
And regarding #6 and #7, that's fine as long as there is a comment explaining that.
Comment #44
neclimdulComment #45
phenaproximaI have nits. After these are fixed, this is RTBC from me if it passes Drupal CI.
Can this just be "The migration"?
Nit: extra slash before MigrationInterface
Let's remove the word "current".
Nit: s/migrate/Migrate
I don't think we should say "related", it has strange connotations.
s/migrate/Migrate
Remove |bool type hint.
Let's remove |bool here, I don't think this value will ever be boolean.
Can $destination_id_values be typehinted as an array?
Comment #46
neclimdulAs discussed in IRC, 7-9, no can do. that's all tied to the return value of ::import(). Additionally unrelated to this patch.
Comment #47
phenaproximaI assume this will pass Drupal CI. Thanks for putting up with my persnicketiness. Happily RTBC!
Comment #48
alexpottCommitted e5908d6 and pushed to 8.2.x. Thanks!
Well the documentation still has the "display" thing... I think we should change "display" to "log" here. For the reasons given earlier.
Made these changes on commit because I don't think this is controversial at all.
Coding standards fixed on commit too.