Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / statistics / src / Plugin / migrate / destination / NodeCounter.php
index e9771f3d988c23c45a858e6d166d64657356ad77..eee23bff5fa653b5ab8e8e5859f6ef358072c2e6 100644 (file)
@@ -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')];
   }