From 024d56cd52ba75f4e8bbd375c67ffb6812991b5d Mon Sep 17 00:00:00 2001 From: colemanw Date: Tue, 22 Aug 2023 19:05:42 -0400 Subject: [PATCH] Discount - Make entity_table required and add option list --- CRM/Core/BAO/Discount.php | 11 +++++++++++ CRM/Core/DAO/Discount.php | 8 ++++++-- CRM/Upgrade/Incremental/php/FiveSixtySix.php | 3 ++- CRM/Upgrade/Incremental/sql/5.66.alpha1.mysql.tpl | 3 +++ xml/schema/Core/Discount.xml | 4 ++++ 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CRM/Core/BAO/Discount.php b/CRM/Core/BAO/Discount.php index fb2b71bf00..f360709493 100644 --- a/CRM/Core/BAO/Discount.php +++ b/CRM/Core/BAO/Discount.php @@ -93,6 +93,17 @@ class CRM_Core_BAO_Discount extends CRM_Core_DAO_Discount { return parent::buildOptions($fieldName, $context, $values); } + /** + * Whitelist of possible values for the entity_table field + * + * @return array + */ + public static function entityTables(): array { + return [ + 'civicrm_event' => ts('Event'), + ]; + } + /** * Determine in which discount set the registration date falls. * diff --git a/CRM/Core/DAO/Discount.php b/CRM/Core/DAO/Discount.php index f37e4d7cda..d9d44b82fa 100644 --- a/CRM/Core/DAO/Discount.php +++ b/CRM/Core/DAO/Discount.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Core/Discount.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:8d80d6c79c0ecd92e22ed5ac74d59700) + * (GenCodeChecksum:83144959b102b14625522e9fae8dd8d8) */ /** @@ -42,7 +42,7 @@ class CRM_Core_DAO_Discount extends CRM_Core_DAO { /** * physical tablename for entity being joined to discount, e.g. civicrm_event * - * @var string|null + * @var string * (SQL type: varchar(64)) * Note that values will be retrieved from the database as a string. */ @@ -154,6 +154,7 @@ class CRM_Core_DAO_Discount extends CRM_Core_DAO { 'type' => CRM_Utils_Type::T_STRING, 'title' => ts('Entity Table'), 'description' => ts('physical tablename for entity being joined to discount, e.g. civicrm_event'), + 'required' => TRUE, 'maxlength' => 64, 'size' => CRM_Utils_Type::BIG, 'usage' => [ @@ -167,6 +168,9 @@ class CRM_Core_DAO_Discount extends CRM_Core_DAO { 'entity' => 'Discount', 'bao' => 'CRM_Core_BAO_Discount', 'localizable' => 0, + 'pseudoconstant' => [ + 'callback' => 'CRM_Core_BAO_Discount::entityTables', + ], 'add' => '2.1', ], 'entity_id' => [ diff --git a/CRM/Upgrade/Incremental/php/FiveSixtySix.php b/CRM/Upgrade/Incremental/php/FiveSixtySix.php index f54debcaa6..38423bd73f 100644 --- a/CRM/Upgrade/Incremental/php/FiveSixtySix.php +++ b/CRM/Upgrade/Incremental/php/FiveSixtySix.php @@ -30,7 +30,8 @@ class CRM_Upgrade_Incremental_php_FiveSixtySix extends CRM_Upgrade_Incremental_B public function upgrade_5_66_alpha1($rev): void { $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); // These run after the sql file - $this->addTask('Make ActionSchedule.name required', 'alterColumn', 'civicrm_action_schedule', 'name', "varchar(64) NOT NULL COMMENT 'Name of the action(reminder)'"); + $this->addTask('Make Discount.entity_table required', 'alterColumn', 'civicrm_discount', 'entity_table', "varchar(64) NOT NULL COMMENT 'Name of the action(reminder)'"); + $this->addTask('Make ActionSchedule.name required', 'alterColumn', 'civicrm_action_schedule', 'name', "varchar(64) NOT NULL COMMENT 'physical tablename for entity being joined to discount, e.g. civicrm_event'"); $this->addTask(ts('Create index %1', [1 => 'civicrm_action_schedule.UI_name']), 'addIndex', 'civicrm_action_schedule', 'name', 'UI'); $this->addTask('Add fields to civicrm_mail_settings to allow more flexibility for email to activity', 'addMailSettingsFields'); } diff --git a/CRM/Upgrade/Incremental/sql/5.66.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/5.66.alpha1.mysql.tpl index 0cf997d5bd..1560cfeadb 100644 --- a/CRM/Upgrade/Incremental/sql/5.66.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/5.66.alpha1.mysql.tpl @@ -5,3 +5,6 @@ UPDATE `civicrm_action_schedule` SET name = CONCAT('reminder_', id) WHERE name I UPDATE `civicrm_action_schedule` a1, `civicrm_action_schedule` a2 SET a2.name = CONCAT(a2.name, '_', a2.id) WHERE a2.name = a1.name AND a2.id > a1.id; + +{* Set default value for Discount.entity_table *} +UPDATE `civicrm_discount` SET `entity_table` = 'civicrm_event' WHERE `entity_table` IS NULL; diff --git a/xml/schema/Core/Discount.xml b/xml/schema/Core/Discount.xml index e9cc6d423d..8e7b921866 100644 --- a/xml/schema/Core/Discount.xml +++ b/xml/schema/Core/Discount.xml @@ -27,6 +27,10 @@ Entity Table varchar 64 + + CRM_Core_BAO_Discount::entityTables + + true physical tablename for entity being joined to discount, e.g. civicrm_event 2.1 -- 2.25.1