diff --git a/CRM/Event/DAO/Participant.php b/CRM/Event/DAO/Participant.php index e4cfd363b94ca83652300d1c7270a46f9189ddb0..aad57f4f226e4401b3e99f09e6f0510c4de62f07 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 6c38b980a0769d1fabc5c01c1e49c49e92597708..15b9032414e917087a0081a5b7fbab073230ee64 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 ad91d37c569e2ff9b9e7daca7069cabefe9d40a2..a93a914e9da52c1a1c0f78413ead44dff812d040 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 b05c01f2af59a0ec908a063283698884228ca391..46f3e159f7db397920de5ec8e0e15e2f8fcebc9b 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 31b4544542b09b9486ed079a665723d2abd3d40c..2b25f1e79367b7f536899a0dd6c7351c6847585a 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 9247cbb44191df73be50e0b40f9c941266051ea7..504afc47a1cf81d9c02ef21f71845fb0f0fe1ef5 100644 --- a/xml/schema/Event/Participant.xml +++ b/xml/schema/Event/Participant.xml @@ -208,7 +208,7 @@ <default>NULL</default> <comment>FK to Participant ID</comment> <html> - <label>Registered By</label> + <label>Registered By Participant</label> </html> <add>2.1</add> <export>true</export> @@ -338,4 +338,22 @@ <key>id</key> <onDelete>SET NULL</onDelete> </foreignKey> + <field> + <name>created_id</name> + <type>int unsigned</type> + <title>Created by Contact ID</title> + <comment>Contact responsible for registering this participant</comment> + <html> + <type>EntityRef</type> + <label>Created By</label> + </html> + <add>5.54</add> + </field> + <foreignKey> + <name>created_id</name> + <table>civicrm_contact</table> + <key>id</key> + <add>5.54</add> + <onDelete>SET NULL</onDelete> + </foreignKey> </table>