3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Just another collection of static utils functions.
32 * @copyright CiviCRM LLC (c) 2004-2018
37 * Helper function for adding the permissioned subquery from one entity onto another
39 * @param string $entity
40 * @param string $joinColumn
43 public static function mergeSubquery($entity, $joinColumn = 'id') {
44 require_once 'api/v3/utils.php';
45 $baoName = _civicrm_api3_get_BAO($entity);
46 $bao = new $baoName();
47 $clauses = $subclauses = array();
48 foreach ((array) $bao->addSelectWhereClause() as $field => $vals) {
49 if ($vals && $field == $joinColumn) {
50 $clauses = array_merge($clauses, (array) $vals);
53 $subclauses[] = "$field " . implode(" AND $field ", (array) $vals);
57 $clauses[] = "IN (SELECT `$joinColumn` FROM `" . $bao->tableName() . "` WHERE " . implode(' AND ', $subclauses) . ")";
63 * Get current sqlModes of the session
66 public static function getSqlModes() {
67 $sqlModes = explode(',', CRM_Core_DAO
::singleValueQuery('SELECT @@sql_mode'));
72 * Checks if this system enforce the MYSQL mode ONLY_FULL_GROUP_BY.
73 * This function should be named supportsAnyValueAndEnforcesFullGroupBY(),
74 * but should be deprecated instead.
79 public static function supportsFullGroupBy() {
80 // CRM-21455 MariaDB 10.2 does not support ANY_VALUE
81 $version = CRM_Core_DAO
::singleValueQuery('SELECT VERSION()');
83 if (stripos($version, 'mariadb') !== FALSE) {
87 return version_compare($version, '5.7', '>=');
91 * Disable ONLY_FULL_GROUP_BY for MySQL versions lower then 5.7
95 public static function disableFullGroupByMode() {
96 $sqlModes = self
::getSqlModes();
98 // Disable only_full_group_by mode for lower sql versions.
99 if (!self
::supportsFullGroupBy() ||
(!empty($sqlModes) && !in_array('ONLY_FULL_GROUP_BY', $sqlModes))) {
100 if ($key = array_search('ONLY_FULL_GROUP_BY', $sqlModes)) {
101 unset($sqlModes[$key]);
102 CRM_Core_DAO
::executeQuery("SET SESSION sql_mode = '" . implode(',', $sqlModes) . "'");
111 * CHeck if ONLY_FULL_GROUP_BY is in the global sql_modes
114 public static function isGroupByModeInDefault() {
115 $sqlModes = explode(',', CRM_Core_DAO
::singleValueQuery('SELECT @@global.sql_mode'));
116 if (!in_array('ONLY_FULL_GROUP_BY', $sqlModes)) {
123 * Is the Database set up to handle acceents.
124 * @warning This function was introduced in attempt to determine the reason why the test getInternationalStrings was failing on ubu1604 but passing on ubu1204-5
125 * This function should not be used as the basis of further work as the reasoning is not perfact and is giving false failures.
128 public static function supportStorageOfAccents() {
129 $charSetDB = CRM_Core_DAO
::executeQuery("SHOW VARIABLES LIKE 'character_set_database'")->fetchAll();
130 $charSet = $charSetDB[0]['Value'];
131 if ($charSet == 'utf8') {