From: Tim Otten Date: Tue, 26 Jan 2016 01:49:32 +0000 (-0800) Subject: SettingsBag - Fix upgrade failure for WP 4.4=>4.7 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=867a532bada3762b20e3c540397907eedb8efde3;p=civicrm-core.git SettingsBag - Fix upgrade failure for WP 4.4=>4.7 The WP integration attempts to define a new setting (`wpLoadPhp`) during bootstrap -- before upgrade logic has run. This was failing because the `group_name` property wouldn't get passed through by DAO (because the DAO is newer than the schema). --- diff --git a/CRM/Core/Config.php b/CRM/Core/Config.php index 79757178ea..a0b34fad49 100644 --- a/CRM/Core/Config.php +++ b/CRM/Core/Config.php @@ -413,6 +413,15 @@ class CRM_Core_Config extends CRM_Core_Config_MagicMerge { return TRUE; } + if ($path && preg_match('/^civicrm\/ajax\/l10n-js/', $path) + && !empty($_SERVER['HTTP_REFERER']) + ) { + $ref = parse_url($_SERVER['HTTP_REFERER']); + if (preg_match('/civicrm\/upgrade/', $ref['path']) || preg_match('/civicrm\/upgrade/', urldecode($ref['query']))) { + return TRUE; + } + } + return FALSE; } diff --git a/CRM/Utils/SQL/Insert.php b/CRM/Utils/SQL/Insert.php index 627473df14..e7f6d69dfd 100644 --- a/CRM/Utils/SQL/Insert.php +++ b/CRM/Utils/SQL/Insert.php @@ -50,6 +50,28 @@ class CRM_Utils_SQL_Insert { return new self($table); } + /** + * Insert a record based on a DAO. + * + * @param \CRM_Core_DAO $dao + * @return \CRM_Utils_SQL_Insert + * @throws \CRM_Core_Exception + */ + public static function dao(CRM_Core_DAO $dao) { + $table = CRM_Core_DAO::getLocaleTableName($dao->getTableName()); + $row = array(); + foreach ((array) $dao as $key => $value) { + if ($value === 'null') { + $value = NULL; // Blerg!!! + } + // Skip '_foobar' and '{\u00}*_options' and 'N'. + if (preg_match('/[a-zA-Z]/', $key{0}) && $key !== 'N') { + $row[$key] = $value; + } + } + return self::into($table)->row($row); + } + /** * Create a new SELECT query. * diff --git a/Civi/Core/SettingsBag.php b/Civi/Core/SettingsBag.php index 05fe3a1229..14585e999a 100644 --- a/Civi/Core/SettingsBag.php +++ b/Civi/Core/SettingsBag.php @@ -385,7 +385,14 @@ class SettingsBag { $dao->created_id = $session->get('userID'); } - $dao->save(); + if ($dao->id) { + $dao->save(); + } + else { + // Cannot use $dao->save(); in upgrade mode (eg WP + Civi 4.4=>4.7), the DAO will refuse + // to save the field `group_name`, which is required in older schema. + \CRM_Core_DAO::executeQuery(\CRM_Utils_SQL_Insert::dao($dao)->toSQL()); + } $dao->free(); }