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.

CommentFileSizeAuthor
#46 interdiff.txt966 bytesquietone
#46 refactor_run_method-2687851-46.patch12.44 KBquietone
#37 interdiff.txt1.13 KBquietone
#37 refactor_run_method-2687851-37.patch12.65 KBquietone
#35 interdiff.txt3.31 KBquietone
#35 refactor_run_method-2687851-35.patch12.74 KBquietone
#33 interdiff-29-33.txt4.05 KBquietone
#33 refactor_run_method-2687851-33.patch16.23 KBquietone
#31 interdiff.patch4.05 KBquietone
#31 refactor_run_method-2687851-31.patch16.23 KBquietone
#29 interdiff.txt19.2 KBquietone
#29 refactor_run_method-2687851-29.patch18.41 KBquietone
#24 interdiff.txt26.29 KBquietone
#24 refactor_run_method-2687851-25.patch28.42 KBquietone
#20 refactor_run_method-2687851-20.patch17.11 KBquietone
#12 interdiff.txt795 bytesmikeryan
#12 refactor_run_method-2687851-12.patch17.55 KBmikeryan
#9 refactor_run_method-2687851-9.patch18.12 KBmikeryan
#4 2687851-4.patch27.23 KBquietone
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

xjm created an issue. See original summary.

xjm’s picture

This also applies to the displayResults() method.

quietone’s picture

Assigned: Unassigned » quietone

I've been working on this and should be able to upload a patch in a day or two.

quietone’s picture

Status: Active » Needs review
FileSize
27.23 KB

Took a bit longer than expected.

quietone’s picture

Assigned: quietone » Unassigned

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Status: Needs review » Needs work

The last submitted patch, 4: 2687851-4.patch, failed testing.

mikeryan’s picture

Version: 8.3.x-dev » 8.2.x-dev
Issue tags: +Needs reroll
mikeryan’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
18.12 KB

Simple 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.

mikeryan’s picture

Status: Needs review » Needs work

D'oh! Didn't wait for the full migration to finish running, this is regressing the EntityFile change to source_base_path...

The last submitted patch, 4: 2687851-4.patch, failed testing.

mikeryan’s picture

Status: Needs work » Needs review
FileSize
17.55 KB
795 bytes

OK, fixed up source_base_path.

The last submitted patch, 9: refactor_run_method-2687851-9.patch, failed testing.

The last submitted patch, 9: refactor_run_method-2687851-9.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 12: refactor_run_method-2687851-12.patch, failed testing.

quietone’s picture

Test failures look unrelated, so retesting.

quietone’s picture

Status: Needs work » Needs review
mikeryan’s picture

I 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, ...).

spesic’s picture

Status: Needs review » Needs work

#12 fails to apply on core/modules/migrate_drupal_ui/src/MigrateUpgradeRunBatch.php against 8.2.x and 8.2.1

quietone’s picture

Status: Needs work » Needs review
FileSize
17.11 KB

@spesic, thanks. Here is a reroll.

heddn’s picture

Assigned: Unassigned » heddn

Assigning to myself to review this.

