Skip to content

Commit

Permalink
Merge pull request #18159 from civicrm/5.29
Browse files Browse the repository at this point in the history
5.29
  • Loading branch information
seamuslee001 authored Aug 15, 2020
2 parents fa1fd85 + 32a7956 commit b2b1b9a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
17 changes: 17 additions & 0 deletions CRM/Core/BAO/SchemaHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,23 @@ public static function getDBCollation() {
return CRM_Core_DAO::singleValueQuery('SELECT @@collation_database');
}

/**
* Get the collation actually being used by the tables in the database.
*
* The db collation may not match the collation used by the tables, get what is
* set on the tables (represented by civicrm_contact).
*
* @return string
*/
public static function getInUseCollation() {
if (!isset(\Civi::$statics[__CLASS__][__FUNCTION__])) {
$dao = CRM_Core_DAO::executeQuery('SHOW TABLE STATUS LIKE \'civicrm_contact\'');
$dao->fetch();
\Civi::$statics[__CLASS__][__FUNCTION__] = $dao->Collation;
}
return \Civi::$statics[__CLASS__][__FUNCTION__];
}

/**
* Get the database collation.
*
Expand Down
16 changes: 3 additions & 13 deletions CRM/Utils/SQL/TempTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,13 @@ public function createWithQuery($selectQuery) {
/**
* Get the utf8 string for the table.
*
* If the db collation is already utf8 by default (either
* utf8 or utf84mb) then rely on that. Otherwise set to utf8.
*
* Respecting the DB collation supports utf8mb4 adopters, which is currently
* not the norm in civi installs.
* Our tables are either utf8_unicode_ci OR utf8mb8_unicode_ci - check the contact table
* to see which & use the matching one.
*
* @return string
*/
public function getUtf8String() {
if (!$this->utf8) {
return '';
}
$dbUTF = CRM_Core_BAO_SchemaHandler::getDBCollation();
if (strpos($dbUTF, 'utf8') !== FALSE) {
return '';
}
return self::UTF8;
return $this->utf8 ? ('COLLATE ' . CRM_Core_BAO_SchemaHandler::getInUseCollation()) : '';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/ReportTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ public function testLybuntReportWithFYData() {

$this->assertEquals(2, $rows['count'], 'Report failed - the sql used to generate the results was ' . print_r($rows['metadata']['sql'], TRUE));

$expected = preg_replace('/\s+/', ' ', 'DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci AS
$expected = preg_replace('/\s+/', ' ', 'COLLATE utf8_unicode_ci AS
SELECT SQL_CALC_FOUND_ROWS contact_civireport.id as cid FROM civicrm_contact contact_civireport INNER JOIN civicrm_contribution contribution_civireport USE index (received_date) ON contribution_civireport.contact_id = contact_civireport.id
AND contribution_civireport.is_test = 0
AND contribution_civireport.receive_date BETWEEN \'20140701000000\' AND \'20150630235959\'
Expand Down

0 comments on commit b2b1b9a

Please sign in to comment.