From 8ced16c78b3d086cbd303117ebac085348c91df6 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 8 Jun 2021 08:37:38 -0400 Subject: [PATCH] Convert Notes to use option_group instead of hardcoded list --- CRM/Core/BAO/Note.php | 13 ------------ CRM/Core/DAO/Note.php | 5 +++-- CRM/Upgrade/Incremental/php/FiveForty.php | 25 +++++++++++++++++++++++ xml/schema/Core/Note.xml | 2 +- xml/templates/civicrm_data.tpl | 8 ++++++++ 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/CRM/Core/BAO/Note.php b/CRM/Core/BAO/Note.php index a08dbacf4f..85cc99bd2b 100644 --- a/CRM/Core/BAO/Note.php +++ b/CRM/Core/BAO/Note.php @@ -565,17 +565,4 @@ WHERE participant.contact_id = %1 AND note.entity_table = 'civicrm_participant' } } - /** - * Whitelist of possible values for the entity_table field - * @return array - */ - public static function entityTables() { - return array( - 'civicrm_relationship' => 'Relationship', - 'civicrm_contact' => 'Contact', - 'civicrm_participant' => 'Participant', - 'civicrm_contribution' => 'Contribution', - ); - } - } diff --git a/CRM/Core/DAO/Note.php b/CRM/Core/DAO/Note.php index 35067ea292..4370b6d075 100644 --- a/CRM/Core/DAO/Note.php +++ b/CRM/Core/DAO/Note.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Core/Note.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:a84f607a5a29a8977287f694f05ab721) + * (GenCodeChecksum:49a15912788803e8ccf5298fe93932aa) */ /** @@ -180,7 +180,8 @@ class CRM_Core_DAO_Note extends CRM_Core_DAO { 'bao' => 'CRM_Core_BAO_Note', 'localizable' => 0, 'pseudoconstant' => [ - 'callback' => 'CRM_Core_BAO_Note::entityTables', + 'optionGroupName' => 'note_used_for', + 'optionEditPath' => 'civicrm/admin/options/note_used_for', ], 'add' => '1.1', ], diff --git a/CRM/Upgrade/Incremental/php/FiveForty.php b/CRM/Upgrade/Incremental/php/FiveForty.php index a27a780970..83ddaf411e 100644 --- a/CRM/Upgrade/Incremental/php/FiveForty.php +++ b/CRM/Upgrade/Incremental/php/FiveForty.php @@ -51,9 +51,34 @@ class CRM_Upgrade_Incremental_php_FiveForty extends CRM_Upgrade_Incremental_Base public function upgrade_5_40_alpha1($rev) { $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); + $this->addTask('Add option list for group_used_for', 'addGroupOptionList'); $this->addTask('core-issue#2486 - Add product_id foreign key to civicrm_contribution_product', 'addContributionProductFK'); } + /** + * @param CRM_Queue_TaskContext $ctx + * @return bool + */ + public static function addGroupOptionList(CRM_Queue_TaskContext $ctx) { + $optionGroupId = \CRM_Core_BAO_OptionGroup::ensureOptionGroupExists([ + 'name' => 'note_used_for', + 'title' => ts('Note Used For'), + 'is_reserved' => 1, + 'is_active' => 1, + 'is_locked' => 1, + ]); + $values = [ + ['value' => 'civicrm_relationship', 'name' => 'Relationship', 'label' => ts('Relationships')], + ['value' => 'civicrm_contact', 'name' => 'Contact', 'label' => ts('Contacts')], + ['value' => 'civicrm_participant', 'name' => 'Participant', 'label' => ts('Participants')], + ['value' => 'civicrm_contribution', 'name' => 'Contribution', 'label' => ts('Contributions')], + ]; + foreach ($values as $value) { + \CRM_Core_BAO_OptionValue::ensureOptionValueExists($value + ['option_group_id' => $optionGroupId]); + } + return TRUE; + } + /** * @param \CRM_Queue_TaskContext $ctx * diff --git a/xml/schema/Core/Note.xml b/xml/schema/Core/Note.xml index dd0ef304a5..87f9b45f65 100644 --- a/xml/schema/Core/Note.xml +++ b/xml/schema/Core/Note.xml @@ -31,7 +31,7 @@ true Name of table where item being referenced is stored. - CRM_Core_BAO_Note::entityTables + note_used_for 1.1 diff --git a/xml/templates/civicrm_data.tpl b/xml/templates/civicrm_data.tpl index 7898670885..24f7ab5171 100644 --- a/xml/templates/civicrm_data.tpl +++ b/xml/templates/civicrm_data.tpl @@ -164,6 +164,7 @@ VALUES ('contact_reference_options' , '{ts escape="sql"}Contact Reference Autocomplete Options{/ts}', NULL, 1, 1, 1), ('website_type' , '{ts escape="sql"}Website Type{/ts}' , NULL, 1, 1, 0), ('tag_used_for' , '{ts escape="sql"}Tag Used For{/ts}' , NULL, 1, 1, 1), + ('note_used_for' , '{ts escape="sql"}Note Used For{/ts}' , NULL, 1, 1, 1), ('currencies_enabled' , '{ts escape="sql"}Currencies Enabled{/ts}' , NULL, 1, 1, 0), ('event_badge' , '{ts escape="sql"}Event Name Badge{/ts}' , NULL, 1, 1, 0), ('note_privacy' , '{ts escape="sql"}Privacy levels for notes{/ts}' , NULL, 1, 1, 0), @@ -248,6 +249,7 @@ SELECT @option_group_id_acsOpt := max(id) from civicrm_option_group wher SELECT @option_group_id_acConRef := max(id) from civicrm_option_group where name = 'contact_reference_options'; SELECT @option_group_id_website := max(id) from civicrm_option_group where name = 'website_type'; SELECT @option_group_id_tuf := max(id) from civicrm_option_group where name = 'tag_used_for'; +SELECT @option_group_id_nuf := max(id) from civicrm_option_group where name = 'note_used_for'; SELECT @option_group_id_currency := max(id) from civicrm_option_group where name = 'currencies_enabled'; SELECT @option_group_id_eventBadge := max(id) from civicrm_option_group where name = 'event_badge'; SELECT @option_group_id_notePrivacy := max(id) from civicrm_option_group where name = 'note_privacy'; @@ -755,6 +757,12 @@ VALUES (@option_group_id_tuf, '{ts escape="sql"}Cases{/ts}', 'civicrm_case', 'Case', NULL, 0, NULL, 3, NULL, 0, 0, 1, NULL, NULL, NULL), (@option_group_id_tuf, '{ts escape="sql"}Attachments{/ts}', 'civicrm_file', 'File', NULL, 0, NULL, 4, NULL, 0, 0, 1, NULL, NULL, NULL), +-- Note used for + (@option_group_id_nuf, '{ts escape="sql"}Contacts{/ts}', 'civicrm_contact', 'Contact', NULL, 0, NULL, 1, NULL, 0, 0, 1, NULL, NULL, NULL), + (@option_group_id_nuf, '{ts escape="sql"}Relationships{/ts}', 'civicrm_relationship', 'Relationship', NULL, 0, NULL, 2, NULL, 0, 0, 1, NULL, NULL, NULL), + (@option_group_id_nuf, '{ts escape="sql"}Participants{/ts}', 'civicrm_participant', 'Participant', NULL, 0, NULL, 3, NULL, 0, 0, 1, NULL, NULL, NULL), + (@option_group_id_nuf, '{ts escape="sql"}Contributions{/ts}', 'civicrm_contribution', 'Contribution', NULL, 0, NULL, 4, NULL, 0, 0, 1, NULL, NULL, NULL), + (@option_group_id_currency, 'USD ($)', 'USD', 'USD', NULL, 0, 1, 1, NULL, 0, 0, 1, NULL, NULL, NULL), -- event name badges -- 2.25.1