4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.5 |
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 function verifyPreDBstate(&$errors) {
48 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,
70 array(1 => array($name, 'String'),
71 2 => array($customField->id
, 'Integer'),
75 $name = CRM_Utils_String
::munge("{$name}_" . rand(), '_', 64);
78 Update `civicrm_custom_field`
82 $customFieldParams = array(1 => array($name, 'String'),
83 2 => array($customField->id
, 'Integer'),
85 CRM_Core_DAO
::executeQuery($customFieldQuery, $customFieldParams, TRUE, NULL, FALSE, FALSE);
89 $customGrpCntQuery = 'select count(*) from civicrm_custom_group where name like %1 and id != %2';
90 $customGroup = new CRM_Core_DAO_CustomGroup();
91 $customGroup->selectAdd();
92 $customGroup->selectAdd('id, title');
94 while ($customGroup->fetch()) {
95 $name = CRM_Utils_String
::munge($customGroup->title
, '_', 64);
96 $grpCnt = CRM_Core_DAO
::singleValueQuery($customGrpCntQuery,
97 array(1 => array($name, 'String'),
98 2 => array($customGroup->id
, 'Integer'),
102 $name = CRM_Utils_String
::munge("{$name}_" . rand(), '_', 64);
104 CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_CustomGroup', $customGroup->id
, 'name', $name);
106 $customGroup->free();
108 $ufGrpCntQuery = 'select count(*) from civicrm_uf_group where name like %1 and id != %2';
109 $ufGroup = new CRM_Core_DAO_UFGroup();
110 $ufGroup->selectAdd();
111 $ufGroup->selectAdd('id, title');
113 while ($ufGroup->fetch()) {
114 $name = CRM_Utils_String
::munge($ufGroup->title
, '_', 64);
115 $ufGrpCnt = CRM_Core_DAO
::singleValueQuery($ufGrpCntQuery,
116 array(1 => array($name, 'String'),
117 2 => array($ufGroup->id
, 'Integer'),
121 $name = CRM_Utils_String
::munge("{$name}_" . rand(), '_', 64);
123 CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_UFGroup', $ufGroup->id
, 'name', $name);
127 $upgrade = new CRM_Upgrade_Form();
128 $upgrade->processSQL($rev);
130 // now modify the config so that the directories are stored in option group/value
132 // require_once 'CRM/Core/BAO/ConfigSetting.php';
133 // $params = array( );
134 // CRM_Core_BAO_ConfigSetting::add( $parambs );
140 function upgrade_3_3_beta1($rev) {
141 $upgrade = new CRM_Upgrade_Form();
142 $upgrade->processSQL($rev);
145 // Add column price_field_value_id in civicrm_line_item.
146 // Do not drop option_group_id column now since we need it to
147 // update line items.
148 $updateLineItem1 = "ALTER TABLE civicrm_line_item ADD COLUMN price_field_value_id int(10) unsigned default NULL;";
149 CRM_Core_DAO
::executeQuery($updateLineItem1);
152 $priceFieldDAO = new CRM_Price_DAO_PriceField();
153 $priceFieldDAO->find();
155 while ($priceFieldDAO->fetch()) {
157 $opGroupDAO = new CRM_Core_DAO_OptionGroup();
158 $opGroupDAO->name
= 'civicrm_price_field.amount.' . $priceFieldDAO->id
;
160 if (!$opGroupDAO->find(TRUE)) {
165 $opValueDAO = new CRM_Core_DAO_OptionValue();
166 $opValueDAO->option_group_id
= $opGroupDAO->id
;
169 while ($opValueDAO->fetch()) {
170 // FIX ME: not migrating description(?), there will
171 // be a field description for each option.
173 'price_field_id' => $priceFieldDAO->id
,
174 'label' => $opValueDAO->label
,
175 'name' => CRM_Utils_String
::munge($opValueDAO->label
, '_', 64),
176 'amount' => $opValueDAO->name
,
177 'weight' => $opValueDAO->weight
,
178 'is_default' => $opValueDAO->is_default
,
179 'is_active' => $opValueDAO->is_active
,
182 if ($priceFieldDAO->count
) {
183 // Migrate Participant Counts on option level.
184 // count of each option will be the same
185 // as earlier field count.
186 $fieldValue['count'] = $priceFieldDAO->count
;
189 $fieldValueDAO = CRM_Price_BAO_PriceFieldValue
::add($fieldValue, $ids);
191 $lineItemDAO = new CRM_Price_DAO_LineItem();
192 $lineItemDAO->option_group_id
= $opGroupDAO->id
;
193 $lineItemDAO->label
= $opValueDAO->label
;
194 $lineItemDAO->unit_price
= $opValueDAO->name
;
196 $labelFound = $priceFound = FALSE;
198 // check with label and amount
199 if (!$lineItemDAO->find(TRUE)) {
200 $lineItemDAO->free();
201 $lineItemDAO = new CRM_Price_DAO_LineItem();
202 $lineItemDAO->option_group_id
= $opGroupDAO->id
;
203 $lineItemDAO->label
= $opValueDAO->label
;
205 // check with label only
206 if ($lineItemDAO->find(TRUE)) {
215 $lineItemDAO->free();
217 // update civicrm_line_item for price_field_value_id.
218 // Used query to avoid line by line update.
219 if ($labelFound ||
$priceFound) {
220 $lineItemParams = array(1 => array($fieldValueDAO->id
, 'Integer'),
221 2 => array($opValueDAO->label
, 'String'),
223 $updateLineItems = "UPDATE civicrm_line_item SET price_field_value_id = %1 WHERE label = %2";
225 $lineItemParams[3] = array($opValueDAO->name
, 'Float');
226 $updateLineItems .= " AND unit_price = %3";
228 CRM_Core_DAO
::executeQuery($updateLineItems, $lineItemParams);
232 $opGroupDAO->delete();
237 $priceFieldDAO->free();
239 // Now drop option_group_id column from civicrm_line_item
240 $updateLineItem2 = "ALTER TABLE civicrm_line_item DROP option_group_id,
241 ADD CONSTRAINT `FK_civicrm_price_field_value_id` FOREIGN KEY (price_field_value_id) REFERENCES civicrm_price_field_value(id) ON DELETE SET NULL;";
242 CRM_Core_DAO
::executeQuery($updateLineItem2, array(), TRUE, NULL, FALSE, FALSE);
244 $updatePriceField = "ALTER TABLE civicrm_price_field DROP count";
245 CRM_Core_DAO
::executeQuery($updatePriceField, array(), TRUE, NULL, FALSE, FALSE);
247 // as the table 'civicrm_price_field' is localised and column 'count' is dropped
248 // after the views are rebuild, we need to rebuild views to avoid invalid refrence of table.
249 if ($upgrade->multilingual
) {
250 CRM_Core_I18n_Schema
::rebuildMultilingualSchema($upgrade->locales
, $rev);
257 function upgrade_3_3_beta3($rev) {
258 // get the duplicate Ids of line item entries
259 $dupeLineItemIds = array();
260 $fields = array('entity_table', 'entity_id', 'price_field_id', 'price_field_value_id');
261 $mainLineItem = new CRM_Price_BAO_LineItem();
262 $mainLineItem->find(TRUE);
263 while ($mainLineItem->fetch()) {
264 $dupeLineItem = new CRM_Price_BAO_LineItem();
265 foreach ($fields as $fld) $dupeLineItem->$fld = $mainLineItem->$fld;
266 $dupeLineItem->find(TRUE);
267 $dupeLineItem->addWhere("id != $mainLineItem->id");
268 while ($dupeLineItem->fetch()) {
269 $dupeLineItemIds[$dupeLineItem->id
] = $dupeLineItem->id
;
271 $dupeLineItem->free();
273 $mainLineItem->free();
275 //clean line item table.
276 if (!empty($dupeLineItemIds)) {
277 $sql = 'DELETE FROM civicrm_line_item WHERE id IN ( ' . implode(', ', $dupeLineItemIds) . ' )';
278 CRM_Core_DAO
::executeQuery($sql);
281 $upgrade = new CRM_Upgrade_Form();
282 $upgrade->processSQL($rev);
288 function upgrade_3_3_0($rev) {
289 $upgrade = new CRM_Upgrade_Form();
290 $upgrade->processSQL($rev);
292 //CRM-7123 -lets activate needful languages.
293 $config = CRM_Core_Config
::singleton();
295 if (is_dir($config->gettextResourceDir
)) {
296 $dir = opendir($config->gettextResourceDir
);
297 while ($filename = readdir($dir)) {
298 if (preg_match('/^[a-z][a-z]_[A-Z][A-Z]$/', $filename)) {
299 $locales[$filename] = $filename;
305 if (isset($config->languageLimit
) && !empty($config->languageLimit
)) {
306 //get all already enabled and all l10n languages.
307 $locales = array_merge(array_values($locales), array_keys($config->languageLimit
));
310 if (!empty($locales)) {
312 UPDATE civicrm_option_value val
313 INNER JOIN civicrm_option_group grp ON ( grp.id = val.option_group_id )
314 SET val.is_active = 1
316 AND val.name IN ( ' . "'" . implode("', '", $locales) . "' )";
318 CRM_Core_DAO
::executeQuery($sql,
319 array(1 => array('languages', 'String')),
320 TRUE, NULL, FALSE, FALSE
328 function upgrade_3_3_2($rev) {
329 $dropMailingIndex = FALSE;
330 $indexes = CRM_Core_DAO
::executeQuery('SHOW INDEXES FROM civicrm_mailing_job');
331 while ($indexes->fetch()) {
332 if ($indexes->Key_name
== 'parent_id') {
333 $dropMailingIndex = TRUE;
338 // get membership type for each membership block.
339 $sql = "SELECT id, membership_types FROM civicrm_membership_block ";
340 $dao = CRM_Core_DAO
::executeQuery($sql);
341 while ($dao->fetch()) {
342 $memType = explode(',', $dao->membership_types
);
344 $memTypeSerialize = array();
345 foreach ($memType as $k => $v) {
346 $memTypeSerialize[$v] = 0;
349 // save membership type as an serialized array along w/ auto_renew defalt value zero.
350 $memBlock = new CRM_Member_DAO_MembershipBlock();
351 $memBlock->id
= $dao->id
;
352 $memBlock->membership_types
= serialize($memTypeSerialize);
357 if (CRM_Mailing_Info
::workflowEnabled()) {
358 $config = CRM_Core_Config
::singleton();
359 if (is_callable(array(
360 $config->userSystem
, 'replacePermission'))) {
361 $config->userSystem
->replacePermission('access CiviMail', array('access CiviMail', 'create mailings', 'approve mailings', 'schedule mailings'));
365 $upgrade = new CRM_Upgrade_Form();
366 $upgrade->assign('dropMailingIndex', $dropMailingIndex);
367 $upgrade->processSQL($rev);
373 function upgrade_3_3_7($rev) {
374 $dao = new CRM_Contact_DAO_Contact();
375 $dbName = $dao->_database
;
377 $chkExtQuery = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %1
378 AND TABLE_NAME = 'civicrm_phone' AND COLUMN_NAME = 'phone_ext'";
379 $extensionExists = CRM_Core_DAO
::singleValueQuery($chkExtQuery,
380 array(1 => array($dbName, 'String')),
384 if (!$extensionExists) {
385 $colQuery = 'ALTER TABLE `civicrm_phone` ADD `phone_ext` VARCHAR( 16 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL AFTER `phone` ';
386 CRM_Core_DAO
::executeQuery($colQuery);
389 // handle db changes done for CRM-8218
390 $alterContactDashboard = FALSE;
391 $dao = new CRM_Contact_DAO_DashboardContact();
392 $dbName = $dao->_database
;
394 $chkContentQuery = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %1
395 AND TABLE_NAME = 'civicrm_dashboard_contact' AND COLUMN_NAME = 'content'";
396 $contentExists = CRM_Core_DAO
::singleValueQuery($chkContentQuery,
397 array(1 => array($dbName, 'String')),
400 if (!$contentExists) {
401 $alterContactDashboard = TRUE;
404 $upgrade = new CRM_Upgrade_Form();
405 $upgrade->assign('alterContactDashboard', $alterContactDashboard);
406 $upgrade->processSQL($rev);