From 9b3a4cbd971ce2ab8410261bf3f92294e5cf7af7 Mon Sep 17 00:00:00 2001
From: Chris Gross <gross.364@osu.edu>
Date: Tue, 24 Jul 2018 15:26:24 -0400
Subject: [PATCH] 7.x-1.8 Release Candidate 3

---
 profiles/wcm_base/CHANGELOG.txt                      |  4 ++++
 profiles/wcm_base/modules/contrib/views/PATCHES.txt  |  1 +
 .../views/plugins/views_plugin_query_default.inc     | 12 +++++++++---
 profiles/wcm_base/wcm_base.make                      |  1 +
 4 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/profiles/wcm_base/CHANGELOG.txt b/profiles/wcm_base/CHANGELOG.txt
index f6f76c2a..5526a177 100644
--- a/profiles/wcm_base/CHANGELOG.txt
+++ b/profiles/wcm_base/CHANGELOG.txt
@@ -1,3 +1,7 @@
+WCM Base 7.x-1.8-rc3, 2018-07-24
+--------------------------------
+- WCM Base: Added patch to fix duplicate results bug introduced in Views 3.20.
+
 WCM Base 7.x-1.8-rc2, 2018-07-23
 --------------------------------
 - WCM Base:
diff --git a/profiles/wcm_base/modules/contrib/views/PATCHES.txt b/profiles/wcm_base/modules/contrib/views/PATCHES.txt
index c09d8e8a..1d3ca2cc 100644
--- a/profiles/wcm_base/modules/contrib/views/PATCHES.txt
+++ b/profiles/wcm_base/modules/contrib/views/PATCHES.txt
@@ -1,4 +1,5 @@
 The following patches have been applied to this project:
+- http://drupal.org/files/issues/2018-07-15/mysql-group-by-duplication-workaround-2985178-7.patch
 - http://drupal.org/files/issues/views-exposed-sorts-2037469-26.patch
 
 This file was automatically generated by Drush Make (http://drupal.org/project/drush).
diff --git a/profiles/wcm_base/modules/contrib/views/plugins/views_plugin_query_default.inc b/profiles/wcm_base/modules/contrib/views/plugins/views_plugin_query_default.inc
index 2911a560..92eb1926 100644
--- a/profiles/wcm_base/modules/contrib/views/plugins/views_plugin_query_default.inc
+++ b/profiles/wcm_base/modules/contrib/views/plugins/views_plugin_query_default.inc
@@ -1214,7 +1214,10 @@ class views_plugin_query_default extends views_plugin_query {
       }
       // This is a formula, using no tables.
       elseif (empty($field['table'])) {
-        if (!in_array($fieldname, $non_aggregates)) {
+        if (Database::getConnection()->databaseType() != 'pgsql') {
+          $non_aggregates[] = $fieldname;
+        }
+        elseif (!in_array($fieldname, $non_aggregates)) {
           $non_aggregates[] = $fieldname;
         }
         $placeholders = !empty($field['placeholders']) ? $field['placeholders'] : array();
@@ -1224,13 +1227,16 @@ class views_plugin_query_default extends views_plugin_query {
       elseif ($this->distinct && !in_array($fieldname, $this->groupby)) {
         // d7cx: This code was there, apparently needed for PostgreSQL
         // $string = db_driver() == 'pgsql' ? "FIRST($string)" : $string;
-        if (!in_array($string, $non_aggregates)) {
+        if (Database::getConnection()->databaseType() == 'pgsql' && !in_array($string, $non_aggregates)) {
           $non_aggregates[] = $string;
         }
         $query->addField(!empty($field['table']) ? $field['table'] : $this->base_table, $field['field'], $fieldname);
       }
       elseif (empty($field['aggregate'])) {
-        if (!in_array($string, $non_aggregates)) {
+        if (Database::getConnection()->databaseType() != 'pgsql') {
+          $non_aggregates[] = $fieldname;
+        }
+        elseif (!in_array($string, $non_aggregates)) {
           $non_aggregates[] = $string;
         }
         $query->addField(!empty($field['table']) ? $field['table'] : $this->base_table, $field['field'], $fieldname);
diff --git a/profiles/wcm_base/wcm_base.make b/profiles/wcm_base/wcm_base.make
index 1484d827..fb8d4b62 100644
--- a/profiles/wcm_base/wcm_base.make
+++ b/profiles/wcm_base/wcm_base.make
@@ -174,6 +174,7 @@ projects[token_filter][subdir] = contrib
 
 projects[views][version] = 3.20
 projects[views][subdir] = contrib
+projects[views][patch][2985178] = http://drupal.org/files/issues/2018-07-15/mysql-group-by-duplication-workaround-2985178-7.patch
 projects[views][patch][2037469] = http://drupal.org/files/issues/views-exposed-sorts-2037469-26.patch
 
 projects[views_accordion][version] = 1.1
-- 
GitLab