From b38fa0b6669cdb951ae4cedb68c6c29d41911c15 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Tue, 9 Aug 2022 11:41:11 +0100 Subject: [PATCH] Add created_id field to civicrm_participant --- CRM/Event/DAO/Participant.php | 31 +++++++++++++++++-- CRM/Upgrade/Incremental/php/FiveFiftyFour.php | 9 ++++++ tests/phpunit/CRM/Dedupe/MergerTest.php | 3 +- .../phpunit/CRM/Event/BAO/ParticipantTest.php | 1 + .../CRM/Utils/TokenConsistencyTest.php | 2 ++ xml/schema/Event/Participant.xml | 20 +++++++++++- 6 files changed, 62 insertions(+), 4 deletions(-) diff --git a/CRM/Event/DAO/Participant.php b/CRM/Event/DAO/Participant.php index e4cfd363b9..aad57f4f22 100644 --- a/CRM/Event/DAO/Participant.php +++ b/CRM/Event/DAO/Participant.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Event/Participant.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:69f3a659171cd9e8d162720e620a446d) + * (GenCodeChecksum:ebc70049a0ce4ebc8b7abce72db42fbb) */ /** @@ -206,6 +206,15 @@ class CRM_Event_DAO_Participant extends CRM_Core_DAO { */ public $transferred_to_contact_id; + /** + * Contact responsible for registering this participant + * + * @var int|string|null + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. + */ + public $created_id; + /** * Class constructor. */ @@ -250,6 +259,7 @@ class CRM_Event_DAO_Participant extends CRM_Core_DAO { Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'campaign_id', 'civicrm_campaign', 'id'); Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'cart_id', 'civicrm_event_carts', 'id'); Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'transferred_to_contact_id', 'civicrm_contact', 'id'); + Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'created_id', 'civicrm_contact', 'id'); CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']); } return Civi::$statics[__CLASS__]['links']; @@ -499,7 +509,7 @@ class CRM_Event_DAO_Participant extends CRM_Core_DAO { 'localizable' => 0, 'FKClassName' => 'CRM_Event_DAO_Participant', 'html' => [ - 'label' => ts("Registered By"), + 'label' => ts("Registered By Participant"), ], 'add' => '2.1', ], @@ -635,6 +645,23 @@ class CRM_Event_DAO_Participant extends CRM_Core_DAO { ], 'add' => '4.7', ], + 'created_id' => [ + 'name' => 'created_id', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('Created by Contact ID'), + 'description' => ts('Contact responsible for registering this participant'), + 'where' => 'civicrm_participant.created_id', + 'table_name' => 'civicrm_participant', + 'entity' => 'Participant', + 'bao' => 'CRM_Event_BAO_Participant', + 'localizable' => 0, + 'FKClassName' => 'CRM_Contact_DAO_Contact', + 'html' => [ + 'type' => 'EntityRef', + 'label' => ts("Created By"), + ], + 'add' => '5.54', + ], ]; CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); } diff --git a/CRM/Upgrade/Incremental/php/FiveFiftyFour.php b/CRM/Upgrade/Incremental/php/FiveFiftyFour.php index 6c38b980a0..15b9032414 100644 --- a/CRM/Upgrade/Incremental/php/FiveFiftyFour.php +++ b/CRM/Upgrade/Incremental/php/FiveFiftyFour.php @@ -38,6 +38,15 @@ class CRM_Upgrade_Incremental_php_FiveFiftyFour extends CRM_Upgrade_Incremental_ */ public function upgrade_5_54_alpha1($rev): void { $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); + $this->addTask('Add "created_id" column to "civicrm_participant"', 'addCreatedIDColumnToParticipant'); + } + + public static function addCreatedIDColumnToParticipant($ctx): bool { + CRM_Upgrade_Incremental_Base::addColumn($ctx, 'civicrm_participant', 'created_id', 'int(10) UNSIGNED DEFAULT NULL COMMENT "Created by Contact ID"'); + if (!CRM_Core_BAO_SchemaHandler::checkFKExists('civicrm_participant', 'FK_civicrm_participant_created_id')) { + CRM_Core_DAO::executeQuery('ALTER TABLE `civicrm_participant` ADD CONSTRAINT `FK_civicrm_participant_created_id` FOREIGN KEY (`created_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE SET NULL;'); + } + return TRUE; } } diff --git a/tests/phpunit/CRM/Dedupe/MergerTest.php b/tests/phpunit/CRM/Dedupe/MergerTest.php index 3403c22458..8512e0fe76 100644 --- a/tests/phpunit/CRM/Dedupe/MergerTest.php +++ b/tests/phpunit/CRM/Dedupe/MergerTest.php @@ -1360,8 +1360,9 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase { ], 'civicrm_participant' => [ 0 => 'contact_id', + 1 => 'created_id', //CRM-16761 - 1 => 'transferred_to_contact_id', + 2 => 'transferred_to_contact_id', ], 'civicrm_payment_token' => [ 0 => 'contact_id', diff --git a/tests/phpunit/CRM/Event/BAO/ParticipantTest.php b/tests/phpunit/CRM/Event/BAO/ParticipantTest.php index b05c01f2af..46f3e159f7 100644 --- a/tests/phpunit/CRM/Event/BAO/ParticipantTest.php +++ b/tests/phpunit/CRM/Event/BAO/ParticipantTest.php @@ -102,6 +102,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { 'cart_id' => NULL, 'must_wait' => NULL, 'transferred_to_contact_id' => NULL, + 'created_id' => NULL, ]; foreach ($compareValues as $key => $value) { diff --git a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php index ef491e0656..7b94efc82a 100644 --- a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php +++ b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php @@ -584,6 +584,7 @@ participant.fee_level :steep participant.fee_amount :$50.00 participant.registered_by_id : participant.transferred_to_contact_id : +participant.created_id : participant.role_id:label :Attendee participant.balance : participant.custom_2 :99999 @@ -706,6 +707,7 @@ December 21st, 2007 '{participant.fee_amount}' => 'Fee Amount', '{participant.registered_by_id}' => 'Registered By Participant ID', '{participant.transferred_to_contact_id}' => 'Transferred to Contact ID', + '{participant.created_id}' => 'Created by Contact ID', '{participant.role_id:label}' => 'Participant Role', '{participant.balance}' => 'Event Balance', '{participant.' . $this->getCustomFieldName('participant_int') . '}' => 'Enter integer here :: participant_Group with field int', diff --git a/xml/schema/Event/Participant.xml b/xml/schema/Event/Participant.xml index 9247cbb441..504afc47a1 100644 --- a/xml/schema/Event/Participant.xml +++ b/xml/schema/Event/Participant.xml @@ -208,7 +208,7 @@ NULL FK to Participant ID - + 2.1 true @@ -338,4 +338,22 @@ id SET NULL + + created_id + int unsigned + Created by Contact ID + Contact responsible for registering this participant + + EntityRef + + + 5.54 + + + created_id + civicrm_contact
+ id + 5.54 + SET NULL +
-- 2.25.1