diff --git a/core/modules/ban/migration_templates/d7_blocked_ips.yml b/core/modules/ban/migration_templates/d7_blocked_ips.yml new file mode 100644 index 00000000000..f48f977d8db --- /dev/null +++ b/core/modules/ban/migration_templates/d7_blocked_ips.yml @@ -0,0 +1,10 @@ +id: d7_blocked_ips +label: Drupal 7 blocked IPs +migration_tags: + - Drupal 7 +source: + plugin: d7_blocked_ips +process: + ip: ip +destination: + plugin: blocked_ip diff --git a/core/modules/ban/src/Plugin/migrate/destination/BlockedIp.php b/core/modules/ban/src/Plugin/migrate/destination/BlockedIp.php new file mode 100644 index 00000000000..2ff4a3698fb --- /dev/null +++ b/core/modules/ban/src/Plugin/migrate/destination/BlockedIp.php @@ -0,0 +1,88 @@ +banManager = $ban_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $migration, + $container->get('ban.ip_manager') + ); + } + + /** + * {@inheritdoc} + */ + public function getIds() { + return ['ip' => ['type' => 'string']]; + } + + /** + * {@inheritdoc} + */ + public function fields(MigrationInterface $migration = NULL) { + return [ + 'ip' => $this->t('The blocked IP address.'), + ]; + } + + /** + * {@inheritdoc} + */ + public function import(Row $row, array $old_destination_id_values = array()) { + $this->banManager->banIp($row->getDestinationProperty('ip')); + } + +} diff --git a/core/modules/ban/src/Plugin/migrate/source/d7/BlockedIps.php b/core/modules/ban/src/Plugin/migrate/source/d7/BlockedIps.php new file mode 100644 index 00000000000..71f6678ab1e --- /dev/null +++ b/core/modules/ban/src/Plugin/migrate/source/d7/BlockedIps.php @@ -0,0 +1,45 @@ +select('blocked_ips', 'bi')->fields('bi', ['ip']); + } + + /** + * {@inheritdoc} + */ + public function fields() { + return [ + 'ip' => $this->t('The blocked IP address.'), + ]; + } + + /** + * {@inheritdoc} + */ + public function getIds() { + return ['ip' => ['type' => 'string']]; + } + +} diff --git a/core/modules/ban/src/Tests/d7/MigrateBlockedIPsTest.php b/core/modules/ban/src/Tests/d7/MigrateBlockedIPsTest.php new file mode 100644 index 00000000000..be352d8a922 --- /dev/null +++ b/core/modules/ban/src/Tests/d7/MigrateBlockedIPsTest.php @@ -0,0 +1,46 @@ +installSchema('ban', ['ban_ip']); + $this->loadDumps(['BlockedIps.php']); + $this->executeMigration('d7_blocked_ips'); + } + + /** + * Tests migration of blocked IPs. + */ + public function testBlockedIPs() { + $this->assertTrue(\Drupal::service('ban.ip_manager')->isBanned('111.111.111.111')); + } + +} diff --git a/core/modules/ban/tests/src/Unit/Plugin/migrate/source/d7/BlockedIpsTest.php b/core/modules/ban/tests/src/Unit/Plugin/migrate/source/d7/BlockedIpsTest.php new file mode 100644 index 00000000000..ddfaebaba94 --- /dev/null +++ b/core/modules/ban/tests/src/Unit/Plugin/migrate/source/d7/BlockedIpsTest.php @@ -0,0 +1,49 @@ + 'test', + 'idlist' => [], + 'source' => [ + 'plugin' => 'd7_blocked_ips', + ], + ]; + + protected $expectedResults = [ + [ + 'ip' => '127.0.0.1', + ], + ]; + + /** + * {@inheritdoc} + */ + protected function setUp() { + $this->databaseContents['blocked_ips'] = [ + [ + 'iid' => 1, + 'ip' => '127.0.0.1', + ] + ]; + parent::setUp(); + } + +}