summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorAlex Pott2018-03-20 16:53:51 (GMT)
committerAlex Pott2018-03-20 16:53:51 (GMT)
commitd45dc9d26a3c9a6cd4638deea906d7e167389eec (patch)
treedf22bfab703528d2118da2ee252bcfc299b1eff2 /core
parentd47cfa0efdc9cf60ce58a7303119b6cb6ff108a4 (diff)
Issue #2930101 by maxocub, heddn, alexpott, phenaproxima, catch, masipila: i18n / statistics - node counter not updated for translations
Diffstat (limited to 'core')
-rw-r--r--core/modules/migrate_drupal/tests/fixtures/drupal6.php24
-rw-r--r--core/modules/statistics/migrations/statistics_node_translation_counter.yml34
-rw-r--r--core/modules/statistics/src/Plugin/migrate/destination/NodeCounter.php19
-rw-r--r--core/modules/statistics/tests/src/Kernel/Migrate/d6/MigrateNodeCounterTest.php15
-rw-r--r--core/modules/statistics/tests/src/Kernel/Migrate/d7/MigrateNodeCounterTest.php13
5 files changed, 98 insertions, 7 deletions
diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal6.php b/core/modules/migrate_drupal/tests/fixtures/drupal6.php
index b49c92c..de20137 100644
--- a/core/modules/migrate_drupal/tests/fixtures/drupal6.php
+++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php
@@ -43635,6 +43635,30 @@ $connection->insert('node_counter')
'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',
'daycount' => '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 0000000..bf8cde4
--- /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 e9771f3..eee23bf 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 ebd7766..ea917f5 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 8cdb9e7..9a7317f 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);
}
/**