Skip to content

Commit

Permalink
Merge pull request #12147 from JMAConsulting/dev_core_120
Browse files Browse the repository at this point in the history
Dev/Core#120 Advanced Search - Contacts throws Fata Error v 5.1.1
  • Loading branch information
eileenmcnaughton authored May 16, 2018
2 parents 9c515df + 22e0ffe commit ad662ef
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
23 changes: 23 additions & 0 deletions CRM/Core/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,29 @@ public static function getConnection() {
return $_DB_DATAOBJECT['CONNECTIONS'][$dao->_database_dsn_md5];
}

/**
* Disables usage of the ONLY_FULL_GROUP_BY Mode if necessary
*/
public static function disableFullGroupByMode() {
$currentModes = CRM_Utils_SQL::getSqlModes();
if (CRM_Utils_SQL::supportsFullGroupBy() && in_array('ONLY_FULL_GROUP_BY', $currentModes) && CRM_Utils_SQL::isGroupByModeInDefault()) {
$key = array_search('ONLY_FULL_GROUP_BY', $currentModes);
unset($currentModes[$key]);
CRM_Core_DAO::executeQuery("SET SESSION sql_mode = %1", array(1 => array(implode(',', $currentModes), 'String')));
}
}

/**
* Re-enables ONLY_FULL_GROUP_BY sql_mode as necessary..
*/
public static function reenableFullGroupByMode() {
$currentModes = CRM_Utils_SQL::getSqlModes();
if (CRM_Utils_SQL::supportsFullGroupBy() && !in_array('ONLY_FULL_GROUP_BY', $currentModes) && CRM_Utils_SQL::isGroupByModeInDefault()) {
$currentModes[] = 'ONLY_FULL_GROUP_BY';
CRM_Core_DAO::executeQuery("SET SESSION sql_mode = %1", array(1 => array(implode(',', $currentModes), 'String')));
}
}

/**
* @param string $fieldName
* @param $fieldDef
Expand Down
7 changes: 5 additions & 2 deletions CRM/Export/BAO/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ public static function getGroupBy($exportMode, $queryMode, $returnProperties, $q
}

if (!empty($groupBy)) {
if (!Civi::settings()->get('searchPrimaryDetailsOnly')) {
CRM_Core_DAO::disableFullGroupByMode();
}
$groupBy = CRM_Contact_BAO_Query::getGroupByFromSelectColumns($query->_select, $groupBy);
}

Expand Down Expand Up @@ -1004,10 +1007,11 @@ public static function exportComponents(
// delete the export temp table and component table
$sql = "DROP TABLE IF EXISTS {$exportTempTable}";
CRM_Core_DAO::executeQuery($sql);

CRM_Core_DAO::reenableFullGroupByMode();
CRM_Utils_System::civiExit();
}
else {
CRM_Core_DAO::reenableFullGroupByMode();
throw new CRM_Core_Exception(ts('No records to export'));
}
}
Expand Down Expand Up @@ -1309,7 +1313,6 @@ public static function writeDetailsToTable($tableName, &$details, &$sqlColumns)
INSERT INTO $tableName $sqlColumnString
VALUES $sqlValueString
";

CRM_Core_DAO::executeQuery($sql);
}

Expand Down
4 changes: 2 additions & 2 deletions CRM/Mailing/Event/BAO/TrackableURLOpen.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,9 @@ public static function &getRows(
//Added "||$rowCount" to avoid displaying all records on first page
$query .= ' LIMIT ' . CRM_Utils_Type::escape($offset, 'Integer') . ', ' . CRM_Utils_Type::escape($rowCount, 'Integer');
}

CRM_Core_DAO::disableFullGroupByMode();
$dao->query($query);

CRM_Core_DAO::reenableFullGroupByMode();
$results = array();

while ($dao->fetch()) {
Expand Down
1 change: 1 addition & 0 deletions CRM/Report/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -2750,6 +2750,7 @@ public function unselectedSectionColumns() {
*/
public function buildRows($sql, &$rows) {
$dao = CRM_Core_DAO::executeQuery($sql);
CRM_Core_DAO::reenableFullGroupByMode();
if (!is_array($rows)) {
$rows = array();
}
Expand Down

0 comments on commit ad662ef

Please sign in to comment.