From cf7384c13ab5970adc77e7582889becd09161d67 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sat, 19 Jun 2021 18:57:12 +1200 Subject: [PATCH] dev/membership#29 Add civicrm_line_item.membership_num_terms Specify table in query (no change in query meaning) --- CRM/Contribute/BAO/Contribution.php | 2 +- CRM/Price/DAO/LineItem.php | 22 +++++++++++++++++++++- CRM/Upgrade/Incremental/php/FiveForty.php | 3 +++ xml/schema/Price/LineItem.xml | 8 ++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 9309dc0d0f..e0f140a7bd 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -468,7 +468,7 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { */ public static function getNumTermsByContributionAndMembershipType($membershipTypeID, $contributionID) { $numTerms = CRM_Core_DAO::singleValueQuery(" - SELECT membership_num_terms FROM civicrm_line_item li + SELECT v.membership_num_terms FROM civicrm_line_item li LEFT JOIN civicrm_price_field_value v ON li.price_field_value_id = v.id WHERE contribution_id = %1 AND membership_type_id = %2", [1 => [$contributionID, 'Integer'], 2 => [$membershipTypeID, 'Integer']] diff --git a/CRM/Price/DAO/LineItem.php b/CRM/Price/DAO/LineItem.php index 4d027fbc98..98bae25c61 100644 --- a/CRM/Price/DAO/LineItem.php +++ b/CRM/Price/DAO/LineItem.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Price/LineItem.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:588f54f07db70f636888c88374b6b5b1) + * (GenCodeChecksum:27940b7d9e1152223c1fde0e32a8e909) */ /** @@ -129,6 +129,13 @@ class CRM_Price_DAO_LineItem extends CRM_Core_DAO { */ public $tax_amount; + /** + * Number of terms for this membership (only supported in Order->Payment flow). If the field is NULL it means unknown and it will be assumed to be 1 during payment.create if entity_table is civicrm_membership + * + * @var int + */ + public $membership_num_terms; + /** * Class constructor. */ @@ -444,6 +451,19 @@ class CRM_Price_DAO_LineItem extends CRM_Core_DAO { ], 'add' => '4.6', ], + 'membership_num_terms' => [ + 'name' => 'membership_num_terms', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('Number of membership terms purchased'), + 'description' => ts('Number of terms for this membership (only supported in Order->Payment flow). If the field is NULL it means unknown and it will be assumed to be 1 during payment.create if entity_table is civicrm_membership'), + 'where' => 'civicrm_line_item.membership_num_terms', + 'default' => 'NULL', + 'table_name' => 'civicrm_line_item', + 'entity' => 'LineItem', + 'bao' => 'CRM_Price_BAO_LineItem', + 'localizable' => 0, + 'add' => '5.40', + ], ]; CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); } diff --git a/CRM/Upgrade/Incremental/php/FiveForty.php b/CRM/Upgrade/Incremental/php/FiveForty.php index 83ddaf411e..55504c06c1 100644 --- a/CRM/Upgrade/Incremental/php/FiveForty.php +++ b/CRM/Upgrade/Incremental/php/FiveForty.php @@ -53,6 +53,9 @@ class CRM_Upgrade_Incremental_php_FiveForty extends CRM_Upgrade_Incremental_Base $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'); + $this->addTask('Add membership_num_terms column to civicrm_line_item', 'addColumn', + 'civicrm_line_item', 'membership_num_terms', "int unsigned DEFAULT NULL COMMENT 'Number of terms for this membership (only supported in Order->Payment flow). If the field is NULL it means unknown and it will be assumed to be 1 during payment.create if entity_table is civicrm_membership'" + ); } /** diff --git a/xml/schema/Price/LineItem.xml b/xml/schema/Price/LineItem.xml index 4e0f795bec..f53364ebcb 100644 --- a/xml/schema/Price/LineItem.xml +++ b/xml/schema/Price/LineItem.xml @@ -227,4 +227,12 @@ Text + + membership_num_terms + Number of membership terms purchased + int unsigned + NULL + Number of terms for this membership (only supported in Order->Payment flow). If the field is NULL it means unknown and it will be assumed to be 1 during payment.create if entity_table is civicrm_membership + 5.40 + -- 2.25.1