Skip to content

Commit

Permalink
Dev/Core#90 Disable Only Full Group By sql mode on specific queries t…
Browse files Browse the repository at this point in the history
…o get tests to pass so we can switch to using MySQL 5.7 for PR Tests
  • Loading branch information
seamuslee001 committed Apr 29, 2018
1 parent 6756330 commit 84cb7d1
Show file tree
Hide file tree
Showing 3 changed files with 30 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')));
}
}

/**
* Enables ONLY_FULL_GROUP_BY sql_mode as necessary..
*/
public static function enableFullGroupByMode() {
$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::enableFullGroupByMode();
CRM_Utils_System::civiExit();
}
else {
CRM_Core_DAO::enableFullGroupByMode();
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 @@ -364,9 +364,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::enableFullGroupByMode();
$results = array();

while ($dao->fetch()) {
Expand Down

0 comments on commit 84cb7d1

Please sign in to comment.