From d45dc9d26a3c9a6cd4638deea906d7e167389eec Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 20 Mar 2018 16:53:51 +0000 Subject: [PATCH] Issue #2930101 by maxocub, heddn, alexpott, phenaproxima, catch, masipila: i18n / statistics - node counter not updated for translations --- .../migrate_drupal/tests/fixtures/drupal6.php | 24 +++++++++++++ .../statistics_node_translation_counter.yml | 34 +++++++++++++++++++ .../migrate/destination/NodeCounter.php | 19 ++++++++--- .../Migrate/d6/MigrateNodeCounterTest.php | 15 +++++++- .../Migrate/d7/MigrateNodeCounterTest.php | 13 ++++++- 5 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 core/modules/statistics/migrations/statistics_node_translation_counter.yml diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal6.php b/core/modules/migrate_drupal/tests/fixtures/drupal6.php index b49c92c80a4f..de20137606a8 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal6.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php @@ -43634,6 +43634,30 @@ $connection->insert('node_counter') 'daycount' => '1', 'timestamp' => '1478755314', )) +->values(array( + 'nid' => '10', + 'totalcount' => '5', + 'daycount' => '1', + 'timestamp' => '1521137459', +)) +->values(array( + 'nid' => '11', + 'totalcount' => '3', + 'daycount' => '1', + 'timestamp' => '1521137463', +)) +->values(array( + 'nid' => '12', + 'totalcount' => '3', + 'daycount' => '0', + 'timestamp' => '1521137469', +)) +->values(array( + 'nid' => '13', + 'totalcount' => '2', + 'daycount' => '1', + 'timestamp' => '1521137470', +)) ->values(array( 'nid' => '14', 'totalcount' => '1', diff --git a/core/modules/statistics/migrations/statistics_node_translation_counter.yml b/core/modules/statistics/migrations/statistics_node_translation_counter.yml new file mode 100644 index 000000000000..bf8cde409201 --- /dev/null +++ b/core/modules/statistics/migrations/statistics_node_translation_counter.yml @@ -0,0 +1,34 @@ +id: statistics_node_translation_counter +label: Node translation counter +migration_tags: + - Drupal 6 + - Drupal 7 + - Content +source: + plugin: node_counter +process: + nid: + - + plugin: migration_lookup + migration: + - d6_node_translation + - d7_node_translation + source: nid + - + plugin: skip_on_empty + method: row + - + plugin: extract + index: + - 0 + totalcount: totalcount + daycount: daycount + timestamp: timestamp +destination: + plugin: node_counter +migration_dependencies: + required: + - statistics_node_counter + optional: + - d6_node_translation + - d7_node_translation diff --git a/core/modules/statistics/src/Plugin/migrate/destination/NodeCounter.php b/core/modules/statistics/src/Plugin/migrate/destination/NodeCounter.php index e9771f3d988c..eee23bff5fa6 100644 --- a/core/modules/statistics/src/Plugin/migrate/destination/NodeCounter.php +++ b/core/modules/statistics/src/Plugin/migrate/destination/NodeCounter.php @@ -81,15 +81,24 @@ class NodeCounter extends DestinationBase implements ContainerFactoryPluginInter * {@inheritdoc} */ public function import(Row $row, array $old_destination_id_values = []) { + $nid = $row->getDestinationProperty('nid'); + $daycount = $row->getDestinationProperty('daycount'); + $totalcount = $row->getDestinationProperty('totalcount'); + $timestamp = $row->getDestinationProperty('timestamp'); + $this->connection - ->insert('node_counter') + ->merge('node_counter') + ->key('nid', $nid) ->fields([ - 'nid' => $row->getDestinationProperty('nid'), - 'daycount' => $row->getDestinationProperty('daycount'), - 'totalcount' => $row->getDestinationProperty('totalcount'), - 'timestamp' => $row->getDestinationProperty('timestamp'), + 'daycount' => $daycount, + 'totalcount' => $totalcount, + 'timestamp' => $timestamp, ]) + ->expression('daycount', 'daycount + :daycount', [':daycount' => $daycount]) + ->expression('totalcount', 'totalcount + :totalcount', [':totalcount' => $totalcount]) + ->expression('timestamp', 'CASE WHEN timestamp > :timestamp THEN timestamp ELSE :timestamp END', [':timestamp' => $timestamp]) ->execute(); + return [$row->getDestinationProperty('nid')]; } diff --git a/core/modules/statistics/tests/src/Kernel/Migrate/d6/MigrateNodeCounterTest.php b/core/modules/statistics/tests/src/Kernel/Migrate/d6/MigrateNodeCounterTest.php index ebd776638625..ea917f51a426 100644 --- a/core/modules/statistics/tests/src/Kernel/Migrate/d6/MigrateNodeCounterTest.php +++ b/core/modules/statistics/tests/src/Kernel/Migrate/d6/MigrateNodeCounterTest.php @@ -15,6 +15,8 @@ class MigrateNodeCounterTest extends MigrateDrupal6TestBase { * {@inheritdoc} */ public static $modules = [ + 'content_translation', + 'language', 'menu_ui', 'node', 'statistics', @@ -29,16 +31,20 @@ class MigrateNodeCounterTest extends MigrateDrupal6TestBase { $this->installEntitySchema('node'); $this->installConfig('node'); + $this->installSchema('node', ['node_access']); $this->installSchema('statistics', ['node_counter']); $this->executeMigrations([ + 'language', 'd6_filter_format', 'd6_user_role', 'd6_node_settings', 'd6_user', 'd6_node_type', + 'd6_language_content_settings', 'd6_node', - 'statistics_node_counter' + 'd6_node_translation', + 'statistics_node_counter', ]); } @@ -51,6 +57,13 @@ class MigrateNodeCounterTest extends MigrateDrupal6TestBase { $this->assertNodeCounter(3, 1, 0, 1471428153); $this->assertNodeCounter(4, 1, 1, 1478755275); $this->assertNodeCounter(5, 1, 1, 1478755314); + $this->assertNodeCounter(10, 5, 1, 1521137459); + $this->assertNodeCounter(12, 3, 0, 1521137469); + + // Tests that translated node counts include all translation counts. + $this->executeMigration('statistics_node_translation_counter'); + $this->assertNodeCounter(10, 8, 2, 1521137463); + $this->assertNodeCounter(12, 5, 1, 1521137470); } /** diff --git a/core/modules/statistics/tests/src/Kernel/Migrate/d7/MigrateNodeCounterTest.php b/core/modules/statistics/tests/src/Kernel/Migrate/d7/MigrateNodeCounterTest.php index 8cdb9e70731a..9a7317fada64 100644 --- a/core/modules/statistics/tests/src/Kernel/Migrate/d7/MigrateNodeCounterTest.php +++ b/core/modules/statistics/tests/src/Kernel/Migrate/d7/MigrateNodeCounterTest.php @@ -15,6 +15,8 @@ class MigrateNodeCounterTest extends MigrateDrupal7TestBase { * {@inheritdoc} */ public static $modules = [ + 'content_translation', + 'language', 'menu_ui', 'node', 'statistics', @@ -29,14 +31,18 @@ class MigrateNodeCounterTest extends MigrateDrupal7TestBase { $this->installEntitySchema('node'); $this->installConfig('node'); + $this->installSchema('node', ['node_access']); $this->installSchema('statistics', ['node_counter']); $this->executeMigrations([ + 'language', 'd7_user_role', 'd7_user', 'd7_node_type', + 'd7_language_content_settings', 'd7_node', - 'statistics_node_counter' + 'd7_node_translation', + 'statistics_node_counter', ]); } @@ -47,6 +53,11 @@ class MigrateNodeCounterTest extends MigrateDrupal7TestBase { $this->assertNodeCounter(1, 2, 0, 1421727536); $this->assertNodeCounter(2, 1, 0, 1471428059); $this->assertNodeCounter(4, 1, 1, 1478755275); + + // Tests that translated node counts include all translation counts. + $this->executeMigration('statistics_node_translation_counter'); + $this->assertNodeCounter(2, 2, 0, 1471428153); + $this->assertNodeCounter(4, 2, 2, 1478755314); } /**