Problem / motivation

Follow-up for #2500521: Upgrade path for Statistics 7.x and 6.x

As @dexter42 pointed out in #25, the node_counter table only knows about node ids and so if the D6 nodes have translations with the current patch the statistics of the translations are lost when migrating to D8.

Comments

masipila created an issue. See original summary.

catch’s picture

Attaching this to the meta-issue for translated node IDs.

catch’s picture

Also postponing on #2912348: Handle entity_references related to Drupal 6 and 7 node translations with different IDs since that will add infrastructure and a pattern that this issue can use.

heddn’s picture

Title: i18n / statistics - node counter not updaged for translations » i18n / statistics - node counter not updated for translations
Status: Active » Postponed
Related issues: +#2912348: Handle entity_references related to Drupal 6 and 7 node translations with different IDs
heddn’s picture

Issue tags: +Migrate Drupal

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

maxocub’s picture

Status: Postponed » Needs review
StatusFileSize
new6.88 KB

I doesn't seems like this issue needs to be postponed on #2912348: Handle entity_references related to Drupal 6 and 7 node translations with different IDs since it can be done without a follow-up migration.

phenaproxima’s picture

  1. +++ b/core/modules/statistics/migrations/statistics_node_counter_translation.yml
    @@ -0,0 +1,34 @@
    +id: statistics_node_counter_translation
    +label: Node counter translations
    

    I think we should rephrase these a little; IMHO, "node translation counter" makes more sense than "node counter translation", since the counter itself is not being translated in any way.

  2. +++ b/core/modules/statistics/src/Plugin/migrate/destination/NodeCounter.php
    @@ -81,15 +81,41 @@ public function fields(MigrationInterface $migration = NULL) {
    +    if (!$result) {
    +      $this->connection
    +        ->insert('node_counter')
    +        ->fields([
    +          'nid' => $nid,
    +          'daycount' => $daycount,
    +          'totalcount' => $totalcount,
    +          'timestamp' => $timestamp,
    +        ])
    +        ->execute();
    +    }
    +    else {
    +      $this->connection
    +        ->update('node_counter')
    +        ->fields([
    +          'nid' => $nid,
    +          'daycount' => $result['daycount'] + $daycount,
    +          'totalcount' => $result['totalcount'] + $totalcount,
    +          'timestamp' => $timestamp > $result['timestamp'] ? $timestamp : $result['timestamp'],
    +        ])
    +        ->condition('nid', $nid)
    +        ->execute();
    +    }
    

    It's too bad that Statistics doesn't provide an API for this, but I suppose that's not a big problem as long as there is test coverage of both the insert and update cases.

heddn’s picture

StatusFileSize
new567 bytes
new6.88 KB

I think #8.2 is an observation. Here's a quick fix to 8.1.

maxocub’s picture

StatusFileSize
new7.14 KB
new2.52 KB

Re #8.2: I updated the tests to make it more obvious that the node counters are updated by the new migration after being inserted by the first migration.

(I also renamed the migration yml to reflect the migration id)

The last submitted patch, 9: 2930101-9.patch, failed testing. View results

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/modules/statistics/src/Plugin/migrate/destination/NodeCounter.php
@@ -81,15 +81,41 @@ public function fields(MigrationInterface $migration = NULL) {
+    if (!$result) {
+      $this->connection
+        ->insert('node_counter')
+        ->fields([
+          'nid' => $nid,
+          'daycount' => $daycount,
+          'totalcount' => $totalcount,
+          'timestamp' => $timestamp,
+        ])
+        ->execute();
+    }
+    else {
+      $this->connection
+        ->update('node_counter')
+        ->fields([
+          'nid' => $nid,
+          'daycount' => $result['daycount'] + $daycount,
+          'totalcount' => $result['totalcount'] + $totalcount,
+          'timestamp' => $timestamp > $result['timestamp'] ? $timestamp : $result['timestamp'],
+        ])
+        ->condition('nid', $nid)
+        ->execute();
+    }

We could combine these two queries into a single merge query, to DRY things up a bit. But that's a total fundamentalist nitpick, so feel free to disregard.

Otherwise, I don't see anything to object to. To paraphrase Mortal Kombat, let's finish this.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.99 KB
new6.79 KB
+++ b/core/modules/statistics/src/Plugin/migrate/destination/NodeCounter.php
@@ -81,15 +81,41 @@ public function fields(MigrationInterface $migration = NULL) {
+    $result = $this->connection
+      ->select('node_counter', 'nc')
+      ->fields('nc')
+      ->condition('nid', $nid)
+      ->execute()
+      ->fetchAssoc();
+
+    if (!$result) {
+      $this->connection
+        ->insert('node_counter')
+        ->fields([
+          'nid' => $nid,
+          'daycount' => $daycount,
+          'totalcount' => $totalcount,
+          'timestamp' => $timestamp,
+        ])
+        ->execute();
+    }
+    else {
+      $this->connection
+        ->update('node_counter')
+        ->fields([
+          'nid' => $nid,
+          'daycount' => $result['daycount'] + $daycount,
+          'totalcount' => $result['totalcount'] + $totalcount,
+          'timestamp' => $timestamp > $result['timestamp'] ? $timestamp : $result['timestamp'],
+        ])
+        ->condition('nid', $nid)
+        ->execute();
+    }

This whole thing should be a single merge query.

heddn’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC.

alexpott’s picture

Crediting @phenaproxima for reviews and @catch and @masipila for issue management.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed d45dc9d26a to 8.6.x and 63210e8ef3 to 8.5.x. Thanks!

  • alexpott committed d45dc9d on 8.6.x
    Issue #2930101 by maxocub, heddn, alexpott, phenaproxima, catch,...

  • alexpott committed 63210e8 on 8.5.x
    Issue #2930101 by maxocub, heddn, alexpott, phenaproxima, catch,...
RytoEX’s picture

Does this fully resolve the known issues in the handbook on upgrading Statistics from D6/7 to D8? If so, should those sections be removed, or should it wait till the commit ships?

masipila’s picture

Re #19: Yes, this should permanently fix the i18n statistics migration. I updated the known issue page and mentioned that i18n statistics migration will be included as of D8.5.1.

Cheers,
Markus

oriol_e9g’s picture

Will be included in 8.5.2. Drupal 8.5.1 is only security fix.

masipila’s picture

Thanks @oriol_e9g, I updated the documentation accordingly.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.