Ejegg has submitted this change and it was merged. Change subject: Fix custom table naming when table_name is not set ......................................................................
Fix custom table naming when table_name is not set This is important when writing migrations for legacy tables which were created from the UI. In this case, we want Civi to build table name like "civicrm_value_GROUPNAME_ID". Note that this only affects dev and test installs. Change-Id: I25fcf9cccecd6e33cacfb7b1b9280f5eed028ac3 --- M CRM/Core/BAO/CustomField.php M CRM/Core/BAO/CustomGroup.php M patches/civicrm-4.2.19-drupal-wmf-custom-names.patch 3 files changed, 15 insertions(+), 11 deletions(-) Approvals: Ejegg: Looks good to me, approved jenkins-bot: Verified diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index f734d65..f414984 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -2225,6 +2225,7 @@ return $dao->id; } else { + // FIXME: This should be an exception. return NULL; } } diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index 3df400b..951c9f6 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -140,15 +140,6 @@ $group->created_id = CRM_Utils_Array::value('created_id', $params); $group->created_date = CRM_Utils_Array::value('created_date', $params); - - // lets create the table associated with the group and save it - if (isset($params['table_name'])) { - $tableName = $params['table_name']; - } else { - $munged_title = strtolower(CRM_Utils_String::munge($group->title, '_', 32)); - $tableName = "civicrm_value_{$munged_title}_{$group->id}"; - } - // we do this only once, so name never changes $group->name = CRM_Utils_String::munge($params['title'], '_', 64); if (isset($params['name'])) { @@ -163,7 +154,15 @@ $transaction = new CRM_Core_Transaction(); $group->save(); - if ($tableName) { + + if (isset($params['table_name'])) { + $tableName = $params['table_name']; + } else { + $munged_title = strtolower(CRM_Utils_String::munge($group->title, '_', 32)); + $tableName = "civicrm_value_{$munged_title}_{$group->id}"; + } + + if (!isset($params['id'])) { $group->table_name = $tableName; CRM_Core_DAO::setFieldValue('CRM_Core_DAO_CustomGroup', $group->id, @@ -190,7 +189,7 @@ // reset the cache CRM_Utils_System::flushCache(); - if ($tableName) { + if (!isset($params['id'])) { CRM_Utils_Hook::post('create', 'CustomGroup', $group->id, $group); } else { diff --git a/patches/civicrm-4.2.19-drupal-wmf-custom-names.patch b/patches/civicrm-4.2.19-drupal-wmf-custom-names.patch index 41f858d..2807c90 100644 --- a/patches/civicrm-4.2.19-drupal-wmf-custom-names.patch +++ b/patches/civicrm-4.2.19-drupal-wmf-custom-names.patch @@ -1,3 +1,7 @@ +Note: this code was wrong for the case where table_name is not passed in. +The change has been upstreamed correctly, abandon this. + +I donno what the is_view thing was about. diff -urN civicrm-4.2.19/CRM/Core/BAO/CustomField.php civicrm-4.2.19-wmf/CRM/Core/BAO/CustomField.php --- civicrm-4.2.19/CRM/Core/BAO/CustomField.php 2014-09-09 15:40:20.000000000 -0700 +++ civicrm-4.2.19-wmf/CRM/Core/BAO/CustomField.php 2015-03-11 13:31:10.274248477 -0700 -- To view, visit https://gerrit.wikimedia.org/r/218407 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I25fcf9cccecd6e33cacfb7b1b9280f5eed028ac3 Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/crm/civicrm Gerrit-Branch: master Gerrit-Owner: Awight <awi...@wikimedia.org> Gerrit-Reviewer: AndyRussG <andrew.green...@gmail.com> Gerrit-Reviewer: Awight <awi...@wikimedia.org> Gerrit-Reviewer: Cdentinger <cdentin...@wikimedia.org> Gerrit-Reviewer: Ejegg <eeggles...@wikimedia.org> Gerrit-Reviewer: Katie Horn <kh...@wikimedia.org> Gerrit-Reviewer: Ssmith <ssm...@wikimedia.org> Gerrit-Reviewer: XenoRyet <dkozlow...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits