CRM-12274
authoryashodha <yashodha.chaku@webaccess.co.in>
Tue, 23 Apr 2013 00:58:43 +0000 (06:28 +0530)
committeryashodha <yashodha.chaku@webaccess.co.in>
Tue, 23 Apr 2013 00:59:06 +0000 (06:29 +0530)
CRM/Upgrade/Incremental/php/FourFour.php

index 7574a638f70213f38a9869a748455c2b6b81783c..d9badb956921af3d936a79660e6162c645582235 100644 (file)
@@ -78,36 +78,42 @@ class CRM_Upgrade_Incremental_php_FourFour {
    */
   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";