3 namespace Drupal\statistics\Plugin\migrate\destination;
5 use Drupal\Core\Database\Connection;
6 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
7 use Drupal\migrate\Plugin\migrate\destination\DestinationBase;
8 use Drupal\migrate\Plugin\MigrationInterface;
9 use Drupal\migrate\Row;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
13 * Destination for node counter.
15 * @MigrateDestination(
16 * id = "node_counter",
17 * destination_module = "statistics"
20 class NodeCounter extends DestinationBase implements ContainerFactoryPluginInterface {
23 * The database connection.
25 * @var \Drupal\Core\Database\Connection
27 protected $connection;
30 * Constructs a node counter plugin.
32 * @param array $configuration
33 * Plugin configuration.
34 * @param string $plugin_id
36 * @param mixed $plugin_definition
37 * The plugin definition.
38 * @param \Drupal\migrate\Plugin\MigrationInterface $migration
39 * The current migration.
40 * @param \Drupal\Core\Database\Connection $connection
41 * The database connection.
43 public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, Connection $connection) {
44 parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
45 $this->connection = $connection;
51 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
57 $container->get('database')
64 public function getIds() {
65 return ['nid' => ['type' => 'integer']];
71 public function fields(MigrationInterface $migration = NULL) {
73 'nid' => $this->t('The ID of the node to which these statistics apply.'),
74 'totalcount' => $this->t('The total number of times the node has been viewed.'),
75 'daycount' => $this->t('The total number of times the node has been viewed today.'),
76 'timestamp' => $this->t('The most recent time the node has been viewed.'),
83 public function import(Row $row, array $old_destination_id_values = []) {
85 ->insert('node_counter')
87 'nid' => $row->getDestinationProperty('nid'),
88 'daycount' => $row->getDestinationProperty('daycount'),
89 'totalcount' => $row->getDestinationProperty('totalcount'),
90 'timestamp' => $row->getDestinationProperty('timestamp'),
93 return [$row->getDestinationProperty('nid')];