Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
2b9b8d0e
Commit
2b9b8d0e
authored
Aug 04, 2015
by
Angie Byron
Browse files
Issue
#2503049
by phenaproxima, quietone, joelpittet: Migrate D7 blocked IPs to D8
parent
dccbd911
Changes
5
Hide whitespace changes
Inline
Side-by-side
core/modules/ban/migration_templates/d7_blocked_ips.yml
0 → 100644
View file @
2b9b8d0e
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
core/modules/ban/src/Plugin/migrate/destination/BlockedIp.php
0 → 100644
View file @
2b9b8d0e
<?php
/**
* @file
* Contains \Drupal\ban\Plugin\migrate\destination\BlockedIP.
*/
namespace
Drupal\ban\Plugin\migrate\destination
;
use
Drupal\ban\BanIpManagerInterface
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Drupal\migrate\Entity\MigrationInterface
;
use
Drupal\migrate\Plugin\migrate\destination\DestinationBase
;
use
Drupal\migrate\Row
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* Destination for blocked IP addresses.
*
* @MigrateDestination(
* id = "blocked_ip"
* )
*/
class
BlockedIP
extends
DestinationBase
implements
ContainerFactoryPluginInterface
{
/**
* The IP ban manager.
*
* @var \Drupal\ban\BanIpManagerInterface
*/
protected
$banManager
;
/**
* Constructs a BlockedIP object.
*
* @param array $configuration
* Plugin configuration.
* @param string $plugin_id
* The plugin ID.
* @param mixed $plugin_definition
* The plugin definiiton.
* @param \Drupal\migrate\Entity\MigrationInterface $migration
* The current migration.
* @param \Drupal\ban\BanIpManagerInterface $ban_manager
* The IP manager service.
*/
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
,
MigrationInterface
$migration
,
BanIpManagerInterface
$ban_manager
)
{
parent
::
__construct
(
$configuration
,
$plugin_id
,
$plugin_definition
,
$migration
);
$this
->
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'
));
}
}
core/modules/ban/src/Plugin/migrate/source/d7/BlockedIps.php
0 → 100644
View file @
2b9b8d0e
<?php
/**
* @file
* Contains \Drupal\ban\Plugin\migrate\source\d7\BlockedIps.
*/
namespace
Drupal\ban\Plugin\migrate\source\d7
;
use
Drupal\migrate_drupal
\
Plugin\migrate\source\DrupalSqlBase
;
/**
* Drupal 7 blocked IPs from database.
*
* @MigrateSource(
* id = "d7_blocked_ips",
* source_provider = "system"
* )
*/
class
BlockedIps
extends
DrupalSqlBase
{
/**
* {@inheritdoc}
*/
public
function
query
()
{
return
$this
->
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'
]];
}
}
core/modules/ban/src/Tests/Migrate/d7/MigrateBlockedIPsTest.php
0 → 100644
View file @
2b9b8d0e
<?php
/**
* @file
* Contains \Drupal\ban\Tests\Migrate\d7\MigrateBlockedIPsTest.
*/
namespace
Drupal\ban\Tests\Migrate\d7
;
use
Drupal\config\Tests\SchemaCheckTestTrait
;
use
Drupal\migrate_drupal
\
Tests\d7\MigrateDrupal7TestBase
;
/**
* Migrate blocked IPs.
*
* @group ban
*/
class
MigrateBlockedIPsTest
extends
MigrateDrupal7TestBase
{
use
SchemaCheckTestTrait
;
/**
* Modules to enable.
*
* @var array
*/
public
static
$modules
=
[
'ban'
];
/**
* {@inheritdoc}
*/
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
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'
));
}
}
core/modules/ban/tests/src/Unit/Plugin/migrate/source/d7/BlockedIpsTest.php
0 → 100644
View file @
2b9b8d0e
<?php
/**
* @file
* Contains \Drupal\Tests\ban\Unit\Plugin\migrate\source\d7\BlockedIps.
*/
namespace
Drupal\Tests\ban\Unit\Plugin\migrate\source\d7
;
use
Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase
;
/**
* Tests D7 blocked_ip source plugin.
*
* @coversDefaultClass \Drupal\ban\Plugin\migrate\source\d7\BlockedIps
* @group ban
*/
class
BlockedIpsTest
extends
MigrateSqlSourceTestCase
{
const
PLUGIN_CLASS
=
'Drupal\ban\Plugin\migrate\source\d7\BlockedIps'
;
protected
$migrationConfiguration
=
[
'id'
=>
'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
();
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment