3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
30 * @copyright CiviCRM LLC (c) 2004-2013
34 class CRM_Upgrade_Incremental_php_FourFour
{
35 const BATCH_SIZE
= 5000;
37 function verifyPreDBstate(&$errors) {
42 * Compute any messages which should be displayed beforeupgrade
44 * Note: This function is called iteratively for each upcoming
45 * revision to the database.
47 * @param $postUpgradeMessage string, alterable
48 * @param $rev string, a version number, e.g. '4.4.alpha1', '4.4.beta3', '4.4.0'
51 function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) {
55 * Compute any messages which should be displayed after upgrade
57 * @param $postUpgradeMessage string, alterable
58 * @param $rev string, an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs
61 function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
62 if ($rev == '4.4.alpha1') {
63 $config = CRM_Core_Config
::singleton();
64 if (!empty($config->useIDS
)) {
65 $postUpgradeMessage .= '<br />' . ts("The setting to skip IDS check has been deprecated. Please use the permission 'skip IDS check' to bypass the IDS system");
70 function upgrade_4_4_alpha1($rev) {
71 // task to process sql
72 $this->addTask(ts('Upgrade DB to 4.4.alpha1: SQL'), 'task_4_4_x_runSql', $rev);
74 // Consolidate activity contacts CRM-12274.
75 $this->addTask(ts('Consolidate activity contacts'), 'activityContacts');
80 function upgrade_4_4_beta1($rev) {
81 $this->addTask(ts('Upgrade DB to 4.4.beta1: SQL'), 'task_4_4_x_runSql', $rev);
83 // check if batch entry data exists in civicrm_cache table
84 $query = 'SELECT path, data FROM civicrm_cache WHERE group_name = "batch entry"';
85 $dao = CRM_Core_DAO
::executeQuery($query);
86 while ($dao->fetch()) {
87 // get batch id $batchId[2]
88 $batchId = explode('-', $dao->path
);
89 $data = unserialize($dao->data
);
91 // move the data to civicrm_batch table
92 CRM_Core_DAO
::setFieldValue('CRM_Batch_DAO_Batch', $batchId[2], 'data', json_encode(array('values' => $data)));
95 // delete entries from civicrm_cache table
96 $query = 'DELETE FROM civicrm_cache WHERE group_name = "batch entry"';
97 CRM_Core_DAO
::executeQuery($query);
101 * Update activity contacts CRM-12274
103 * @return bool TRUE for success
105 static function activityContacts(CRM_Queue_TaskContext
$ctx) {
106 $upgrade = new CRM_Upgrade_Form();
108 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
109 $ovValue[] = $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
110 $ovValue[] = $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
111 $ovValue[] = $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
113 $optionGroupID = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup', 'activity_contacts', 'id', 'name');
114 if (!empty($ovValue)) {
115 $ovValues = implode(', ', $ovValue);
117 UPDATE civicrm_option_value
119 WHERE option_group_id = {$optionGroupID} AND value IN ($ovValues)";
121 $dao = CRM_Core_DAO
::executeQuery($query);
126 $value[] = "({$optionGroupID}, 'Activity Assignees', 1, 'Activity Assignees', 1, 1, 1)";
130 $value[] = "({$optionGroupID}, 'Activity Source', 2, 'Activity Source', 2, 1, 1)";
134 $value[] = "({$optionGroupID}, 'Activity Targets', 3, 'Activity Targets', 3, 1, 1)";
137 if (!$assigneeID ||
!$sourceID ||
!$targetID ) {
139 INSERT INTO civicrm_option_value
140 (option_group_id, label, value, name, weight, is_reserved, is_active)
144 $values = implode(', ', $value);
145 $query = $insert . $values;
146 $dao = CRM_Core_DAO
::executeQuery($query);
151 CREATE TABLE IF NOT EXISTS civicrm_activity_contact (
152 id int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Activity contact id',
153 activity_id int(10) unsigned NOT NULL COMMENT 'Foreign key to the activity for this record.',
154 contact_id int(10) unsigned NOT NULL COMMENT 'Foreign key to the contact for this record.',
155 record_type_id int(10) unsigned DEFAULT NULL COMMENT 'The record type id for this row',
157 UNIQUE KEY UI_activity_contact (contact_id,activity_id,record_type_id),
158 KEY FK_civicrm_activity_contact_activity_id (activity_id)
159 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
162 $dao = CRM_Core_DAO
::executeQuery($query);
165 INSERT INTO civicrm_activity_contact (activity_id, contact_id, record_type_id)
166 SELECT activity_id, target_contact_id, {$targetID} as record_type_id
167 FROM civicrm_activity_target";
169 $dao = CRM_Core_DAO
::executeQuery($query);
172 INSERT INTO civicrm_activity_contact (activity_id, contact_id, record_type_id)
173 SELECT activity_id, assignee_contact_id, {$assigneeID} as record_type_id
174 FROM civicrm_activity_assignment";
175 $dao = CRM_Core_DAO
::executeQuery($query);
178 INSERT INTO civicrm_activity_contact (activity_id, contact_id, record_type_id)
179 SELECT id, source_contact_id, {$sourceID} as record_type_id
180 FROM civicrm_activity
181 WHERE source_contact_id IS NOT NULL";
183 $dao = CRM_Core_DAO
::executeQuery($query);
185 $query = "DROP TABLE civicrm_activity_target";
186 $dao = CRM_Core_DAO
::executeQuery($query);
188 $query = "DROP TABLE civicrm_activity_assignment";
189 $dao = CRM_Core_DAO
::executeQuery($query);
191 $query = "ALTER TABLE civicrm_activity
192 DROP FOREIGN KEY FK_civicrm_activity_source_contact_id";
194 $dao = CRM_Core_DAO
::executeQuery($query);
196 $query = "ALTER TABLE civicrm_activity DROP COLUMN source_contact_id";
197 $dao = CRM_Core_DAO
::executeQuery($query);
203 * (Queue Task Callback)
205 static function task_4_4_x_runSql(CRM_Queue_TaskContext
$ctx, $rev) {
206 $upgrade = new CRM_Upgrade_Form();
207 $upgrade->processSQL($rev);
213 * Syntatic sugar for adding a task which (a) is in this class and (b) has
216 * After passing the $funcName, you can also pass parameters that will go to
217 * the function. Note that all params must be serializable.
219 protected function addTask($title, $funcName) {
220 $queue = CRM_Queue_Service
::singleton()->load(array(
222 'name' => CRM_Upgrade_Form
::QUEUE_NAME
,
225 $args = func_get_args();
226 $title = array_shift($args);
227 $funcName = array_shift($args);
228 $task = new CRM_Queue_Task(
229 array(get_class($this), $funcName),
233 $queue->createItem($task, array('weight' => -1));