Closed (fixed)
Project:
Migrate Tools
Version:
8.x-4.x-dev
Component:
Drush commands
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
5 Oct 2017 at 05:46 UTC
Updated:
22 Nov 2017 at 08:09 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
pcambraHappy to move this patch forward when there's feedback.
Comment #3
FredCorreia commentedHello,
Thanks for this patch. We use drush 9 too wo we really need this for the beta5 version.
I think you forgot to replace just one drush_log by $this->logger on line 74 of MigrateToolsCommand.php
Comment #4
pcambraGood catch, thanks, here's the fix
Comment #6
moshe weitzman commentedThanks so much for doing this! I have received requests for these commands.
$this->logger()->info(dt('No migrations found.'), 'error');. The error part at the end is a mistake I think.Comment #7
bpresles commentedThis patch doesn't work for me.
1) If I use the "mi" alias instead of "migrate-import": drush mi --group=[group_name] it says:
[error] You must specify --all, --group, --tag or one or more migration names separated by commas
2) If I use the complete command with --group or even --all: drush migrate-import --all or drush migrate-import --group=[group_name], it says:
[error] You must specify --all, --group, --tag or one or more migration names separated by commas
Versions:
Drush 9.0.0-beta5
Drupal 8.4-rc2
Migrate_Tools: Tested with 4.0.0-beta1 and 4.x-dev patched with patch #4
Comment #8
moshe weitzman commentedCommands should be renamed to
@command migrate:status. Then add an alias to the original name:@aliases mi,migrate-status. I will update the generator for this.Comment #9
bpresles commentedHere is a new patch. For now I didn't replace any drush_log('', 'error') by Exception (but I replaced drush_set_error() calls by Exception as recommended by Drush portng doc), just by $this->logger()->error(), but feel free to do so for a future patch.
Comment #10
bpresles commentedSorry bad patch on previous comment.
Btw, I replaced "mi" alias for migrate:import (or migrate-import) by "mim", as "mi" is considered ambiguous with all the migrate: commands by Drush 9.
Comment #11
bpresles commentedComment #12
francescoben commentedHi guys,
thanks for your work but last patch doesn't work for me, when I run `migrate:status` I can't see any migrations.
In the method
migrationsListI replaced the serviceplugin.manager.migrationwithplugin.manager.config_entity_migrationthat is the one used by the old drush commands.With this service all commands work as expected and I can list/import/revert my migrations.
Drush 9.0.0-beta5
Drupal 8.4.0
Migrate_Tools: Tested with 4.0.0-beta1/4.x-dev patched with patch #10
Comment #13
pcambraPlease add a interdiff if you change parts of the patches, it makes it so much easier to follow the variations.
Regarding #12, patch in #4 worked for status, I think the missing parts were the drush_set_option to options, I need to reapply the whole thing to check it, will try to do it next week if someone else doesn't do it earlier
Comment #14
bpresles commented@fancescoben
In which version of original Drush commands did you see that the service used on drush_migrate_tools_migration_list() was "plugin.manager.config_entity_migration" and not "plugin.manager.migration".
I checked on both latest GIT code and beta1 archive and on both the service used in this function is "plugin.manager.migration". In fact I just did a simple copy/paster from this function and applied port instructions to it to create the migrationsList method:
On my side #10 works for status on both beta1 and 4.x-dev with Drupal 8.4.0. Are you you are on Drupal 8.4 or even 8.3.x ? The service plugin.manager.config_entity_migration has been removed from Drupal Core since 8.3.5 (if I remember correctly) and replaced by plugin.manager.migration.
So your patch is not valid for unpatched Drupal 8.3.5+ core.
Btw, I prepare a new version of my Patch with dependency injection (instead of using \Drupal::service()).
Comment #15
sebastixPatch #12 does not work, I got this error:
[error] You have requested a non-existent service "plugin.manager.config_entity_migration".Patch #10 does work for me.
Comment #16
bpresles commentedHere a new version of my patch with the following changes:
Comment #17
goz commentedYou should use entity type manager to load entities
i think it could be more readable on one line
same thing here, no needs to mulitiple lines
same thing here. There is a lot of things like that. Do not make a new line each time you call a function.
Comment #18
bpresles commentedNew patch version taking code review comments in account. There will probably still be some formatting stuff, but I had applied PHPStorm reformat action that (stupidly) apply Drupal coding standards.
Comment #19
moshe weitzman commented@bpresles - my suggestion is to make the output of these commands less dynamic. You might need to break them into multiple commands. i have not looked into it.
Comment #20
bpresles commentedI uploaded the interdiff of patches (between #10 and #15-2, and between #15-2 and #18).
Comment #21
mpp commentedThe patch in #18 does the job but with some notices:
Notice: Undefined index: execute-dependencies in MigrateToolsCommands.php on line 673Comment #23
claudiu.cristeaWe should call the parent constructor even, right now, that one is doing nothing.
Right now we are duplicating code from the the legacy
migrate_tools.drush.inc. This is hard to maintain. IMO, we should deprecate the procedural functions. For example:Same for all commands. Then we would face the problem with the message logger because we need a different one for drush < 9. My suggestion would be to add
protected $migrateMessageproperty and set it in constructorWhen the BC layer will be removed, we remove also this part and we inject the log service.
EDIT: Lately, I found that
$this->logger()returns nothing in this stage. Weird.EDIT2: Then we can use this lazy getter:
Comment #24
mpp commentedHi @claudiu.cristea, not sure why you've hidden patch #21 as it fixed a trivial error notice.
I added the remarks you made in #23. Instead of doing the private method perhaps we could inject the logger in the command?
Marking for tests.
Comment #26
mpp commentedForgot a use statement, added now.
Comment #28
claudiu.cristeaThis function was kind of "protected" (a helper) and we don't need to keep it anymore. Anyway a call to a service protected method would have failed.
We pass
$migration_id, right?Again, how is suppose to work this call to a protected method? This function is also an internal/helper we should remove it from there.
I wonder if the group name is placed in the correct position, given that all the rows are grouped together. Shouldn't the group be also a row (I don't know if we can do rowspan)?
We are using this method at least in 3 Drush commands, so let's move it after the commands, just before executeMigration().
This looks too dynamic.
EDIT: Please use .txt for interdiff so it won't get tested. Please read https://www.drupal.org/documentation/git/interdiff on how to create an interdiff.
Comment #29
claudiu.cristeaMore...
This is wrong because we'll not benefit from 'names-only' speed. We should move
if ($names_only) {...}outside so we don't parse the migration statistics if we don't need them. We only output the migration ID, right?EDIT: And more...
We directly output the exception message and also drop that to the logger?
EDIT2: additional
The key-value store service should be injected too.
Comment #30
bpresles commentedUsing the Drush 9 Commands class in .drush.inc seems to be a good idea at first, but the fact is with Drush 8 the service declared in drush.servcices.yml won't be detected and usable at all. As well as the "Drush\Commands\DrushCommands" and "Drush\Drush" classes don't exist at all.
So the migrate_tools.drush.inc should be kept as is without any modification from its original version.
Comment #31
bpresles commentedFind attached a new patch with the following changes:
- Injecting KeyValue store service.
- Added column "Group" to the Status table.
- Removed the $this->output->writeln($e->getMessage()) in status() method.
- Calculating the migrations statistics only if the names-only options is not passed.
- Moved migrationsList() method just before executeMigration() method.
- Rewritten Drush9LogMigrateMessage class so that it extends the MigrateMessage class and work similarly except that it uses the logger instance passed in the constructor (instead of the default 'migrate' logger)
- Reverted the migrate_tools.drush.inc file completely as using the Drush 9 Commands service won't work on Drush 8 at all. This may mean code duplication, but the drush.inc file is just a legacy file only kept for now for Drush 8 compatibility and so doesn't need to be maintained and will be removed anyway at the end.
Comment #32
bpresles commentedComment #33
bpresles commentedNew patch with the following changes:
Comment #34
pobster commentedThere's a tiny typo in your patch, you've got the "mi" alias in as "mim".
Comment #35
goz commented@pobster i think you miss the #10 comment
You should add a diff when you post a patch so we can see your changes.
#34 should be ignored in favour of #33
Comment #36
pobster commentedAn interdiff is a courtesy, not a requirement. Regardless of what way round it was, you shouldn't change the alias in one place and not the other ~ if you're going to change an alias, then change the alias for everyone. It's only going to lead to confusion where it differs.
Comment #37
pobster commentedBugger, ignore that one ~ I committed the patch by mistake... This instead.
Comment #38
bpresles commented@pobster
I didn't change the alias in the drush.inc legacy file, because it's a legacy file and so should not break compatibility with current users. Current users, in Drush 8, use "mi" as alias for migrate-import.
So I changed the alias in new Drush 9 commands class, as users will expect possible changes/new stuff because of Drush 9. So in my pint of view, changing the alias in legacy .drush.inc file is not a good idea and it should only be done on new Drush 9 commands class. Just my point of view.
Comment #39
pobster commentedHa, since when did Drupal ever worry about backwards compatibility?!
I'd consider it more breaking to be using a module, and for a drush command to break simply by updating the version of drush which is installed. You wouldn't expect updating drush to cause that kind of mayhem? Far better to have a command "break" when you update the related module, at least then your automated pipelines don't have such mysterious failures ~ especially in cases where a developer could test something on their machine, and yet once deployed the server might see failures due to the difference. It's far, far, far better to simply break it here first ~ it's the typical Drupal "ripping off the band-aid" approach to updates. After all ... this is exactly the reason you have to make this change in the first place right? You have an exact match on the command you're attempting to run, and yet you can't run it due to updates in drush which don't care about breaking backwards compatibility.
TL:DR; Drupal doesn't give a toss about legacy ;o)
Comment #40
bpresles commented@pobster
Major releases of Drupal don't care about backward compatibility, but minor releases do. That's why there are a lot of deprecated APIs on Drupal 8 (even deprecated API from alpha/beta or dev versions of Drupal 8) that will survive all the life span of Drupal 8 (so until Drupal 9).
As for the migrate_tools.drush.inc file, at the end this file will be removed all together, it's only useful for Drush 8 (it's totally ignored by Drush 9), and so replacing the alias for migrate-import is not a good idea. Adding the new "mim" alias to the existing "mi" one is ok though, but not replacing it altogether.
Breaking the compatibility for a major release is not a problem, as it's expected and generally practiced on the software industry (this is what Drupal, Drush, Symfony and most software projects do). But updating an old API (here drush 8 commands) to reflect a new one, breaking compatibility with old usage is not common at all (if not never seen) and is a bad practice.
In a nutshell: You may ADD the "mim" alias in the migrate_tools.drush.inc file, in addition to the "mi" existing one and display a deprecated messaged when "mi" is used, for helping to the transition, but removing the "mi" alias altogether to replace it by the new one, in this legacy .drush.inc file is clearly not a good idea.
I'll post a patch that does just that (add the "mim" alias additionally to the existing "mi" one and display a deprecated message when the "mi" alias is used).
Comment #41
bpresles commentedHere the patch with the following changes:
- Puts back the "mi" alias alongside the new one "mim" on migrate_tools.drush.inc.
- Display a "The 'mi' alias is deprecated and will no longer work with Drush 9. Consider the use of 'mim' alias instead." message if 'mi' is used.
Comment #42
pobster commentedFrom over the years using Drupal I can give you probably more than a dozen instances where this isn't true, but sure ~ your spirit hasn't been broken yet, so let's just keep it that way ;o) Anyways, the patch looks good to me ~ thanks for your update.
Comment #43
agoradesign commented@bpresles
The patch basically works for me without any problems so far, despite a tiny drawback:
I was used to write "mi" for starting imports and tried to do so. But I didn't get a deprecation notice, instead it just didn't work:
Comment #44
agoradesign commentedPS: I haven't tried a plain "drush mi" call for running all updates, I trigger them individually by ID, like "drush mi db_spareparts --update". Now instead, I have to use "drush migrate-import db_spareparts --update", but that's ok for me
Comment #45
moshe weitzman commentedThats Synfony console being annoying. Not much we can do, beside pick another brief alias that it likes better. Maybe
mim?Comment #46
moshe weitzman commentedNow I see that the patch already declared mim alias and shows a deprecation message for drush8 users when they use mi. Nice work!
I could only find one minor issue whuch we can fix whenever -
$this->logger->error(dt('No migrations found.'));. That should be the method logger() [with parenthesis], not the property.Comment #48
moshe weitzman commentedAfter talking with heddn, we decided to merge the latest patch. Drush9 users rejoice!
This merge increased the maintenance burden for our Drush commands, by duplicating some code/logic. Please help out at #2921721: Consolidate CLI functionality into a service in order to get this in good shape.
Comment #49
agoradesign commentedGreat! Is there a new beta planned? Would be nice to have this released asap