View source
<?php
namespace Drupal\forum_access_migrate\Plugin\migrate\destination;
use Drupal\Core\Database\Connection;
use Drupal\Core\Database\Database;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row;
use Drupal\migrate_plus\Plugin\migrate\destination\Table;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ForumAccess extends Table {
protected $tableName;
protected $idFields;
protected $fields;
protected $dbConnection;
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, Connection $connection) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $connection);
$this->dbConnection = $connection;
$this->tableName = 'forum_access';
$this->idFields = [
'tid' => [
'type' => 'integer',
],
'rid' => [
'type' => 'string',
],
];
$this->fields = [];
$this->supportsRollback = TRUE;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
$db_key = !empty($configuration['database_key']) ? $configuration['database_key'] : NULL;
return new static($configuration, $plugin_id, $plugin_definition, $migration, Database::getConnection('default', $db_key));
}
public function import(Row $row, array $old_destination_id_values = []) {
module_load_include('inc', 'forum_access', 'includes/forum_access.acl');
$tid = $row
->getSourceProperty('tid');
$moderators = $row
->getSourceProperty('moderators');
if (!empty($moderators)) {
$acl_id = forum_access_get_acl($tid, 'moderate');
foreach ($moderators as $uid) {
acl_add_user($acl_id, $uid);
}
}
return parent::import($row, $old_destination_id_values);
}
}