4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.6 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License along with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
35 class CRM_Upgrade_Incremental_php_ThreeThree
{
41 public function verifyPreDBstate(&$errors) {
48 public function upgrade_3_3_alpha1($rev) {
49 $config = CRM_Core_Config
::singleton();
50 if ($config->userSystem
->is_drupal
) {
51 // CRM-6426 - make civicrm profiles permissioned on drupal my account
52 $config->userSystem
->updateCategories();
56 // insert name column for custom field table.
57 // make sure name for custom field, group and
58 // profile should be unique and properly munged.
59 $colQuery = 'ALTER TABLE `civicrm_custom_field` ADD `name` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL AFTER `custom_group_id` ';
60 CRM_Core_DAO
::executeQuery($colQuery, CRM_Core_DAO
::$_nullArray, TRUE, NULL, FALSE, FALSE);
62 $customFldCntQuery = 'select count(*) from civicrm_custom_field where name like %1 and id != %2';
63 $customField = new CRM_Core_DAO_CustomField();
64 $customField->selectAdd();
65 $customField->selectAdd('id, label');
67 while ($customField->fetch()) {
68 $name = CRM_Utils_String
::munge($customField->label
, '_', 64);
69 $fldCnt = CRM_Core_DAO
::singleValueQuery($customFldCntQuery,
71 1 => array($name, 'String'),
72 2 => array($customField->id
, 'Integer'),
76 $name = CRM_Utils_String
::munge("{$name}_" . rand(), '_', 64);
79 Update `civicrm_custom_field`
83 $customFieldParams = array(
84 1 => array($name, 'String'),
85 2 => array($customField->id
, 'Integer'),
87 CRM_Core_DAO
::executeQuery($customFieldQuery, $customFieldParams, TRUE, NULL, FALSE, FALSE);
91 $customGrpCntQuery = 'select count(*) from civicrm_custom_group where name like %1 and id != %2';
92 $customGroup = new CRM_Core_DAO_CustomGroup();
93 $customGroup->selectAdd();
94 $customGroup->selectAdd('id, title');
96 while ($customGroup->fetch()) {
97 $name = CRM_Utils_String
::munge($customGroup->title
, '_', 64);
98 $grpCnt = CRM_Core_DAO
::singleValueQuery($customGrpCntQuery,
100 1 => array($name, 'String'),
101 2 => array($customGroup->id
, 'Integer'),
105 $name = CRM_Utils_String
::munge("{$name}_" . rand(), '_', 64);
107 CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_CustomGroup', $customGroup->id
, 'name', $name);
109 $customGroup->free();
111 $ufGrpCntQuery = 'select count(*) from civicrm_uf_group where name like %1 and id != %2';
112 $ufGroup = new CRM_Core_DAO_UFGroup();
113 $ufGroup->selectAdd();
114 $ufGroup->selectAdd('id, title');
116 while ($ufGroup->fetch()) {
117 $name = CRM_Utils_String
::munge($ufGroup->title
, '_', 64);
118 $ufGrpCnt = CRM_Core_DAO
::singleValueQuery($ufGrpCntQuery,
120 1 => array($name, 'String'),
121 2 => array($ufGroup->id
, 'Integer'),
125 $name = CRM_Utils_String
::munge("{$name}_" . rand(), '_', 64);
127 CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_UFGroup', $ufGroup->id
, 'name', $name);
131 $upgrade = new CRM_Upgrade_Form();
132 $upgrade->processSQL($rev);
134 // now modify the config so that the directories are stored in option group/value
136 // require_once 'CRM/Core/BAO/ConfigSetting.php';
137 // $params = array( );
138 // CRM_Core_BAO_ConfigSetting::add( $parambs );
144 public function upgrade_3_3_beta1($rev) {
145 $upgrade = new CRM_Upgrade_Form();
146 $upgrade->processSQL($rev);
149 // Add column price_field_value_id in civicrm_line_item.
150 // Do not drop option_group_id column now since we need it to
151 // update line items.
152 $updateLineItem1 = "ALTER TABLE civicrm_line_item ADD COLUMN price_field_value_id int(10) unsigned default NULL;";
153 CRM_Core_DAO
::executeQuery($updateLineItem1);
155 $priceFieldDAO = new CRM_Price_DAO_PriceField();
156 $priceFieldDAO->find();
158 while ($priceFieldDAO->fetch()) {
160 $opGroupDAO = new CRM_Core_DAO_OptionGroup();
161 $opGroupDAO->name
= 'civicrm_price_field.amount.' . $priceFieldDAO->id
;
163 if (!$opGroupDAO->find(TRUE)) {
168 $opValueDAO = new CRM_Core_DAO_OptionValue();
169 $opValueDAO->option_group_id
= $opGroupDAO->id
;
172 while ($opValueDAO->fetch()) {
173 // FIX ME: not migrating description(?), there will
174 // be a field description for each option.
176 'price_field_id' => $priceFieldDAO->id
,
177 'label' => $opValueDAO->label
,
178 'name' => CRM_Utils_String
::munge($opValueDAO->label
, '_', 64),
179 'amount' => $opValueDAO->name
,
180 'weight' => $opValueDAO->weight
,
181 'is_default' => $opValueDAO->is_default
,
182 'is_active' => $opValueDAO->is_active
,
185 if ($priceFieldDAO->count
) {
186 // Migrate Participant Counts on option level.
187 // count of each option will be the same
188 // as earlier field count.
189 $fieldValue['count'] = $priceFieldDAO->count
;
192 $fieldValueDAO = CRM_Price_BAO_PriceFieldValue
::add($fieldValue, $ids);
194 $lineItemDAO = new CRM_Price_DAO_LineItem();
195 $lineItemDAO->option_group_id
= $opGroupDAO->id
;
196 $lineItemDAO->label
= $opValueDAO->label
;
197 $lineItemDAO->unit_price
= $opValueDAO->name
;
199 $labelFound = $priceFound = FALSE;
201 // check with label and amount
202 if (!$lineItemDAO->find(TRUE)) {
203 $lineItemDAO->free();
204 $lineItemDAO = new CRM_Price_DAO_LineItem();
205 $lineItemDAO->option_group_id
= $opGroupDAO->id
;
206 $lineItemDAO->label
= $opValueDAO->label
;
208 // check with label only
209 if ($lineItemDAO->find(TRUE)) {
218 $lineItemDAO->free();
220 // update civicrm_line_item for price_field_value_id.
221 // Used query to avoid line by line update.
222 if ($labelFound ||
$priceFound) {
223 $lineItemParams = array(
224 1 => array($fieldValueDAO->id
, 'Integer'),
225 2 => array($opValueDAO->label
, 'String'),
227 $updateLineItems = "UPDATE civicrm_line_item SET price_field_value_id = %1 WHERE label = %2";
229 $lineItemParams[3] = array($opValueDAO->name
, 'Float');
230 $updateLineItems .= " AND unit_price = %3";
232 CRM_Core_DAO
::executeQuery($updateLineItems, $lineItemParams);
236 $opGroupDAO->delete();
241 $priceFieldDAO->free();
243 // Now drop option_group_id column from civicrm_line_item
244 $updateLineItem2 = "ALTER TABLE civicrm_line_item DROP option_group_id,
245 ADD CONSTRAINT `FK_civicrm_price_field_value_id` FOREIGN KEY (price_field_value_id) REFERENCES civicrm_price_field_value(id) ON DELETE SET NULL;";
246 CRM_Core_DAO
::executeQuery($updateLineItem2, array(), TRUE, NULL, FALSE, FALSE);
248 $updatePriceField = "ALTER TABLE civicrm_price_field DROP count";
249 CRM_Core_DAO
::executeQuery($updatePriceField, array(), TRUE, NULL, FALSE, FALSE);
251 // as the table 'civicrm_price_field' is localised and column 'count' is dropped
252 // after the views are rebuild, we need to rebuild views to avoid invalid refrence of table.
253 if ($upgrade->multilingual
) {
254 CRM_Core_I18n_Schema
::rebuildMultilingualSchema($upgrade->locales
, $rev);
261 public function upgrade_3_3_beta3($rev) {
262 // get the duplicate Ids of line item entries
263 $dupeLineItemIds = array();
264 $fields = array('entity_table', 'entity_id', 'price_field_id', 'price_field_value_id');
265 $mainLineItem = new CRM_Price_BAO_LineItem();
266 $mainLineItem->find(TRUE);
267 while ($mainLineItem->fetch()) {
268 $dupeLineItem = new CRM_Price_BAO_LineItem();
269 foreach ($fields as $fld) { $dupeLineItem->$fld = $mainLineItem->$fld;
271 $dupeLineItem->find(TRUE);
272 $dupeLineItem->addWhere("id != $mainLineItem->id");
273 while ($dupeLineItem->fetch()) {
274 $dupeLineItemIds[$dupeLineItem->id
] = $dupeLineItem->id
;
276 $dupeLineItem->free();
278 $mainLineItem->free();
280 //clean line item table.
281 if (!empty($dupeLineItemIds)) {
282 $sql = 'DELETE FROM civicrm_line_item WHERE id IN ( ' . implode(', ', $dupeLineItemIds) . ' )';
283 CRM_Core_DAO
::executeQuery($sql);
286 $upgrade = new CRM_Upgrade_Form();
287 $upgrade->processSQL($rev);
293 public function upgrade_3_3_0($rev) {
294 $upgrade = new CRM_Upgrade_Form();
295 $upgrade->processSQL($rev);
297 //CRM-7123 -lets activate needful languages.
298 $config = CRM_Core_Config
::singleton();
300 if (is_dir($config->gettextResourceDir
) && $dir = opendir($config->gettextResourceDir
)) {
301 while ($filename = readdir($dir)) {
302 if (preg_match('/^[a-z][a-z]_[A-Z][A-Z]$/', $filename)) {
303 $locales[$filename] = $filename;
309 if (isset($config->languageLimit
) && !empty($config->languageLimit
)) {
310 //get all already enabled and all l10n languages.
311 $locales = array_merge(array_values($locales), array_keys($config->languageLimit
));
314 if (!empty($locales)) {
316 UPDATE civicrm_option_value val
317 INNER JOIN civicrm_option_group grp ON ( grp.id = val.option_group_id )
318 SET val.is_active = 1
320 AND val.name IN ( ' . "'" . implode("', '", $locales) . "' )";
322 CRM_Core_DAO
::executeQuery($sql,
323 array(1 => array('languages', 'String')),
324 TRUE, NULL, FALSE, FALSE
332 public function upgrade_3_3_2($rev) {
333 $dropMailingIndex = FALSE;
334 $indexes = CRM_Core_DAO
::executeQuery('SHOW INDEXES FROM civicrm_mailing_job');
335 while ($indexes->fetch()) {
336 if ($indexes->Key_name
== 'parent_id') {
337 $dropMailingIndex = TRUE;
342 // get membership type for each membership block.
343 $sql = "SELECT id, membership_types FROM civicrm_membership_block ";
344 $dao = CRM_Core_DAO
::executeQuery($sql);
345 while ($dao->fetch()) {
346 $memType = explode(',', $dao->membership_types
);
348 $memTypeSerialize = array();
349 foreach ($memType as $k => $v) {
350 $memTypeSerialize[$v] = 0;
353 // save membership type as an serialized array along w/ auto_renew defalt value zero.
354 $memBlock = new CRM_Member_DAO_MembershipBlock();
355 $memBlock->id
= $dao->id
;
356 $memBlock->membership_types
= serialize($memTypeSerialize);
361 if (CRM_Mailing_Info
::workflowEnabled()) {
362 $config = CRM_Core_Config
::singleton();
363 if (is_callable(array(
364 $config->userSystem
, 'replacePermission'))) {
365 $config->userSystem
->replacePermission('access CiviMail', array('access CiviMail', 'create mailings', 'approve mailings', 'schedule mailings'));
369 $upgrade = new CRM_Upgrade_Form();
370 $upgrade->assign('dropMailingIndex', $dropMailingIndex);
371 $upgrade->processSQL($rev);
377 public function upgrade_3_3_7($rev) {
378 $dao = new CRM_Contact_DAO_Contact();
379 $dbName = $dao->_database
;
381 $chkExtQuery = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %1
382 AND TABLE_NAME = 'civicrm_phone' AND COLUMN_NAME = 'phone_ext'";
383 $extensionExists = CRM_Core_DAO
::singleValueQuery($chkExtQuery,
384 array(1 => array($dbName, 'String')),
388 if (!$extensionExists) {
389 $colQuery = 'ALTER TABLE `civicrm_phone` ADD `phone_ext` VARCHAR( 16 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL AFTER `phone` ';
390 CRM_Core_DAO
::executeQuery($colQuery);
393 // handle db changes done for CRM-8218
394 $alterContactDashboard = FALSE;
395 $dao = new CRM_Contact_DAO_DashboardContact();
396 $dbName = $dao->_database
;
398 $chkContentQuery = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %1
399 AND TABLE_NAME = 'civicrm_dashboard_contact' AND COLUMN_NAME = 'content'";
400 $contentExists = CRM_Core_DAO
::singleValueQuery($chkContentQuery,
401 array(1 => array($dbName, 'String')),
404 if (!$contentExists) {
405 $alterContactDashboard = TRUE;
408 $upgrade = new CRM_Upgrade_Form();
409 $upgrade->assign('alterContactDashboard', $alterContactDashboard);
410 $upgrade->processSQL($rev);