Commit 3bbd7a97 authored by Srishti Bankar's avatar Srishti Bankar Committed by Sascha Grossenbacher
Browse files

Issue #3253034 by srishtiiee: Migration from D7 to D9

parent 52daac98
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
id: mail_system_settings
label: Mail system configuration
migration_tags:
  - Drupal 7
  - Configuration
source:
  plugin: variable
  variables:
    - mailsystem_theme
    - mail_system
  source_module: mailsystem
process:
  theme: mailsystem_theme
  defaults/sender:
    plugin: static_map
    source: 'mail_system/default-system'
    map:
      TestingMailSystem: test_mail_collector
    default_value: php_mail
  defaults/formatter: '@defaults/sender'
  modules:
    plugin: mailsystem_modules
    source: mail_system
destination:
  plugin: config
  config_name: mailsystem.settings
+44 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\mailsystem\Plugin\migrate\process;

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

/**
 * Maps D7 mail system settings to D9 settings.
 *
 * @MigrateProcessPlugin(
 *   id = "mailsystem_modules",
 *   handle_multiples = true
 * )
 */
class MailSystemModules extends ProcessPluginBase {

  /**
   * {@inheritdoc}
   */
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    // The "default-system" key-value pair is not for a module-specific
    // migration, but for the default. This is already handled elsewhere in the
    // migration process pipeline ("defaults/sender" and "defaults/formatter").
    unset($value['default-system']);
    foreach ($value as $key => $data) {
      [$module, $index] = explode("_", $key);
      if (\Drupal::moduleHandler()->moduleExists($module)) {
        if ($data == 'DefaultMailSystem') {
          $data = 'php_mail';
        }
        else {
          $data = 'test_mail_collector';
        }
        $value[$module][$index]['formatter'] = $data;
        $value[$module][$index]['sender'] = $data;
      }
      unset($value[$key]);
    }
    return $value;
  }

}
+156 −0
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' => 'sites/all/modules/contrib/mailsystem/mailsystem.module',
  'name' => 'mailsystem',
  'type' => 'module',
  'owner' => '',
  'status' => '1',
  'bootstrap' => '0',
  'schema_version' => '0',
  'weight' => '0',
  'info' => 'a:11:{s:7:"package";s:4:"Mail";s:4:"name";s:11:"Mail System";s:11:"description";s:77:"Provides a user interface for per-module and site-wide mail_system selection.";s:4:"core";s:3:"7.x";s:9:"configure";s:30:"admin/config/system/mailsystem";s:12:"dependencies";a:1:{i:0;s:6:"filter";}s:5:"mtime";i:1638344276;s:7:"version";N;s:3:"php";s:5:"5.2.4";s:5:"files";a:0:{}s:9:"bootstrap";i:0;}',
))
->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;}',
))
->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' => 'mailsystem_theme',
  'value' => 's:7:"default";',
))
->values(array(
  'name' => 'mail_system',
  'value' => 'a:4:{s:14:"default-system";s:17:"TestingMailSystem";s:10:"color_1111";s:17:"DefaultMailSystem";s:9:"date_4321";s:17:"DefaultMailSystem";s:10:"system_123";s:17:"TestingMailSystem";}',
))
->execute();
+65 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\mailsystem\Kernel\d7;

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

/**
 * Tests mail system migration.
 *
 * @group mailsystem
 */
class MailSystemMigrateTest extends MigrateDrupal7TestBase {

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

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

  /**
   * Asserts that mail system configuration is migrated.
   */
  public function testMailSystemMigration() {
    $expected_config = [
      'theme' => 'default',
      'defaults' => [
        'sender' => 'test_mail_collector',
        'formatter' => 'test_mail_collector',
      ],
      'modules' => [
        'color' => [
          '1111' => [
            'formatter' => 'php_mail',
            'sender' => 'php_mail',
          ],
        ],
        'system' => [
          '123' => [
            'formatter' => 'test_mail_collector',
            'sender' => 'test_mail_collector',
          ],
        ],
      ],
    ];
    $this->executeMigration('mail_system_settings');
    $config_after = $this->config('mailsystem.settings')->getRawData();
    $this->assertSame($expected_config, $config_after);

  }

}