Commit 47238ec4 authored by Srishti Bankar's avatar Srishti Bankar Committed by Léo Prada
Browse files

Issue #3256084 by srishti.bankar, narendraR: Migration from D7 to D9

parent b4acaa26
Loading
Loading
Loading
Loading
+49 −0
Changes for migrations/r4032login_settings.yml: 49 added lines, 0 removed lines.
Original line number Diff line number Diff line
id: r4032login_settings
label: Redirect 403 to login configuration
migration_tags:
  - Drupal 7
  - Configuration
source:
  plugin: variable
  variables:
    - r4032login_access_denied_message
    - r4032login_access_denied_message_type
    - r4032login_default_redirect_code
    - r4032login_display_denied_message
    - r4032login_match_noredirect_pages
    - r4032login_redirect_authenticated_users_to
    - r4032login_redirect_to_destination
    - r4032login_user_login_path
  source_module: r4032login
process:
  display_denied_message:
    plugin: static_map
    source: 'r4032login_display_denied_message'
    map:
      1: true
    default_value: false
  access_denied_message: r4032login_access_denied_message
  access_denied_message_type: r4032login_access_denied_message_type
  redirect_authenticated_users_to: r4032login_redirect_authenticated_users_to
  user_login_path:
    plugin: r4032login_path
    source: 'r4032login_user_login_path'
  default_redirect_code:
    plugin: static_map
    source: 'r4032login_default_redirect_code'
    map:
      301: 301
      302: 302
    default_value: 307
  match_noredirect_pages:
    plugin: r4032login_path
    source: 'r4032login_match_noredirect_pages'
  redirect_to_destination:
    plugin: static_map
    source: 'r4032login_redirect_to_destination'
    map:
      1: true
    default_value: false
destination:
  plugin: config
  config_name: r4032login.settings
+33 −0
Changes for src/Plugin/migrate/process/R4032loginPath.php: 33 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\r4032login\Plugin\migrate\process;

use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;

/**
 * Maps D7 r4032login path settings to D9.
 *
 * @MigrateProcessPlugin(
 *   id = "r4032login_path"
 * )
 */
class R4032loginPath extends ProcessPluginBase {

  /**
   * {@inheritdoc}
   */
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    // Adds a leading slash to all the paths.
    $all_paths = '';
    foreach (explode("\r\n", $value) as $path) {
      $trimmed_path = trim($path);
      if ($trimmed_path) {
        $all_paths = $all_paths . '/' . $trimmed_path . "\n";
      }
    }
    return rtrim($all_paths);
  }

}
+180 −0
Changes for tests/fixtures/drupal7.php: 180 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php
// phpcs:ignoreFile
/**
 * @file
 * A database agnostic dump for testing purposes.
 */

use Drupal\Core\Database\Database;

$connection = Database::getConnection();

$connection->schema()->createTable('system', array(
  'fields' => array(
    'filename' => array(
      'type' => 'varchar',
      'not null' => TRUE,
      'length' => '255',
      'default' => '',
    ),
    'name' => array(
      'type' => 'varchar',
      'not null' => TRUE,
      'length' => '255',
      'default' => '',
    ),
    'type' => array(
      'type' => 'varchar',
      'not null' => TRUE,
      'length' => '12',
      'default' => '',
    ),
    'owner' => array(
      'type' => 'varchar',
      'not null' => TRUE,
      'length' => '255',
      'default' => '',
    ),
    'status' => array(
      'type' => 'int',
      'not null' => TRUE,
      'size' => 'normal',
      'default' => '0',
    ),
    'bootstrap' => array(
      'type' => 'int',
      'not null' => TRUE,
      'size' => 'normal',
      'default' => '0',
    ),
    'schema_version' => array(
      'type' => 'int',
      'not null' => TRUE,
      'size' => 'small',
      'default' => '-1',
    ),
    'weight' => array(
      'type' => 'int',
      'not null' => TRUE,
      'size' => 'normal',
      'default' => '0',
    ),
    'info' => array(
      'type' => 'blob',
      'not null' => FALSE,
      'size' => 'normal',
    ),
  ),
  'primary key' => array(
    'filename',
  ),
  'indexes' => array(
    'system_list' => array(
      'status',
      'bootstrap',
      'type',
      'weight',
      'name',
    ),
    'type_name' => array(
      'type',
      'name',
    ),
  ),
  'mysql_character_set' => 'utf8mb3',
));

