Ejegg has submitted this change and it was merged.

Change subject: (backport from 4.7) CRM-17394 - Initialize DB slightly later. 
Fix query-log and redundant SET NAMES.
......................................................................


(backport from 4.7) CRM-17394 - Initialize DB slightly later. Fix query-log and 
redundant SET NAMES.

Strictly speaking, this patch does two different things:
 * Initialize DB slightly later. This fixes a race among settings-manager, DB 
init, and query logging.
 * Call `SET NAMES utf8` once during connection init. Before, it was called 
once for every DAO object.

Based on quick spot-check, it still seems to store UTF-8 data. To be safe,
I've added an extra error-check to ensure that the `SET NAMES utf8` is still
called before we actually use the DAO.

Bug: T116724

Change-Id: I6715339b6854a23e2f127718fc4eba380a701b8a
---
M CRM/Core/DAO.php
M CRM/Core/Error.php
2 files changed, 13 insertions(+), 4 deletions(-)

Approvals:
  Ejegg: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php
index d6e3b6d..d142405 100644
--- a/CRM/Core/DAO.php
+++ b/CRM/Core/DAO.php
@@ -99,15 +99,19 @@
    *
    * @param string $dsn
    *   The database connection string.
-   *
-   * @return void
    */
   public static function init($dsn) {
+    Civi::$statics[__CLASS__]['init'] = 1;
     $options = &PEAR::getStaticProperty('DB_DataObject', 'options');
     $options['database'] = $dsn;
     if (defined('CIVICRM_DAO_DEBUG')) {
       self::DebugLevel(CIVICRM_DAO_DEBUG);
     }
+    CRM_Core_DAO::setFactory(new CRM_Contact_DAO_Factory());
+    if (CRM_Utils_Constant::value('CIVICRM_MYSQL_STRICT', 
CRM_Utils_System::isDevelopment())) {
+      CRM_Core_DAO::executeQuery('SET SESSION sql_mode = STRICT_TRANS_TABLES');
+    }
+    CRM_Core_DAO::executeQuery('SET NAMES utf8');
   }
 
   /**
@@ -360,7 +364,12 @@
    */
   public function initialize() {
     $this->_connect();
-    $this->query("SET NAMES utf8");
+    if (empty(Civi::$statics[__CLASS__]['init'])) {
+      // CRM_Core_DAO::init() must be called before CRM_Core_DAO->initialize().
+      // This occurs very early in bootstrap - error handlers may not be wired 
up.
+      echo "Inconsistent system initialization sequence. Premature access of 
(" . get_class($this) . ")";
+      CRM_Utils_System::civiExit();
+    }
   }
 
   /**
diff --git a/CRM/Core/Error.php b/CRM/Core/Error.php
index 36074d5..dbeadcf 100644
--- a/CRM/Core/Error.php
+++ b/CRM/Core/Error.php
@@ -592,7 +592,7 @@
     }
     $file_log->close();
 
-    if ($config->userFrameworkLogging) {
+    if (!empty($config->userFrameworkLogging)) {
       // should call $config->userSystem->logger($message) here - but I got a 
situation where userSystem was not an object - not sure why
       if ($config->userSystem->is_drupal and function_exists('watchdog')) {
         watchdog('civicrm', '%message', array('%message' => $message), 
WATCHDOG_DEBUG);

-- 
To view, visit https://gerrit.wikimedia.org/r/256163
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6715339b6854a23e2f127718fc4eba380a701b8a
Gerrit-PatchSet: 6
Gerrit-Project: wikimedia/fundraising/crm/civicrm
Gerrit-Branch: master
Gerrit-Owner: Eileen <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Eileen <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: Totten <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to