Problem/Motivation
Part of #2679929: Reduce method and control structure length/complexity in Migrate UI and a followup for #2683421: Remove incremental and rollback options from the UI (and add them back when they are more stable). MigrateUpgradeRunBatch::run()
includes code paths for two separate operations with long conditionals that only check one of the options for the $operation
parameter.
Proposed resolution
Refactor it so that different explicit methods exist for running the different batches, and remove the $operation
parameter in favor of those explicit methods. It might also be better for there to be two separate batch classes, possibly subclassing a base class.
Remaining tasks
TBD.
User interface changes
N/A
API changes
Internal API change: No more $operation
parameter on the run method, and different methods for different batches (rollback vs. import) or possibly separate subclasses of a Migrate UI batch base class.
Data model changes
N/A.
Comment | File | Size | Author |
---|---|---|---|
#46 | interdiff.txt | 966 bytes | quietone |
#46 | refactor_run_method-2687851-46.patch | 12.44 KB | quietone |
#37 | interdiff.txt | 1.13 KB | quietone |
#37 | refactor_run_method-2687851-37.patch | 12.65 KB | quietone |
#35 | interdiff.txt | 3.31 KB | quietone |
Comments
Comment #2
xjmThis also applies to the
displayResults()
method.Comment #3
quietone CreditAttribution: quietone as a volunteer commentedI've been working on this and should be able to upload a patch in a day or two.
Comment #4
quietone CreditAttribution: quietone as a volunteer commentedTook a bit longer than expected.
Comment #5
quietone CreditAttribution: quietone as a volunteer commentedComment #8
mikeryanComment #9
mikeryanSimple reroll using git diff -M, so it sees MigrateUpgradeImportBatch.php as a rename of MigrateUpgradeRunBatch.php (thus doesn't need to match the entire contents of MigrateUpgradeRunBatch.php to apply). I don't think I lose my RTBC privileges for that...
Tested locally and works fine - I'll RTBC once the tests pass.
Comment #10
mikeryanD'oh! Didn't wait for the full migration to finish running, this is regressing the EntityFile change to source_base_path...
Comment #12
mikeryanOK, fixed up source_base_path.
Comment #16
quietone CreditAttribution: quietone as a volunteer commentedTest failures look unrelated, so retesting.
Comment #17
quietone CreditAttribution: quietone as a volunteer commentedComment #18
mikeryanI kinda feel my last patch here might be a little too much for me to retain RTBC privileges - someone else probably should take a look-see (phenaproxima, benjy, ...).
Comment #19
spesic CreditAttribution: spesic commented#12 fails to apply on core/modules/migrate_drupal_ui/src/MigrateUpgradeRunBatch.php against 8.2.x and 8.2.1
Comment #20
quietone CreditAttribution: quietone as a volunteer commented@spesic, thanks. Here is a reroll.
Comment #21
heddnAssigning to myself to review this.
Comment #22
heddnI'd like to see these moved into a Batch namespace. This is more important with my next comment.
This class is not necessary if we don't implement a single base (abstract) class with two different implementations. One for running import and one for running finish. I think that approach makes more sense, have the abstract base class and two concrete classes for Import and one for Finish, each having a run method.
Const name seems odd. But fixing that doesn't seem in scope. It has been that way for a while.
Could we move the new batch classes into a new Batch namespace? I don't like root level classes.
Comment #23
heddnComment #24
quietone CreditAttribution: quietone as a volunteer commentedTook a few readings of #1, 2 and 4 to grasp your meaning. The attached patch moves MigrateUpgradeBatchBase, MigrateUpgradeImportBatch and MigrateMessageCapture to a new batch namespace. And moves the finish method from MigrateUpgradeImportBatch to a new file MigrateUpgradeImportFinish in the new batch namespace.
And for #3, yes MESSAGE_LENGTH is probably better named something like NUMBER_OF_MESSAGES. The place to change that may be #2569785: Placement of batch progress messages.
Comment #25
mikeryanComment #26
heddnLooks good now. I added a comment over in #2569785: Placement of batch progress messages for #22-3. All other feedback is addressed.
Comment #27
heddnComment #28
catchHaving this in a separate class doesn't seem useful - they'll never be used independently.
Why not rename the method to 'finished' and have it in the same class?
Comment #29
quietone CreditAttribution: quietone as a volunteer commented@catch, that makes sense to me. (Actually, I wondered about that to but did it anyway).
This patch makes the change mentioned in #28, and adds documentation to the finished method.
Comment #30
heddnWith this new approach, I think we can combine/squash the abstract base class, no?
Comment #31
quietone CreditAttribution: quietone as a volunteer commentedI left it as preparation for rollback. Here it is merged.
Comment #33
quietone CreditAttribution: quietone as a volunteer commentedAh, silly fingers named the interdiff incorrectly. Let's try again.
Comment #34
catchShouldn't this also remove the base class?
Comment #35
quietone CreditAttribution: quietone as a volunteer commentedWell, can only say that this is embarrassing.
Comment #37
quietone CreditAttribution: quietone as a volunteer commentedAnd more errors! There must be a 'moral of the story here'. Don't post patches for a few days after a big earthquake? Don't submit a patch before taking son to the airport in the wee hours?
Comment #44
quietone CreditAttribution: quietone as a volunteer commentedAnd even the bot was having trouble.
Tests passing setting to NR.
Comment #45
heddnMostly small stuff. Really, all small stuff. But the first point should be addressed as it violates coding standards.
Me thinks this should still be protected. Or at least implicitly public.
Nit: It seems more natural english to me to say 'batch import' vs 'import batch'.
Not sure if it is in scope, but would renaming 'operations' => 'run' or 'run_batch' make sense? Use your discretion here. I'd be worried about if we would need to wire in a cache clear or something to an update and re-naming to me isn't that important.
Comment #46
quietone CreditAttribution: quietone as a volunteer commented1. Done. I grepped core and $numProcessed is only used in this file.
2. Changed.
3. No discretion here, 'operations' is a required parameter in the array passed to batch_set. https://api.drupal.org/api/drupal/core!includes!form.inc/function/batch_...
Comment #47
heddnComment #50
catchCommitted/pushed to 8.3.x and cherry-picked to 8.2.x. Thanks!