Skip to content
Snippets Groups Projects
Commit 83145e83 authored by lobo's avatar lobo
Browse files

Merge pull request #2294 from pratik-joshi/CRM-14036_fix

CRM-14036_fix
parents 5df36739 23e300df
No related branches found
No related tags found
No related merge requests found
......@@ -215,6 +215,38 @@ VALUES {$insertStatus}";
}
function upgrade_4_4_4($rev) {
$fkConstraint = array();
if (!CRM_Core_DAO::checkFKConstraintInFormat('civicrm_activity_contact', 'activity_id')) {
$fkConstraint[] = "ADD CONSTRAINT `FK_civicrm_activity_contact_activity_id` FOREIGN KEY (`activity_id`) REFERENCES `civicrm_activity` (`id`) ON DELETE CASCADE";
}
if (!CRM_Core_DAO::checkFKConstraintInFormat('civicrm_activity_contact', 'contact_id')) {
$fkConstraint[] = "ADD CONSTRAINT `FK_civicrm_activity_contact_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE;
";
}
if (!empty($fkConstraint)) {
$fkConstraint = implode(',', $fkConstraint);
$sql = "ALTER TABLE `civicrm_activity_contact`
{$fkConstraint}
";
// CRM-14036 : delete entries of un-mapped contacts
CRM_Core_DAO::executeQuery("DELETE ac FROM civicrm_activity_contact ac
LEFT JOIN civicrm_contact c
ON c.id = ac.contact_id
WHERE c.id IS NULL;
");
// delete entries of un-mapped activities
CRM_Core_DAO::executeQuery("DELETE ac FROM civicrm_activity_contact ac
LEFT JOIN civicrm_activity a
ON a.id = ac.activity_id
WHERE a.id IS NULL;
");
CRM_Core_DAO::executeQuery("SET FOREIGN_KEY_CHECKS=0;");
CRM_Core_DAO::executeQuery($sql);
CRM_Core_DAO::executeQuery("SET FOREIGN_KEY_CHECKS=1;");
}
// task to process sql
$this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.4.4')), 'task_4_4_x_runSql', $rev);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment