*/
static function activityContacts(CRM_Queue_TaskContext $ctx) {
$upgrade = new CRM_Upgrade_Form();
+
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
+ $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+ $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+
$query = "
-CREATE TABLE IF NOT EXISTS `civicrm_activity_contact` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Activity contact id',
- `activity_id` int(10) unsigned NOT NULL COMMENT 'Foreign key to the activity for this record.',
- `contact_id` int(10) unsigned NOT NULL COMMENT 'Foreign key to the contact for this record.',
- `record_type` enum('Source','Assignee','Target') COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'The record type for this row',
- PRIMARY KEY (`id`),
- UNIQUE KEY `UI_activity_contact_id` (`contact_id`,`activity_id`,`record_type`),
- KEY `FK_civicrm_activity_contact_activity_id` (`activity_id`)
+CREATE TABLE IF NOT EXISTS civicrm_activity_contact (
+ id int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Activity contact id',
+ activity_id int(10) unsigned NOT NULL COMMENT 'Foreign key to the activity for this record.',
+ contact_id int(10) unsigned NOT NULL COMMENT 'Foreign key to the contact for this record.',
+ record_type_id int(10) unsigned DEFAULT NULL COMMENT 'The record type id for this row',
+ PRIMARY KEY (id),
+ UNIQUE KEY UI_activity_contact (contact_id,activity_id,record_type_id),
+ KEY FK_civicrm_activity_contact_activity_id (activity_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
";
$dao = CRM_Core_DAO::executeQuery($query);
$query = "
-INSERT INTO civicrm_activity_contact (activity_id, contact_id, record_type)
-SELECT activity_id, target_contact_id, 'Target' as record_type
+INSERT INTO civicrm_activity_contact (activity_id, contact_id, record_type_id)
+SELECT activity_id, target_contact_id, {$targetID} as record_type_id
FROM civicrm_activity_target";
$dao = CRM_Core_DAO::executeQuery($query);
$query = "
-INSERT INTO civicrm_activity_contact (activity_id, contact_id, record_type)
-SELECT activity_id, assignee_contact_id, 'Assignee' as record_type
+INSERT INTO civicrm_activity_contact (activity_id, contact_id, record_type_id)
+SELECT activity_id, assignee_contact_id, {$assigneeID} as record_type_id
FROM civicrm_activity_assignment";
$dao = CRM_Core_DAO::executeQuery($query);
$query = "
- INSERT INTO civicrm_activity_contact (activity_id, contact_id, record_type)
-SELECT id, source_contact_id, 'Source' as record_type
+ INSERT INTO civicrm_activity_contact (activity_id, contact_id, record_type_id)
+SELECT id, source_contact_id, {$sourceID} as record_type_id
FROM civicrm_activity
WHERE source_contact_id IS NOT NULL";