$connection->insert('system')
->fields(array(
  'filename',
  'name',
  'type',
  'owner',
  'status',
  'bootstrap',
  'schema_version',
  'weight',
  'info',
))
->values(array(
  'filename' => 'modules/system/system.module',
  'name' => 'system',
  'type' => 'module',
  'owner' => '',
  'status' => '1',
  'bootstrap' => '0',
  'schema_version' => '7084',
  'weight' => '0',
  'info' => 'a:14:{s:4:"name";s:6:"System";s:11:"description";s:54:"Handles general site configuration for administrators.";s:7:"package";s:4:"Core";s:7:"version";s:4:"7.82";s:4:"core";s:3:"7.x";s:5:"files";a:6:{i:0;s:19:"system.archiver.inc";i:1;s:15:"system.mail.inc";i:2;s:16:"system.queue.inc";i:3;s:14:"system.tar.inc";i:4;s:18:"system.updater.inc";i:5;s:11:"system.test";}s:8:"required";b:1;s:9:"configure";s:19:"admin/config/system";s:7:"project";s:6:"drupal";s:9:"datestamp";s:10:"1626883669";s:5:"mtime";i:1626883669;s:12:"dependencies";a:0:{}s:3:"php";s:5:"5.2.4";s:9:"bootstrap";i:0;}',
))
->values(array(
  'filename' => 'sites/all/modules/contrib/r4032login/r4032login.module',
  'name' => 'r4032login',
  'type' => 'module',
  'owner' => '',
  'status' => '1',
  'bootstrap' => '0',
  'schema_version' => '7000',
  'weight' => '0',
  'info' => 'a:11:{s:4:"name";s:26:"Redirect 403 to User Login";s:11:"description";s:78:"Redirect anonymous users from 403 Access Denied pages to the /user/login page.";s:4:"core";s:3:"7.x";s:9:"configure";s:36:"admin/config/system/site-information";s:5:"mtime";i:1639728369;s:12:"dependencies";a:0:{}s:7:"package";s:5:"Other";s:7:"version";N;s:3:"php";s:5:"5.2.4";s:5:"files";a:0:{}s:9:"bootstrap";i:0;}',
))
->execute();

$connection->schema()->createTable('variable', array(
  'fields' => array(
    'name' => array(
      'type' => 'varchar',
      'not null' => TRUE,
      'length' => '128',
      'default' => '',
    ),
    'value' => array(
      'type' => 'blob',
      'not null' => TRUE,
      'size' => 'big',
    ),
  ),
  'primary key' => array(
    'name',
  ),
  'mysql_character_set' => 'utf8mb3',
));

$connection->insert('variable')
->fields(array(
  'name',
  'value',
))
->values(array(
  'name' => 'r4032login_access_denied_message',
  'value' => 's:49:"Access denied. You must log in to view this page.";',
))
->values(array(
  'name' => 'r4032login_access_denied_message_type',
  'value' => 's:7:"warning";',
))
->values(array(
  'name' => 'r4032login_default_redirect_code',
  'value' => 's:3:"301";',
))
->values(array(
  'name' => 'r4032login_display_denied_message',
  'value' => 'i:1;',
))
->values(array(
  'name' => 'r4032login_match_noredirect_pages',
  'value' => "s:24:\"blog/*\r\nnode/15\r\nnode/16\";",
))
->values(array(
  'name' => 'r4032login_redirect_authenticated_users_to',
  'value' => 's:7:"<front>";',
))
->values(array(
  'name' => 'r4032login_redirect_to_destination',
  'value' => 'i:1;',
))
->values(array(
  'name' => 'r4032login_user_login_path',
  'value' => 's:10:"user/login";',
))
->execute();
+54 −0
Changes for tests/src/Kernel/R4032loginMigrateTest.php: 54 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\r4032login\Kernel;

use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;

/**
 * Tests r4032login config migration.
 *
 * @group r4032login
 */
class R4032loginMigrateTest extends MigrateDrupal7TestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'r4032login',
  ];

  /**
   * {@inheritdoc}
   */
  protected function getFixtureFilePath() {
    return implode(DIRECTORY_SEPARATOR, [
      \Drupal::service('extension.list.module')->getPath('r4032login'),
      'tests',
      'fixtures',
      'drupal7.php',
    ]);
  }

  /**
   * Asserts that r4032login configuration is migrated.
   */
  public function testR4032loginMigration() {
    $expected_config = [
      'display_denied_message' => TRUE,
      'access_denied_message' => 'Access denied. You must log in to view this page.',
      'access_denied_message_type' => 'warning',
      'redirect_authenticated_users_to' => '<front>',
      'user_login_path' => '/user/login',
      'default_redirect_code' => 301,
      'match_noredirect_pages' => '/blog/*
/node/15
/node/16',
      'redirect_to_destination' => TRUE,
    ];
    $this->executeMigration('r4032login_settings');
    $config = $this->config('r4032login.settings')->getRawData();
    $this->assertSame($expected_config, $config);
  }

}