This is a follow up from #2850309-14: Regenerate config entities when using --config-only multiple times..

I found that once you have exported migration files once using the following command:

drush migrate:upgrade --legacy-db-key=ukids7 --legacy-root=sites/default/files  --configure-only

Future runs of the above command (which are needed when you have made changes to the migration files) will keep prefixing upgrade_ to migration files turning out like upgrade_upgrade_d7_dblog_settings.

I discovered that web/core/modules/migrate/src/Plugin/MigrationPluginManager.php::createInstancesByTag() returns not only the core and contrib migrations but also previously exported migrations which are prefixed with "upgrade_". See the following screenshot:

Which then, when exporting configuration, turns into these additional migration files with the upgrade_upgrade_ prefix:

I also found that there is another test in the same class that uses assertEquals(count(), count()) as well so if we change this here we should change it there too for consistency.

Work around

Export config, then remove the extra files from your exported config containing `upgrade_upgrade_ and then import config.

Example:

drush cex
rm *upgrade_upgrade_*.yml 
drush cim

Comments

juampynr created an issue. See original summary.

juampynr’s picture

Status: Active » Needs review
StatusFileSize
new1.43 KB

Here is a patch that fixes it.

juampynr’s picture

Title: migrate-upgrade keep prefixing upgrade_ on subsequent runs » migrate-upgrade keeps prefixing upgrade_ on subsequent runss
heddn’s picture

Would be awful nice to have a test added?

heddn’s picture

also:

src/MigrateUpgradeDrushRunner.php ✗ 1 more
line 525	Type hint "array" missing for $migrations
heddn’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
juampynr’s picture

Title: migrate-upgrade keeps prefixing upgrade_ on subsequent runss » migrate-upgrade keeps prefixing upgrade_ on subsequent runs
aiphes’s picture

juampynr’s picture

Here is an updated patch that includes a test. I am also including a test-only patch.

heddn’s picture

Status: Needs review » Needs work

Just a small nit:

+++ b/tests/src/Kernel/DrushTest.php
@@ -103,6 +103,31 @@ namespace Drupal\Tests\migrate_upgrade\Kernel {
+      $this->assertEquals(count($migrate_plus_migrations_first_run), count($migrate_plus_migrations_second_run));

I think there's an assertCount method in phpunit?

heddn’s picture

Also, looks like phpcs found something:

src/MigrateUpgradeDrushRunner.php ✗
line 449	Expected 1 space after FUNCTION keyword; 0 found
juampynr’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new649 bytes
new2.54 KB

Thanks for the feedback @heddn!

I fixed the coding standards issue. As for the assertCount(), I decided to leave it as it is as it seemed more clear to me. Here is what the patch does:

$this->assertEquals(count($migrate_plus_migrations_first_run), count($migrate_plus_migrations_second_run));

And here is how it should be written using assertCount:

$this->assertCount(count($migrate_plus_migrations_first_run), $migrate_plus_migrations_second_run);

Status: Needs review » Needs work
juampynr’s picture

Status: Needs work » Needs review

Triggered a re-test since I cannot reproduce the PHP warning.

Status: Needs review » Needs work
juampynr’s picture

Can anyone reproduce the warning? I cannot, not even using run_tests.sh.

juampynr’s picture

Status: Needs work » Needs review
damienmckenna’s picture

The question is, what would cause $plugin['plugin'] to be empty? I was able to reproduce it locally and used print_r() to find out what the plugin was:

Array
(
    [map] => Array
        (
            [file] => Array
                (
                    [default] => file_default
                    [url_plain] => file_url_plain
                    [path_plain] => file_url_plain
                    [image_plain] => image
                    [image_nodelink] => image
                    [image_imagelink] => image
                )
            [entityreference] => Array
                (
                    [entityreference_label] => entity_reference_label
                    [entityreference_entity_id] =>entity_reference_entity_id
                    [entityreference_entity_view] =>entity_reference_entity_view
                )
        )
)
damienmckenna’s picture

FWIW I tested with Drush 10, maybe there's a bug that doesn't show in Drush 9?

heddn’s picture

It isn't very clear here what is needed?

heddn’s picture

  protected function modifyId($id) {
    if ((strpos($id, $this->options['migration-prefix']) === 0)) {
      return $id;
    }
    return $this->options['migration-prefix'] . str_replace(':', '_', $id);
  }

This seems like a better solution?

sinasalek’s picture

Applied it against the latest dev and worked. thank you

solideogloria’s picture

Is there a way to remove existing migrations after duplicates with extra prefixes have already been created?

steinmb’s picture

Issue summary: View changes

@solideogloria Added work around to issue summary.

damienmckenna’s picture

StatusFileSize
new3.17 KB

Rerolled.

damienmckenna’s picture

This is the error:

Could not find package drupal/core-composer-scaffold in a version matching ^7.0

Let's see if this covers it.

damienmckenna’s picture

One more try..

damienmckenna’s picture

Is Composer being executed against the project before the patch is applied?

alejo d’s picture

StatusFileSize
new988 bytes

Let's see if this covers it.

alejo d’s picture

StatusFileSize
new3.17 KB

Added tests.

heddn’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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