Problem/Motivation

Migrate session limit configuration from Drupal 7 site to Drupal 9 site.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

srishti.bankar created an issue. See original summary.

srishtiiee’s picture

Status: Needs work » Needs review
FileSize
6.79 KB
srishtiiee’s picture

Version: 2.0.0-beta2 » 2.x-dev

Status: Needs review » Needs work

The last submitted patch, 2: session_limit_migration_3253469-2.patch, failed testing. View results

srishtiiee’s picture

Status: Needs work » Needs review
FileSize
6.79 KB

Changed test name.

Status: Needs review » Needs work

The last submitted patch, 5: session_limit_migration_3253469-5.patch, failed testing. View results

Wim Leers’s picture

Is there no equivalent D7 configuration for session_limit_masquerade_ignore and session_limit_roles config in the D9 port? 🤔

/me checks:

  1. session_limit_masquerade_ignorehttps://git.drupalcode.org/project/session_limit/-/blob/7.x-2.3/session_...
  2. session_limit_rolessession_limit_rid_*https://git.drupalcode.org/project/session_limit/-/blob/7.x-2.3/session_...

So marking Needs work for those. Note that the latter means this migration will need an optional dependency on d7_user_role.

srishtiiee’s picture

srishtiiee’s picture

Status: Needs work » Needs review
Wim Leers’s picture

Status: Needs review » Needs work
  1. +++ b/tests/src/Kernel/SessionLimitMigrateTest.php
    @@ -0,0 +1,75 @@
    +namespace Drupal\Tests\session_limit\Kernel\d7;
    

    The test does not get executed or even found by DrupalCI. Why? 🤔

    Aha, this namespace does not match the directory structure, I think that's why!

  2. +++ b/src/Plugin/migrate/process/SessionLimitConfig.php
    @@ -0,0 +1,87 @@
    + * Maps D7 session limit user config to D9.
    ...
    + *   id = "session_limit_config"
    ...
    +class SessionLimitConfig extends ProcessPluginBase implements ContainerFactoryPluginInterface {
    

    This makes it seem like it's processing/transforming all/arbitrary session limit (user) config.

    But it's not.

    It's only for session_limit_roles.

    So let's call this something like session_limit_rid_variables_to_roles_array — more detailed, more specific, but that's also exactly what it does :)

  3. +++ b/src/Plugin/migrate/process/SessionLimitConfig.php
    @@ -0,0 +1,87 @@
    +   * Constructs a MenuLinkParent object.
    

    Copy/paste remnant 🤓😅

  4. +++ b/src/Plugin/migrate/process/SessionLimitConfig.php
    @@ -0,0 +1,87 @@
    +        $rid = explode("_", $key);
    

    $rid is an array, not a role ID like its name suggests.

    [,,$rid] = explode(…);
    would be simpler.

    See https://3v4l.org/86BMi

  5. +++ b/src/Plugin/migrate/source/SessionLimit.php
    @@ -0,0 +1,49 @@
    +  public function prepareRow(Row $row) {
    +    $rids = $this->select('variable', 'v')
    +      ->fields('v')
    +      ->condition('v.name', 'session_limit_rid_%', 'LIKE')
    +      ->execute();
    +    foreach ($rids as $item) {
    +      $row->setSourceProperty($item['name'], unserialize($item['value']));
    +    }
    +    return parent::prepareRow($row);
    +  }
    +
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityTypeManagerInterface $entity_type_manager) {
    +    $configuration['variables'] = [
    +      'session_limit_max',
    +      'session_limit_masquerade_ignore',
    +      'session_limit_behaviour',
    +      'session_limit_logged_out_message_severity',
    +      'session_limit_include_root_user',
    +    ];
    +    parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_type_manager);
    +  }
    

    I'm a bit confused by this.

    The $configuration['variables'] = … explicitly loads 5 variables.

    But then in ::prepareRow() for every one of these 5 variables, it seems to perform a DB query against the variable table and overrides what's in the row.

    I think we should try to generate a unique row and then do the necessary processing only on that one row.

    Can you check how many times the DB query in ::prepareRow() is executed? I suspect it gets executed 5 times, once for each of the 5 variables listed in $configuration['variables'] = ….

    Let's pair on figuring out a better way for this.

srishtiiee’s picture

Status: Needs work » Needs review
FileSize
23.91 KB
5.04 KB

Addressed all issues in #10.
Pt.5- prepareRow() gets called only once and adds variables related to user roles by querying the variable table along with the variables listed in $configuration['variables'] = …

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

RE: point 5: ahhhh, you're right! I'd forgotten! You can see this in \Drupal\migrate_drupal\Plugin\migrate\source\Variable::doCount(): it always returns count 1! 👍

I have only nits, which can be addressed upon commit by the maintainer:

  1. +++ b/migrations/session_limit_settings.yml
    @@ -0,0 +1,21 @@
    +migration_dependencies:
    +  optional:
    +    - d7_user_role
    

    Nit: We should make this a required dependency; without the roles existing, we can't do a lookup.

    It will work correctly without this change though, because essentially every site will execute d7_user_role. Still, better to be more precise.

  2. +++ b/src/Plugin/migrate/process/SessionLimitRidVariablesToRolesArray.php
    @@ -14,10 +14,10 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
    +class SessionLimitRidVariablesToRolesArray extends ProcessPluginBase implements ContainerFactoryPluginInterface {
    
    @@ -34,7 +34,7 @@ class SessionLimitConfig extends ProcessPluginBase implements ContainerFactoryPl
    +   * Constructs a SesionLimit object.
    

    s/SessionLimit/SessionLimitRidVariablesToRolesArray/

  3. +++ b/src/Plugin/migrate/source/SessionLimit.php
    @@ -0,0 +1,52 @@
    +   * Prepares a single row containing variables to be mapped directly and
    +   * queries variable table for user role related settings.
    

    Nit: The comment must always be a single line. And we can't both "inherit doc" and write docs.

    So … let's move this into the method. 🤓