warning fixes
authorjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Mon, 6 Jun 2016 05:47:47 +0000 (11:17 +0530)
committerjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Tue, 12 Jul 2016 05:36:27 +0000 (11:06 +0530)
CRM/Contact/BAO/Contact/Utils.php
CRM/Contact/BAO/Query.php
CRM/Mailing/BAO/Mailing.php
CRM/Report/Form.php
CRM/Report/Form/Case/TimeSpent.php
CRM/Report/Form/Contact/CurrentEmployer.php
CRM/Report/Form/Contribute/Bookkeeping.php
CRM/Report/Form/Contribute/Summary.php

index 4a94e0c5dad7c0339c017e24895ae7ac60a3cee4..3339de232ab4911b7407f55e75cbcbd83347eb7e 100644 (file)
@@ -777,12 +777,13 @@ INNER JOIN civicrm_contact contact_target ON ( contact_target.id = act.contact_i
       $fromClause = implode(' ', $from);
       $selectClause = implode(', ', $select);
       $whereClause = "{$compTable}.id IN (" . implode(',', $componentIds) . ')';
+      $groupBy = CRM_Contact_BAO_Query::getGroupByFromSelectColumns($select, array("{$compTable}.id", 'contact.id'));
 
       $query = "
   SELECT  contact.id as contactId, $compTable.id as componentId, $selectClause
     FROM  $compTable as $compTable $fromClause
    WHERE  $whereClause
-Group By  componentId";
+   {$groupBy}";
 
       $contact = CRM_Core_DAO::executeQuery($query);
       while ($contact->fetch()) {
index 4cbf220535dc911da29a18ec379346d345ce2176..ec4b004e158896868372cf3ca2c272f67bd02319 100644 (file)
@@ -4523,7 +4523,7 @@ civicrm_relationship.is_permission_a_b = 0
   /**
    * Include Select columns in groupBy clause.
    *
-   * @param array $selectArray
+   * @param array $selectClauses
    * @param array $groupBy - Columns already included in GROUP By clause.
    *
    * @return string
@@ -4534,39 +4534,34 @@ civicrm_relationship.is_permission_a_b = 0
     $sqlMode = CRM_Core_DAO::singleValueQuery('SELECT @@sql_mode');
 
     //return if ONLY_FULL_GROUP_BY is not enabled.
-    if (version_compare($mysqlVersion, '5.7', '<') || !empty($sqlMode) && !in_array('ONLY_FULL_GROUP_BY', explode(',', $sqlMode))) {
-      if (!empty($groupBy)) {
-        return " GROUP BY " . implode(', ', $groupBy);
-      }
-      return '';
-    }
-
-    $regexToExclude = '/(ROUND|AVG|COUNT|GROUP_CONCAT|SUM|MAX|MIN)\(/i';
-    foreach ($selectClauses as $key => $val) {
-      $aliasArray = preg_split('/ as /i', $val);
-      // if more than 1 alias we need to split by ','.
-      if (count($aliasArray) > 2) {
-        $aliasArray = preg_split('/,/', $val);
-        foreach ($aliasArray as $key => $value) {
-          $alias = current(preg_split('/ as /i', $value));
-          if (!in_array($alias, $groupBy) && preg_match($regexToExclude, trim($alias)) !== 1) {
-            $groupBy[] = $alias;
+    if (!version_compare($mysqlVersion, '5.7', '<') && !empty($sqlMode) && in_array('ONLY_FULL_GROUP_BY', explode(',', $sqlMode))) {
+      $regexToExclude = '/(ROUND|AVG|COUNT|GROUP_CONCAT|SUM|MAX|MIN)\(/i';
+      foreach ($selectClauses as $key => $val) {
+        $aliasArray = preg_split('/ as /i', $val);
+        // if more than 1 alias we need to split by ','.
+        if (count($aliasArray) > 2) {
+          $aliasArray = preg_split('/,/', $val);
+          foreach ($aliasArray as $key => $value) {
+            $alias = current(preg_split('/ as /i', $value));
+            if (!in_array($alias, $groupBy) && preg_match($regexToExclude, trim($alias)) !== 1) {
+              $groupBy[] = $alias;
+            }
           }
         }
-      }
-      else {
-        list($selectColumn, $alias) = array_pad($aliasArray, 2, NULL);
-        $dateRegex = '/^(DATE_FORMAT|DATE_ADD|CASE)/i';
-        $tableName = current(explode('.', $selectColumn));
-        $primaryKey = "{$tableName}.id";
-        // exclude columns which are already included in groupBy and aggregate functions from select
-        // CRM-18439 - Also exclude the columns which are functionally dependent on columns in $groupBy (MySQL 5.7+)
-        if (!in_array($selectColumn, $groupBy) && !in_array($primaryKey, $groupBy) && preg_match($regexToExclude, trim($selectColumn)) !== 1) {
-          if (!empty($alias) && preg_match($dateRegex, trim($selectColumn))) {
-            $groupBy[] = $alias;
-          }
-          else {
-            $groupBy[] = $selectColumn;
+        else {
+          list($selectColumn, $alias) = array_pad($aliasArray, 2, NULL);
+          $dateRegex = '/^(DATE_FORMAT|DATE_ADD|CASE)/i';
+          $tableName = current(explode('.', $selectColumn));
+          $primaryKey = "{$tableName}.id";
+          // exclude columns which are already included in groupBy and aggregate functions from select
+          // CRM-18439 - Also exclude the columns which are functionally dependent on columns in $groupBy (MySQL 5.7+)
+          if (!in_array($selectColumn, $groupBy) && !in_array($primaryKey, $groupBy) && preg_match($regexToExclude, trim($selectColumn)) !== 1) {
+            if (!empty($alias) && preg_match($dateRegex, trim($selectColumn))) {
+              $groupBy[] = $alias;
+            }
+            else {
+              $groupBy[] = $selectColumn;
+            }
           }
         }
       }
index bf190fa04922bb5f81239b9b156c592e1b1a620b..a89bf9d26620e23d53007143089f97118ba08e12 100644 (file)
@@ -2512,7 +2512,7 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.id
       "$mailing.id", "$mailing.name", "$job.status",
       "$mailing.approval_status_id", "createdContact.sort_name as created_by", "scheduledContact.sort_name as scheduled_by",
       "$mailing.created_id as created_id", "$mailing.scheduled_id as scheduled_id", "$mailing.is_archived as archived",
-      "$mailing.created_date as created_date", "campaign_id", "$mailing.sms_provider_id as sms_provider_id"
+      "$mailing.created_date as created_date", "campaign_id", "$mailing.sms_provider_id as sms_provider_id",
     );
 
     // we only care about parent jobs, since that holds all the info on
index 07a6c87db7348a735396e458c85617d7977c1a48..c101e38c677461a777d6176675996b149316a607 100644 (file)
@@ -2645,7 +2645,7 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND
   /**
    * append select with ANY_VALUE() keyword.
    *
-   * @param array $selectArray
+   * @param array $selectClauses
    * @param array $groupBy - Columns already included in GROUP By clause.
    */
   public function appendSelect($selectClauses, $groupBy) {
index 659ee4a9be27d7aae3677408d678577212ae0e34..c90270576470168c8472f3720aaeb1d3c9f525e6 100644 (file)
@@ -287,7 +287,7 @@ class CRM_Report_Form_Case_TimeSpent extends CRM_Report_Form {
     if ($this->has_grouping) {
       $groupBy = array(
         "{$this->_aliases['civicrm_contact']}.id",
-        "civicrm_activity_activity_date_time"
+        "civicrm_activity_activity_date_time",
       );
       if ($this->has_activity_type) {
         $groupBy[] = "{$this->_aliases['civicrm_activity']}.activity_type_id";
index 35cd3362a39751e9221293eae264b341462dc20f..150fe68cf8b90bc02cec6c183eae6a045f4281e4 100644 (file)
@@ -324,7 +324,7 @@ FROM civicrm_contact {$this->_aliases['civicrm_contact']}
   public function groupBy() {
     $groupBy = array(
       "{$this->_aliases['civicrm_employer']}.id",
-      "{$this->_aliases['civicrm_contact']}.id"
+      "{$this->_aliases['civicrm_contact']}.id",
     );
 
     $this->_groupBy = CRM_Contact_BAO_Query::getGroupByFromSelectColumns($this->_selectClauses, $groupBy);
index 12e704e9bfebe3441e8350aa6a20a767b47ac6c1..1f818f4f74e40ba4eb1ab4d7f312ea4c9792270c 100644 (file)
@@ -515,7 +515,7 @@ class CRM_Report_Form_Contribute_Bookkeeping extends CRM_Report_Form {
   public function groupBy() {
     $groupBy = array(
       "{$this->_aliases['civicrm_entity_financial_trxn']}.id",
-      "{$this->_aliases['civicrm_line_item']}.id"
+      "{$this->_aliases['civicrm_line_item']}.id",
     );
     $this->_groupBy = CRM_Contact_BAO_Query::getGroupByFromSelectColumns($this->_selectClauses, $groupBy);
   }
@@ -528,16 +528,16 @@ class CRM_Report_Form_Contribute_Bookkeeping extends CRM_Report_Form {
   public function statistics(&$rows) {
     $statistics = parent::statistics($rows);
     $tempTableName = CRM_Core_DAO::createTempTableName('civicrm_contribution');
+    $financialSelect = "CASE WHEN {$this->_aliases['civicrm_entity_financial_trxn']}_item.entity_id IS NOT NULL
+            THEN {$this->_aliases['civicrm_entity_financial_trxn']}_item.amount
+            ELSE {$this->_aliases['civicrm_entity_financial_trxn']}.amount
+            END as amount";
 
     $this->_selectClauses = array(
       "{$this->_aliases['civicrm_contribution']}.id",
       "{$this->_aliases['civicrm_entity_financial_trxn']}.id as trxnID",
       "{$this->_aliases['civicrm_contribution']}.currency",
-      "CASE
-         WHEN {$this->_aliases['civicrm_entity_financial_trxn']}_item.entity_id IS NOT NULL
-         THEN {$this->_aliases['civicrm_entity_financial_trxn']}_item.amount
-         ELSE {$this->_aliases['civicrm_entity_financial_trxn']}.amount
-       END as amount",
+      $financialSelect,
     );
     $select = "SELECT " . implode(', ', $this->_selectClauses);
 
index e4efe70d843e67d7f3234a2470bfc558a90d79da..83564ec9871810a39693d54f8b827eafd613f519 100644 (file)
@@ -539,7 +539,7 @@ class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form {
       }
       $groupBy = array();
       foreach ($this->_groupBy as $key => $val) {
-        if (strpos($val, ';;') !== false) {
+        if (strpos($val, ';;') !== FALSE) {
           $groupBy = array_merge($groupBy, explode(';;', $val));
         }
         else {