From: yashodha Date: Fri, 5 Apr 2013 22:50:27 +0000 (+0530) Subject: worked on upgrade part CRM-12274 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a47a2f90438a9224831763877bd87206de88446e;p=civicrm-core.git worked on upgrade part CRM-12274 --- diff --git a/CRM/Upgrade/Incremental/php/FourFour.php b/CRM/Upgrade/Incremental/php/FourFour.php new file mode 100644 index 0000000000..7574a638f7 --- /dev/null +++ b/CRM/Upgrade/Incremental/php/FourFour.php @@ -0,0 +1,166 @@ +addTask(ts('Upgrade DB to 4.4.alpha1: SQL'), 'task_4_4_x_runSql', $rev); + + // Consolidate activity contacts CRM-12274. + $this->addTask(ts('Consolidate activity contacts'), 'activityContacts'); + + return TRUE; + } + + /** + * Update activity contacts CRM-12274 + * + * @return bool TRUE for success + */ + static function activityContacts(CRM_Queue_TaskContext $ctx) { + $upgrade = new CRM_Upgrade_Form(); + $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`) +) 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 +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 +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 +FROM civicrm_activity +WHERE source_contact_id IS NOT NULL"; + + $dao = CRM_Core_DAO::executeQuery($query); + + $query = "DROP TABLE civicrm_activity_target"; + $dao = CRM_Core_DAO::executeQuery($query); + + $query = "DROP TABLE civicrm_activity_assignment"; + $dao = CRM_Core_DAO::executeQuery($query); + + $query = "ALTER TABLE civicrm_activity + DROP FOREIGN KEY FK_civicrm_activity_source_contact_id"; + + $dao = CRM_Core_DAO::executeQuery($query); + + $query = "ALTER TABLE civicrm_activity DROP COLUMN source_contact_id"; + $dao = CRM_Core_DAO::executeQuery($query); + + return TRUE; + } + + /** + * (Queue Task Callback) + */ + static function task_4_4_x_runSql(CRM_Queue_TaskContext $ctx, $rev) { + $upgrade = new CRM_Upgrade_Form(); + $upgrade->processSQL($rev); + + return TRUE; + } + + /** + * Syntatic sugar for adding a task which (a) is in this class and (b) has + * a high priority. + * + * After passing the $funcName, you can also pass parameters that will go to + * the function. Note that all params must be serializable. + */ + protected function addTask($title, $funcName) { + $queue = CRM_Queue_Service::singleton()->load(array( + 'type' => 'Sql', + 'name' => CRM_Upgrade_Form::QUEUE_NAME, + )); + + $args = func_get_args(); + $title = array_shift($args); + $funcName = array_shift($args); + $task = new CRM_Queue_Task( + array(get_class($this), $funcName), + $args, + $title + ); + $queue->createItem($task, array('weight' => -1)); + } +} diff --git a/CRM/Upgrade/Incremental/sql/4.4.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.4.alpha1.mysql.tpl new file mode 100644 index 0000000000..e69de29bb2