diff --git a/core/modules/statistics/migration_templates/d7_statistics_node_counter.yml b/core/modules/statistics/migration_templates/d7_statistics_node_counter.yml new file mode 100644 index 0000000..abb7695 --- /dev/null +++ b/core/modules/statistics/migration_templates/d7_statistics_node_counter.yml @@ -0,0 +1,19 @@ +id: d7_statistics_node_counter +label: Drupal 7 Node Counter +migration_tags: + - Drupal 7 +source: + plugin: d7_node_counter +process: + nid: + plugin: migration + migration: d7_node + source: nid + totalcount: totalcount + daycount: daycount + timestamp: timestamp +destination: + plugin: node_counter +migration_dependencies: + required: + - d7_node diff --git a/core/modules/statistics/src/Plugin/migrate/destination/NodeCounter.php b/core/modules/statistics/src/Plugin/migrate/destination/NodeCounter.php new file mode 100644 index 0000000..38f266c --- /dev/null +++ b/core/modules/statistics/src/Plugin/migrate/destination/NodeCounter.php @@ -0,0 +1,98 @@ +connection = $connection; + } + + /** + * {@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('database') + ); + } + + /** + * {@inheritdoc} + */ + public function getIds() { + return ['nid' => ['type' => 'int']]; + } + + /** + * {@inheritdoc} + */ + public function fields(MigrationInterface $migration = NULL) { + return [ + 'nid' => $this->t('The ID of the node to which these statistics apply.'), + 'totalcount' => $this->t('The total number of times the node has been viewed.'), + 'daycount' => $this->t('The total number of times the node has been viewed today.'), + 'timestamp' => $this->t('The most recent time the node has been viewed.'), + ]; + } + + /** + * {@inheritdoc} + */ + public function import(Row $row, array $old_destination_id_values = array()) { + return (bool) $this->connection + ->insert('node_counter') + ->fields([ + 'nid', + 'daycount', + 'totalcount', + 'timestamp', + ], [ + $row->getDestinationProperty('nid'), + $row->getDestinationProperty('daycount'), + $row->getDestinationProperty('totalcount'), + $row->getDestinationProperty('timestamp'), + ]) + ->execute(); + } + +}