heddn’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php
    --- /dev/null
    +++ b/core/modules/migrate_drupal_ui/src/MigrateUpgradeBatchBase.php
    
    +++ b/core/modules/migrate_drupal_ui/src/MigrateUpgradeBatchBase.php
    --- /dev/null
    +++ b/core/modules/migrate_drupal_ui/src/MigrateUpgradeImportBatch.php
    

    I'd like to see these moved into a Batch namespace. This is more important with my next comment.

  2. +++ b/core/modules/migrate_drupal_ui/src/MigrateUpgradeBatchBase.php
    @@ -0,0 +1,116 @@
    +abstract class MigrateUpgradeBatchBase {
    

    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.

  3. +++ b/core/modules/migrate_drupal_ui/src/MigrateUpgradeBatchBase.php
    @@ -0,0 +1,116 @@
    +  const MESSAGE_LENGTH = 20;
    

    Const name seems odd. But fixing that doesn't seem in scope. It has been that way for a while.

  4. +++ b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php
    --- /dev/null
    +++ b/core/modules/migrate_drupal_ui/src/MigrateUpgradeBatchBase.php
    

    Could we move the new batch classes into a new Batch namespace? I don't like root level classes.

heddn’s picture

Assigned: heddn » Unassigned
quietone’s picture

Status: Needs work » Needs review
FileSize
28.42 KB
26.29 KB

Took 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.

mikeryan’s picture

Assigned: Unassigned » heddn
heddn’s picture

Status: Needs review » Reviewed & tested by the community

Looks good now. I added a comment over in #2569785: Placement of batch progress messages for #22-3. All other feedback is addressed.

heddn’s picture

Assigned: heddn » Unassigned
catch’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/migrate_drupal_ui/src/Batch/MigrateUpgradeImportFinish.php
@@ -0,0 +1,44 @@
+   * Callback executed when the Migrate Upgrade Import batch process completes.

Having 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?

quietone’s picture

Status: Needs work » Needs review
FileSize
18.41 KB
19.2 KB

@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.

heddn’s picture

Status: Needs review » Needs work
+++ b/core/modules/migrate_drupal_ui/src/Batch/MigrateUpgradeImportBatch.php
@@ -8,76 +8,31 @@
+class MigrateUpgradeImportBatch extends MigrateUpgradeBatchBase {

With this new approach, I think we can combine/squash the abstract base class, no?

quietone’s picture

I left it as preparation for rollback. Here it is merged.

Status: Needs review » Needs work

The last submitted patch, 31: interdiff.patch, failed testing.

quietone’s picture

Status: Needs work » Needs review
FileSize
16.23 KB
4.05 KB

Ah, silly fingers named the interdiff incorrectly. Let's try again.

catch’s picture

Shouldn't this also remove the base class?

quietone’s picture

Well, can only say that this is embarrassing.

Status: Needs review » Needs work

The last submitted patch, 35: refactor_run_method-2687851-35.patch, failed testing.

quietone’s picture

Status: Needs work » Needs review
FileSize
12.65 KB
1.13 KB

And 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?

Status: Needs review » Needs work

The last submitted patch, 37: refactor_run_method-2687851-37.patch, failed testing.

The last submitted patch, 37: refactor_run_method-2687851-37.patch, failed testing.

The last submitted patch, 37: refactor_run_method-2687851-37.patch, failed testing.

The last submitted patch, 37: refactor_run_method-2687851-37.patch, failed testing.

The last submitted patch, 37: refactor_run_method-2687851-37.patch, failed testing.

The last submitted patch, 37: refactor_run_method-2687851-37.patch, failed testing.

quietone’s picture

Status: Needs work » Needs review

And even the bot was having trouble.

Tests passing setting to NR.

heddn’s picture

Status: Needs review » Needs work

Mostly small stuff. Really, all small stuff. But the first point should be addressed as it violates coding standards.

  1. +++ b/core/modules/migrate_drupal_ui/src/Batch/MigrateUpgradeImportBatch.php
    @@ -30,7 +30,7 @@ class MigrateUpgradeRunBatch {
    +  static $numProcessed = 0;
    

    Me thinks this should still be protected. Or at least implicitly public.

  2. +++ b/core/modules/migrate_drupal_ui/src/Batch/MigrateUpgradeImportBatch.php
    @@ -51,33 +51,28 @@ class MigrateUpgradeRunBatch {
    +   * Runs a single migrate import batch.
    

    Nit: It seems more natural english to me to say 'batch import' vs 'import batch'.

  3. +++ b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php
    @@ -1109,13 +1109,12 @@ public function submitConfirmForm(array &$form, FormStateInterface $form_state)
           'operations' => [
    

    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.

quietone’s picture

Status: Needs work » Needs review
FileSize
12.44 KB
966 bytes

1. 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_...

heddn’s picture

Status: Needs review » Reviewed & tested by the community

  • catch committed fee4c4e on 8.3.x
    Issue #2687851 by quietone, mikeryan, heddn, xjm, catch: Refactor run()...

  • catch committed 30ed7a4 on 8.2.x
    Issue #2687851 by quietone, mikeryan, heddn, xjm, catch: Refactor run()...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.3.x and cherry-picked to 8.2.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.