Problem/Motivation

In Drupal 7, actions were part of the System module, which maintained the actions table in the database. In Drupal 8, this has been split out into a core module called Action, and it will need a migration path.

Proposed Resolution

Write a migration which will scan through the contents of the D7 actions table and turn them into the D8 equivalent (config entities?)

Remaining Tasks

  • Write the patch
  • Write tests
  • Review
  • Merge into the parent issue
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikeryan’s picture

Title: Migrate the D7 actions table to D8 » Migrate the D6/D7 actions table to D8

We have a d6_action source plugin currently, but no actual migration of that data is taking place. I doubt there's significant difference between D6 and D7 here, we should be able to do it in one patch.

svendecabooter’s picture

svendecabooter’s picture

Status: Active » Needs work
Issue tags: +Needs tests
FileSize
3.82 KB

First rough attempt at migrating D6 & D7 actions into D8.

Some things to discuss:
* Custom actions in D6 & D7 get a numeric action id (aid). Should we use this as the D8 action machine name as well, or generate the machine name from the label?
* system_block_ip_action from D6 / D7 doesn't seem to exist in D8. In my patch I just skip the migration of this action. Not sure if this is the desired behavior.

phenaproxima’s picture

Custom actions in D6 & D7 get a numeric action id (aid). Should we use this as the D8 action machine name as well, or generate the machine name from the label?

Yes, that would be the preferred way to go; there is a machine_name plugin to help with this.

system_block_ip_action from D6 / D7 doesn't seem to exist in D8. In my patch I just skip the migration of this action. Not sure if this is the desired behavior.

The action may have been moved into the Ban module, so I'd check there first. If it doesn't exist, then yes, we can skip it.

svendecabooter’s picture

Updated version where numeric action IDs get turned into a machine name based on the label.
The action to block IPs doesn't get migrated from D6 & D7, because there is no action plugin in D8 (not in system module, nor ban module).

svendecabooter’s picture

Adding my WIP changes for the tests

svendecabooter’s picture

Might need some help here...

* D7 PHPUnit test doesn't run - getting "No test results to display." (same issue with unit tests as I have in #2500483: Upgrade path for Image 7.x
* D7 migration test: still some things that are failing:
- Something with a missing schema value - haven't figured out yet what's causing this
- Can't find a way to assert the "configuration" settings in the Action config entity. They don't seem to be exposed through a getter. How would I go about checking them?

Once those issues are fixed - I can pretty much copy the tests for D6.

Also: how will we migrate actions that are defined by contrib modules or custom code? Just skip them?

svendecabooter’s picture

Assigned: svendecabooter » Unassigned
FileSize
16.14 KB

Updated patch:
* Fixed PHPUnit errors
* Fixed wrong assertions in D7 MigrateActionsTest

Still have to figure out:
* Why it gives the following schema error:
Schema errors for system.action.unpublish_content_containing_keyword_s_ with the following errors: system.action.unpublish_content_containing_keyword_s_:configuration.keywords missing schema
* Can't find a way to assert the "configuration" settings in the Action config entity. They don't seem to be exposed through a getter. How would I go about checking them?

phenaproxima’s picture

Status: Needs work » Postponed

Why it gives the following schema error:
Schema errors for system.action.unpublish_content_containing_keyword_s_ with the following errors: system.action.unpublish_content_containing_keyword_s_:configuration.keywords missing schema

I looked into this and it turns out it is a tiny bug in the Node module. Issue filed: #2578519: Node has invalid config schema for node_unpublish_by_keyword_action.

Postponing until that lands.

phenaproxima’s picture

Status: Postponed » Needs work

Blocking issue landed.

phenaproxima’s picture

Can't find a way to assert the "configuration" settings in the Action config entity. They don't seem to be exposed through a getter. How would I go about checking them?

If I'm not mistaken, you should be able to get the configuration by calling $action->get('configuration').

svendecabooter’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
15.49 KB

Updated patch:
* Uses new database fixtures to generate test data
* D7 test updated with assertions for $action->get('configuration')
* D6 test added

phenaproxima’s picture

Status: Needs review » Needs work

