Problem/Motivation
We are now double maintaining our Drush commands - Drush 8 and Drush 9. Let's move more logic into a shared CLI service so that duplicate code mostly eliminated.
Proposed resolution
Follow outline in this blog post from Nuvole as recommended by @moshe-weitzman
Remaining tasks
Create service for carrying out drush commands so logic can be consolidated in one place.Create stub functions for each migrate task in that service.Prove the service is usable by porting the Drush 9 migrate-import command to it.- Adapt the service to be usable by Drush 8 for the same command.
- Now the approach works, implement this approach for the remaining commands
- status
- rollback
- stop
- resetStatus
- messages
- fieldsSource
User interface changes
None
API changes
None
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | interdiff.txt | 14.87 KB | quietone |
| #11 | 2921721_11_start_drush_8_import_support.patch | 28.72 KB | quietone |
| #10 | interdiff_2921721_7_10.txt | 2.61 KB | eli-t |
| #10 | 2921721_10_start_drush_8_import_support.patch | 14.99 KB | eli-t |
| #7 | interdiff_2921721_4_7.txt | 3.9 KB | eli-t |
Comments
Comment #2
ressaFixed the link.
Comment #3
eli-tTentative start to this approach.
This patch provides a service for drush commands based on the approach linked in the summary. It provides a service with name migrate_tools.cli in the class Drupal\migrate_tools\MigrateToolsCliService.
This class has stub methods for each of the commands provided by migrate tools. The method for import() is implemented, and called from the Drush 9 command class. This can run a migration in this way, but does not output to the screen as I haven't passed through the drush logger yet.
Next steps should be to pass through the drush logger for drush 9, and get the same service method called from drush 8. Then fill in the other methods. Then profit.
Comment #4
eli-t#3 was missing the constructor to inject the Migration Plugin Manager to the CLI service. This fixes that, and passes the logger Drush injects to the Command class to the CLI service before calling import(). So we get the same output to the screen as we did before refactoring to a service.
Comment #5
heddnSome preliminary suggestions:
Can we do array merging after passing this into import? I really don't like to see functions names span across multiple lines.
I find it easier to read if these are on a single line.
Same here.
Same line maybe?
Comment #6
eli-tThe split lines are just inherited from the equivalent existing code in the MigrateToolsCommands class, so I left them as they were so it was easier to eyeball any differences. But that doesn't mean we can't fix them as we move them, and I agree that they are better unsplit.
Comment #7
eli-tJust addressing the points from #5 - still lots to do.
Comment #8
quietone commented@Eli-T, can you elaborate on 'still lots to do'? Maybe even some small steps or pieces. I'd like to help but not sure what needs to be done next here.
Comment #9
eli-tComment #10
eli-t@quietone that's awesome! I've just updated the issue summary in the standard template so we can clearly detail the approach I was taking and where it was up to.
The tasks struck off in the summary reflect the status of the patch in #7.
I started to work on the next task - getting Drush 8 to run an import through the service - work in progress in patch uploaded in this comment.
The migrate() method on the MigrateToolsCliService is set to be used by Drush 8, but the MigrateToolsCliService class is attempted to be constructed with the Drush 9 logger, which is NULL, so it falls over.
So next step is to either look at that, or flesh out the other methods in Drush 9 land.
Hope that makes sense, if not, hit me up in Slack and I'll try to clarify.
Comment #11
quietone commented@Eli-T, thanks for the details. It is late so I opted to keep it simple and used the existing migrate-import changes to convert stop, resetStatus, messages and fieldSource.
Comment #12
heddnWith the work going into https://github.com/drush-ops/drush/issues/2926 and more specifically the plan in https://github.com/drush-ops/drush/pull/3402... I not sure we need to keep working on things here.
Comment #13
eli-tThanks for the heads up @heddn - I agree, there is little point working on this whilst it looks like it will be removed. Changing status to postponed for now.
Comment #14
marvil07 commentedThis ticket was posponed pending on a possible drush upstrean inclusion, but the it was decided that will not be the case by drush maintainers.
Comment #20
heddnWe no longer have 2 code streams for drush commands. So I think this issue has served its purpose.