if ($rev == '4.5.beta2') {
$postUpgradeMessage .= '<br /><br />' . ts('If you use CiviMail for newsletters or other communications, check out the new sample CiviMail templates which use responsive design to optimize display on mobile devices (Administer > Communications > Message Templates ).');
}
+ if ($rev == '4.5.1') {
+ $postUpgradeMessage .= '<br /><br />' . ts('WARNING: If you use CiviCase, it is possible that previous upgrades corrupted some CiviCase metadata. If you have not already done so, please identify any custom field sets, smart groups, or reports which refer to CiviCase and ensure that they are properly configured.');
+ }
}
/**
*/
function upgrade_4_5_beta9($rev) {
$this->addTask(ts('Upgrade DB to 4.5.beta9: SQL'), 'task_4_5_x_runSql', $rev);
-
+
$entityTable = array(
'Participant' => 'civicrm_participant_payment',
'Contribution' => 'civicrm_contribution',
'Membership' => 'civicrm_membership',
);
-
+
foreach ($entityTable as $label => $tableName) {
list($minId, $maxId) = CRM_Core_DAO::executeQuery("SELECT coalesce(min(id),0), coalesce(max(id),0)
FROM {$tableName}")->getDatabaseResult()->fetchRow();
$endId = $startId + self::BATCH_SIZE - 1;
$title = ts("Upgrade DB to 4.5.beta9: Fix line items for {$label} (%1 => %2)", array(1 => $startId, 2 => $endId));
$this->addTask($title, 'task_4_5_0_fixLineItem', $startId, $endId, $label);
- }
- }
+ }
+ }
return TRUE;
}
* (Queue Task Callback)
*
* Function to update the line items
- *
+ *
*
* @param CRM_Queue_TaskContext $ctx
* @param $startId int, the first/lowest entity ID to convert
* @param $endId int, the last/highest entity ID to convert
- * @param
+ * @param
*
* @return bool
*/
static function task_4_5_0_fixLineItem(CRM_Queue_TaskContext $ctx, $startId, $endId, $entityTable) {
-
+
$sqlParams = array(
1 => array($startId, 'Integer'),
2 => array($endId, 'Integer'),
);
switch ($entityTable) {
- case 'Contribution':
+ case 'Contribution':
// update all the line item entity_table and entity_id with contribution due to bug CRM-15055
CRM_Core_DAO::executeQuery("UPDATE civicrm_line_item li
INNER JOIN civicrm_contribution cc ON cc.id = li.contribution_id
SET entity_id = li.contribution_id, entity_table = 'civicrm_contribution'
WHERE li.contribution_id IS NOT NULL AND li.entity_table <> 'civicrm_participant' AND (cc.id BETWEEN %1 AND %2)", $sqlParams);
-
+
// update the civicrm_line_item.contribution_id
CRM_Core_DAO::executeQuery("UPDATE civicrm_line_item li
- INNER JOIN civicrm_contribution cc ON cc.id = li.entity_id
+ INNER JOIN civicrm_contribution cc ON cc.id = li.entity_id
SET contribution_id = entity_id
- WHERE li.contribution_id IS NULL AND li.entity_table = 'civicrm_contribution' AND (cc.id BETWEEN %1 AND %2)", $sqlParams);
+ WHERE li.contribution_id IS NULL AND li.entity_table = 'civicrm_contribution' AND (cc.id BETWEEN %1 AND %2)", $sqlParams);
break;
-
+
case 'Participant':
// update the civicrm_line_item.contribution_id
- CRM_Core_DAO::executeQuery("UPDATE civicrm_line_item li
+ CRM_Core_DAO::executeQuery("UPDATE civicrm_line_item li
INNER JOIN civicrm_participant_payment pp ON pp.participant_id = li.entity_id
SET li.contribution_id = pp.contribution_id
WHERE li.entity_table = 'civicrm_participant' AND li.contribution_id IS NULL AND (pp.id BETWEEN %1 AND %2)", $sqlParams);
break;
-
+
case 'Membership':
$upgrade = new CRM_Upgrade_Form();
// update the line item of membership
SET li.entity_table = 'civicrm_membership', li.entity_id = mp.membership_id
WHERE li.entity_table = 'civicrm_contribution'
AND pv.membership_type_id IS NOT NULL AND cm.membership_type_id = pv.membership_type_id AND (cm.id BETWEEN %1 AND %2)", $sqlParams);
-
+
CRM_Core_DAO::executeQuery("UPDATE civicrm_line_item li
INNER JOIN civicrm_membership_payment mp ON mp.contribution_id = li.contribution_id
INNER JOIN civicrm_price_field_value pv ON pv.id = li.price_field_value_id
SET li.entity_table = 'civicrm_membership', li.entity_id = mp.membership_id
WHERE li.entity_table = 'civicrm_contribution'
AND pv.membership_type_id IS NOT NULL AND (mp.membership_id BETWEEN %1 AND %2)", $sqlParams);
-
+
CRM_Core_DAO::executeQuery("INSERT INTO civicrm_line_item (entity_table, entity_id, price_field_id, label,
qty, unit_price, line_total, price_field_value_id, financial_type_id)
- SELECT 'civicrm_membership', cm.id, cpf.id price_field_id, cpfv.label, 1 as qty, cpfv.amount, cpfv.amount line_total,
+ SELECT 'civicrm_membership', cm.id, cpf.id price_field_id, cpfv.label, 1 as qty, cpfv.amount, cpfv.amount line_total,
cpfv.id price_field_value_id, cpfv.financial_type_id FROM civicrm_membership cm
LEFT JOIN civicrm_membership_payment cmp ON cmp.membership_id = cm.id
INNER JOIN civicrm_price_field_value cpfv ON cpfv.membership_type_id = cm.membership_type_id
INNER JOIN civicrm_price_set cps ON cps.id = cpf.price_set_id
WHERE cmp.contribution_id IS NULL AND cps.name = 'default_membership_type_amount' AND (cm.id BETWEEN %1 AND %2)", $sqlParams);
break;
- }
+ }
return TRUE;
}
SELECT @option_group_id_case_type := max(id) from civicrm_option_group where name = 'case_type';
INSERT IGNORE INTO civicrm_case_type
- (name, {localize field='title'}title{/localize}, {localize field='description'}description{/localize}, is_active, is_reserved, weight)
+ (id, name, {localize field='title'}title{/localize}, {localize field='description'}description{/localize}, is_active, is_reserved, weight)
SELECT
+ value,
name,
{localize field='label'}label{/localize},
{localize field='description'}description{/localize},
WHERE
option_group_id = @option_group_id_case_type;
--- Replace the pseudo-fk to ov.value with a reference to civicrm_case_type.id
-UPDATE civicrm_case
- SET case_type_id = (
- SELECT civicrm_case_type.id FROM civicrm_case_type
- JOIN civicrm_option_value
- ON civicrm_option_value.name = civicrm_case_type.name
- WHERE
- civicrm_option_value.option_group_id = @option_group_id_case_type
- AND civicrm_option_value.value = replace(civicrm_case.case_type_id, 0x01, '')
- );
+--- Remove the special character, earlier used as a separator and reference to civicrm_case_type.id
+UPDATE civicrm_case SET case_type_id = replace(case_type_id, 0x01, '');
ALTER TABLE civicrm_case
MODIFY case_type_id int(10) unsigned COLLATE utf8_unicode_ci NULL COMMENT 'FK to civicrm_case_type.id',
ADD CONSTRAINT FK_civicrm_case_case_type_id FOREIGN KEY (case_type_id) REFERENCES civicrm_case_type (id) ON DELETE SET NULL;
+-- CRM-15343 set the auto increment civicrm_case_type.id start point to max id to avoid conflict in future insertion
+SELECT @max_case_type_id := max(id) from civicrm_case_type;
+SET @query = CONCAT("ALTER TABLE civicrm_case_type AUTO_INCREMENT = ", @max_case_type_id);
+PREPARE stmt FROM @query;
+EXECUTE stmt;
+DEALLOCATE PREPARE stmt;
+
DELETE FROM civicrm_option_value WHERE option_group_id = @option_group_id_case_type;
DELETE FROM civicrm_option_group WHERE id = @option_group_id_case_type;