7c570bb793cc3779f7ee0cf70bf4b15ac4c7dfd4
[yaffs-website] / web / core / modules / ban / src / Plugin / migrate / destination / BlockedIp.php
1 <?php
2
3 namespace Drupal\ban\Plugin\migrate\destination;
4
5 use Drupal\ban\BanIpManagerInterface;
6 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
7 use Drupal\migrate\Plugin\MigrationInterface;
8 use Drupal\migrate\Plugin\migrate\destination\DestinationBase;
9 use Drupal\migrate\Row;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
11
12 /**
13  * Destination for blocked IP addresses.
14  *
15  * @MigrateDestination(
16  *   id = "blocked_ip"
17  * )
18  */
19 class BlockedIP extends DestinationBase implements ContainerFactoryPluginInterface {
20
21   /**
22    * The IP ban manager.
23    *
24    * @var \Drupal\ban\BanIpManagerInterface
25    */
26   protected $banManager;
27
28   /**
29    * Constructs a BlockedIP object.
30    *
31    * @param array $configuration
32    *   Plugin configuration.
33    * @param string $plugin_id
34    *   The plugin ID.
35    * @param mixed $plugin_definition
36    *   The plugin definiiton.
37    * @param \Drupal\migrate\Plugin\MigrationInterface $migration
38    *   The current migration.
39    * @param \Drupal\ban\BanIpManagerInterface $ban_manager
40    *   The IP manager service.
41    */
42   public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, BanIpManagerInterface $ban_manager) {
43     parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
44     $this->banManager = $ban_manager;
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
51     return new static(
52       $configuration,
53       $plugin_id,
54       $plugin_definition,
55       $migration,
56       $container->get('ban.ip_manager')
57     );
58   }
59
60   /**
61    * {@inheritdoc}
62    */
63   public function getIds() {
64     return ['ip' => ['type' => 'string']];
65   }
66
67   /**
68    * {@inheritdoc}
69    */
70   public function fields(MigrationInterface $migration = NULL) {
71     return [
72       'ip' => $this->t('The blocked IP address.'),
73     ];
74   }
75
76   /**
77    * {@inheritdoc}
78    */
79   public function import(Row $row, array $old_destination_id_values = []) {
80     $this->banManager->banIp($row->getDestinationProperty('ip'));
81   }
82
83 }