Great work so far!

  1. +++ b/core/modules/action/migration_templates/d6_action.yml
    @@ -0,0 +1,36 @@
    +destination:
    +  plugin: entity:action
    \ No newline at end of file
    

    Need a new line at the end of the file to please Git :)

  2. +++ b/core/modules/action/migration_templates/d7_action.yml
    @@ -0,0 +1,36 @@
    +id: d7_action
    

    This migration seems virtually identical to d6_action -- can they be merged?

  3. +++ b/core/modules/action/migration_templates/d7_action.yml
    @@ -0,0 +1,36 @@
    +destination:
    +  plugin: entity:action
    \ No newline at end of file
    

    You heard the version control system :)

  4. +++ b/core/modules/action/src/Plugin/migrate/source/d6/Action.php
    @@ -22,16 +24,15 @@ class Action extends DrupalSqlBase {
    -    $query = $this->select('actions', 'a')
    +    return $this->select('actions', 'a')
           ->fields('a', array(
    -        'aid',
    -        'type',
    -        'callback',
    -        'parameters',
    -        'description',
    -      )
    -    );
    -    return $query;
    +          'aid',
    +          'type',
    +          'callback',
    +          'parameters',
    +          'description',
    +        )
    +      );
    

    I'd prefer if we didn't cherry-pick the fields to select -- just select('actions', 'a')->fields('a')

  5. +++ b/core/modules/action/src/Plugin/migrate/source/d7/Action.php
    @@ -0,0 +1,70 @@
    +/**
    + * Drupal 7 action source from database.
    + *
    + * @MigrateSource(
    + *   id = "d7_action",
    + *   source_provider = "system"
    + * )
    + */
    +class Action extends DrupalSqlBase {
    

    At a glance, this also appears nearly identical to the D6 version. Can they be generalized?

  6. +++ b/core/modules/action/src/Tests/Migrate/d7/MigrateActionsTest.php
    @@ -0,0 +1,82 @@
    +    $this->assertIdentical(22, count($plugin_definitions));
    

    I don't think this assertion adds much value; it's OK to remove it.

  7. +++ b/core/modules/action/src/Tests/Migrate/d7/MigrateActionsTest.php
    @@ -0,0 +1,82 @@
    +   * Asserts various aspects of an Action entity
    

    Needs a period at the end of the sentence.

  8. +++ b/core/modules/action/src/Tests/Migrate/d7/MigrateActionsTest.php
    @@ -0,0 +1,82 @@
    +    $storage = \Drupal::service('entity.manager')->getStorage('action');
    +    $action = $storage->load($id);
    

    This can just be Action::load($id).

  9. +++ b/core/modules/action/src/Tests/Migrate/d7/MigrateActionsTest.php
    @@ -0,0 +1,82 @@
    +    // @TODO: check configuration - there is no method to retrieve that?
    

    $action->get('configuration')

  10. +++ b/core/modules/action/src/Tests/Migrate/d7/MigrateActionsTest.php
    @@ -0,0 +1,82 @@
    +}
    \ No newline at end of file
    

    Whoops :)

svendecabooter’s picture

Status: Needs work » Needs review
FileSize
18.17 KB

* Fixed newline issues
* Consolidated D6 & D7 action source - the only difference is the description field which is called "label" in D7 and "description" in D6.
* Assertion that counts number of actions has been removed.
* Periods added to comments
* @TODO: check configuration was already fixed - guess I uploaded an older patch by accident or something.

I could probably also consolidate d6_action.yml and d7_action.yml into the same file, but then the source property for the description field would need to have the same key in both cases. What's the best approach to do that, since I don't want to mess too much with the source data.

svendecabooter’s picture

Bollocks... still a Git newline missed...
Let's try again

The last submitted patch, 14: migrate_actions-2503047-14.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 15: migrate_actions-2503047-15.patch, failed testing.

svendecabooter’s picture

Status: Needs work » Needs review
FileSize
19.67 KB

Migrate source Unit test also needed updating. Trying again.

svendecabooter’s picture

Issue tags: +rc eligible

Adding this tag - hope that's ok

Status: Needs review » Needs work

The last submitted patch, 18: migrate_actions-2503047-18.patch, failed testing.

svendecabooter’s picture

Status: Needs work » Needs review
FileSize
19.78 KB
quietone’s picture

@svendecabooter, I too would like to know about merging the d6 and d7 yml files. Can someone answer that question, in comment #14?

And other that the two wee edits below, this looks good to me. Not even sure if the question above prevents RTBC.

  1. +++ b/core/modules/action/tests/src/Unit/Plugin/migrate/source/ActionTest.php
    @@ -0,0 +1,73 @@
    +      'parameters' => null,
    +      'description' => null,
    

    I think these should be uppercase.

  2. +++ b/core/modules/action/tests/src/Unit/Plugin/migrate/source/ActionTest.php
    @@ -0,0 +1,73 @@
    +      'parameters' => null,
    +      'description' => null,
    

    And these too.

mikeryan’s picture

Unfortunately, that one discrepancy in source field name does mean we can't use a common config file for both, d6_action and d7_action will need to stay separate.

quietone’s picture

@mikeryan, thank you.

@svendecabooter, I'm still getting used to reviewing, so I looked again and found 2 more items.

  1. +++ b/core/modules/action/src/Tests/Migrate/d6/MigrateActionsTest.php
    @@ -0,0 +1,77 @@
    +  public static $modules = ['action', 'comment', 'node', 'user', 'system'];
    

    MigrateDrupalTestBase enables system and user, so they can be removed.

  2. +++ b/core/modules/action/src/Tests/Migrate/d7/MigrateActionsTest.php
    @@ -0,0 +1,77 @@
    +  public static $modules = ['action', 'comment', 'node', 'user', 'system'];
    

    Same as above.

quietone’s picture

Status: Needs review » Needs work
svendecabooter’s picture

catch’s picture

Priority: Normal » Major
Issue tags: +Migrate D7 critical
quietone’s picture

One more!

  1. +++ b/core/modules/action/src/Tests/Migrate/d7/MigrateActionsTest.php
    @@ -0,0 +1,77 @@
    + * @group action
    

    Should this be migrate_drupal_7?

  2. +++ b/core/modules/action/tests/src/Unit/Plugin/migrate/source/ActionTest.php
    @@ -0,0 +1,73 @@
    + * @group action
    

    Same

svendecabooter’s picture

The @group setting seems to be different for Drupal 6 Migration tests compared to Drupal 7 Migration tests.
Not sure why that's the case, but I based myself on other tests that already made it into core, to keep things consistent.

quietone’s picture

Status: Needs review » Reviewed & tested by the community

@svendecabooter, thx!

Looks like everything has been addressed.

The last submitted patch, 6: migrate_actions-2503047-6.patch, failed testing.

The last submitted patch, 7: migrate_actions-2503047-7.patch, failed testing.

The last submitted patch, 8: migrate_actions-2503047-8.patch, failed testing.

The last submitted patch, 5: migrate_actions-2503047-5.patch, failed testing.

The last submitted patch, 14: migrate_actions-2503047-14.patch, failed testing.

The last submitted patch, 15: migrate_actions-2503047-15.patch, failed testing.

The last submitted patch, 18: migrate_actions-2503047-18.patch, failed testing.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 395c724 and pushed to 8.0.x and 8.1.x. Thanks!

  1. +++ b/core/modules/action/migration_templates/d6_action.yml
    @@ -0,0 +1,39 @@
    +        user_block_ip_action: 0
    
    +++ b/core/modules/action/migration_templates/d7_action.yml
    @@ -0,0 +1,36 @@
    +        system_block_ip_action: 0
    

    It is odd that the Ban module did not add this action.

  2. +++ b/core/modules/action/src/Tests/Migrate/d6/MigrateActionsTest.php
    @@ -0,0 +1,77 @@
    +    /** @var \Drupal\system\Entity/Action $action */
    
    +++ b/core/modules/action/src/Tests/Migrate/d7/MigrateActionsTest.php
    @@ -0,0 +1,77 @@
    +    /** @var \Drupal\system\Entity/Action $action */
    

    Should be \Action not /Action. Fixed on commit.

  • alexpott committed 14cfbd4 on 8.1.x
    Issue #2503047 by svendecabooter, phenaproxima, quietone, mikeryan:...

  • alexpott committed 395c724 on
    Issue #2503047 by svendecabooter, phenaproxima, quietone, mikeryan:...

Status: Fixed » Closed (fixed)

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