From fc0f117c0822e609bc9c17ccbadee83d56c09ca8 Mon Sep 17 00:00:00 2001
From: Kristiaan Van den Eynde <magentix@gmail.com>
Date: Fri, 17 Oct 2014 14:36:55 +0200
Subject: [PATCH] Issue #1930288 by kristiaanvandeneynde, schlicki: Fixed
 views_join: wrong handling of $extra parameter.

---
 includes/handlers.inc |   52 ++++++++++++++++++++++++-------------------------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/includes/handlers.inc b/includes/handlers.inc
index 4346133..59803bb 100644
--- a/includes/handlers.inc
+++ b/includes/handlers.inc
@@ -1544,9 +1544,9 @@ class views_join {
 
     // Tack on the extra.
     if (isset($this->extra)) {
-      if (is_array($this->extra)) {
-        $extras = array();
-        foreach ($this->extra as $info) {
+      $extras = array();
+      foreach ($this->extra as $info) {
+        if (is_array($info)) {
           $extra = '';
           // Figure out the table name. Remember, only use aliases provided
           // if at all possible.
@@ -1596,18 +1596,18 @@ class views_join {
           }
           $extras[] = "$join_table$info[field] $operator $placeholder";
         }
-
-        if ($extras) {
-          if (count($extras) == 1) {
-            $condition .= ' AND ' . array_shift($extras);
-          }
-          else {
-            $condition .= ' AND (' . implode(' ' . $this->extra_type . ' ', $extras) . ')';
-          }
+        elseif (is_string($info)) {
+          $extras[] = $info;
         }
       }
-      elseif ($this->extra && is_string($this->extra)) {
-        $condition .= " AND ($this->extra)";
+
+      if ($extras) {
+        if (count($extras) == 1) {
+          $condition .= ' AND ' . array_shift($extras);
+        }
+        else {
+          $condition .= ' AND (' . implode(' ' . $this->extra_type . ' ', $extras) . ')';
+        }
       }
     }
 
@@ -1657,9 +1657,9 @@ class views_join_subquery extends views_join {
     // Tack on the extra.
     // This is just copied verbatim from the parent class, which itself has a bug: http://drupal.org/node/1118100
     if (isset($this->extra)) {
-      if (is_array($this->extra)) {
-        $extras = array();
-        foreach ($this->extra as $info) {
+      $extras = array();
+      foreach ($this->extra as $info) {
+        if (is_array($info)) {
           $extra = '';
           // Figure out the table name. Remember, only use aliases provided
           // if at all possible.
@@ -1688,18 +1688,18 @@ class views_join_subquery extends views_join {
           $extras[] = "$join_table$info[field] $operator $placeholder";
           $arguments[$placeholder] = $info['value'];
         }
-
-        if ($extras) {
-          if (count($extras) == 1) {
-            $condition .= ' AND ' . array_shift($extras);
-          }
-          else {
-            $condition .= ' AND (' . implode(' ' . $this->extra_type . ' ', $extras) . ')';
-          }
+        elseif (is_string($info)) {
+          $extras[] = $info;
         }
       }
-      elseif ($this->extra && is_string($this->extra)) {
-        $condition .= " AND ($this->extra)";
+
+      if ($extras) {
+        if (count($extras) == 1) {
+          $condition .= ' AND ' . array_shift($extras);
+        }
+        else {
+          $condition .= ' AND (' . implode(' ' . $this->extra_type . ' ', $extras) . ')';
+        }
       }
     }
 
-- 
1.7.9.4

