diff -u b/core/modules/statistics/migration_templates/d7_statistics_node_counter.yml b/core/modules/statistics/migration_templates/d7_statistics_node_counter.yml --- b/core/modules/statistics/migration_templates/d7_statistics_node_counter.yml +++ b/core/modules/statistics/migration_templates/d7_statistics_node_counter.yml @@ -3,12 +3,16 @@ migration_tags: - Drupal 7 source: - plugin: d7_node_counter + plugin: node_counter process: nid: - plugin: migration - migration: d7_node - source: nid + - + plugin: migration + migration: d7_node + source: nid + - + plugin: skip_on_empty + method: row totalcount: totalcount daycount: daycount timestamp: timestamp diff -u b/core/modules/statistics/src/Plugin/migrate/destination/NodeCounter.php b/core/modules/statistics/src/Plugin/migrate/destination/NodeCounter.php --- b/core/modules/statistics/src/Plugin/migrate/destination/NodeCounter.php +++ b/core/modules/statistics/src/Plugin/migrate/destination/NodeCounter.php @@ -3,6 +3,7 @@ namespace Drupal\statistics\Plugin\migrate\destination; use Drupal\Core\Database\Connection; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\migrate\Plugin\migrate\destination\DestinationBase; use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Row; @@ -15,7 +16,7 @@ * id = "node_counter" * ) */ -class NodeCounter extends DestinationBase { +class NodeCounter extends DestinationBase implements ContainerFactoryPluginInterface{ /** * The database connection. @@ -25,7 +26,7 @@ protected $connection; /** - * Constructs a BlockedIP object. + * Constructs a node counter plugin. * * @param array $configuration * Plugin configuration. @@ -60,7 +61,7 @@ * {@inheritdoc} */ public function getIds() { - return ['nid' => ['type' => 'int']]; + return ['nid' => ['type' => 'integer']]; } /** only in patch2: unchanged: --- a/core/modules/migrate_drupal/tests/fixtures/drupal6.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php @@ -41614,6 +41614,45 @@ 'mysql_character_set' => 'utf8', )); +$connection->insert('node_counter') +->fields(array( + 'nid', + 'totalcount', + 'daycount', + 'timestamp', +)) +->values(array( + 'nid' => '1', + 'totalcount' => '2', + 'daycount' => '0', + 'timestamp' => '1421727536', +)) +->values(array( + 'nid' => '2', + 'totalcount' => '1', + 'daycount' => '0', + 'timestamp' => '1471428059', +)) +->values(array( + 'nid' => '3', + 'totalcount' => '1', + 'daycount' => '0', + 'timestamp' => '1471428153', +)) +->values(array( + 'nid' => '4', + 'totalcount' => '1', + 'daycount' => '1', + 'timestamp' => '1478755275', +)) +->values(array( + 'nid' => '5', + 'totalcount' => '1', + 'daycount' => '1', + 'timestamp' => '1478755314', +)) +->execute(); + $connection->schema()->createTable('node_revisions', array( 'fields' => array( 'nid' => array( only in patch2: unchanged: --- /dev/null +++ b/core/modules/statistics/migration_templates/d6_statistics_node_counter.yml @@ -0,0 +1,23 @@ +id: d6_statistics_node_counter +label: Drupal 6 Node Counter +migration_tags: + - Drupal 6 +source: + plugin: node_counter +process: + nid: + - + plugin: migration + migration: d6_node + source: nid + - + plugin: skip_on_empty + method: row + totalcount: totalcount + daycount: daycount + timestamp: timestamp +destination: + plugin: node_counter +migration_dependencies: + required: + - d6_node only in patch2: unchanged: --- /dev/null +++ b/core/modules/statistics/src/Plugin/migrate/source/NodeCounter.php @@ -0,0 +1,43 @@ +select('node_counter', 'nc')->fields('nc'); + } + + /** + * {@inheritdoc} + */ + public function fields() { + return [ + 'nid' => $this->t('The node ID.'), + '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 getIds() { + $ids['nid']['type'] = 'integer'; + return $ids; + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/statistics/tests/src/Kernel/Migrate/d6/MigrateNodeCounterTest.php @@ -0,0 +1,76 @@ +installEntitySchema('node'); + $this->installConfig('node'); + $this->installSchema('statistics', ['node_counter']); + + $this->executeMigrations([ + 'd6_filter_format', + 'd6_user_role', + 'd6_node_settings', + 'd6_user', + 'd6_node_type', + 'd6_node', + 'd6_statistics_node_counter' + ]); + } + + /** + * Tests migration of node counter. + */ + public function testStatisticsSettings() { + $this->assertNodeCounter(1, 2, 0, 1421727536); + $this->assertNodeCounter(2, 1, 0, 1471428059); + $this->assertNodeCounter(3, 1, 0, 1471428153); + $this->assertNodeCounter(4, 1, 1, 1478755275); + $this->assertNodeCounter(5, 1, 1, 1478755314); + } + + /** + * Asserts various aspects of a node counter. + * + * @param integer $nid + * The node ID. + * @param integer $total_count + * The expected total count. + * @param integer $day_count + * The expected day count. + * @param integer $timestamp + * The expected timestamp. + */ + protected function assertNodeCounter($nid, $total_count, $day_count, $timestamp) { + /** @var StatisticsViewsResult $statistics */ + $statistics = $this->container->get('statistics.storage.node')->fetchView($nid); + $this->assertEquals($total_count, $statistics->getTotalCount()); + $this->assertEquals($day_count, $statistics->getDayCount()); + $this->assertEquals($timestamp, $statistics->getTimestamp()); + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/statistics/tests/src/Kernel/Migrate/d7/MigrateNodeCounterTest.php @@ -0,0 +1,72 @@ +installEntitySchema('node'); + $this->installConfig('node'); + $this->installSchema('statistics', ['node_counter']); + + $this->executeMigrations([ + 'd7_user_role', + 'd7_user', + 'd7_node_type', + 'd7_node', + 'd7_statistics_node_counter' + ]); + } + + /** + * Tests migration of node counter. + */ + public function testStatisticsSettings() { + $this->assertNodeCounter(1, 2, 0, 1421727536); + $this->assertNodeCounter(2, 1, 0, 1471428059); + $this->assertNodeCounter(4, 1, 1, 1478755275); + } + + /** + * Asserts various aspects of a node counter. + * + * @param integer $nid + * The node ID. + * @param integer $total_count + * The expected total count. + * @param integer $day_count + * The expected day count. + * @param integer $timestamp + * The expected timestamp. + */ + protected function assertNodeCounter($nid, $total_count, $day_count, $timestamp) { + /** @var StatisticsViewsResult $statistics */ + $statistics = $this->container->get('statistics.storage.node')->fetchView($nid); + $this->assertEquals($total_count, $statistics->getTotalCount()); + $this->assertEquals($day_count, $statistics->getDayCount()); + $this->assertEquals($timestamp, $statistics->getTimestamp()); + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/statistics/tests/src/Kernel/Plugin/NodeCounterTest.php @@ -0,0 +1,66 @@ + 1, + 'totalcount' => 2, + 'daycount' => 0, + 'timestamp' => 1421727536, + ], + [ + 'nid' => 2, + 'totalcount' => 1, + 'daycount' => 0, + 'timestamp' => 1471428059, + ], + [ + 'nid' => 3, + 'totalcount' => 1, + 'daycount' => 0, + 'timestamp' => 1471428153, + ], + [ + 'nid' => 4, + 'totalcount' => 1, + 'daycount' => 1, + 'timestamp' => 1478755275, + ], + [ + 'nid' => 5, + 'totalcount' => 1, + 'daycount' => 1, + 'timestamp' => 1478755314, + ], + ]; + + // The expected results. + $tests[0]['expected_data'] = $tests[0]['source_data']['node_counter']; + + return $tests; + } + +}