From: Coleman Watts Date: Thu, 2 May 2013 19:53:03 +0000 (-0700) Subject: Fix is_primary handling X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=50fa40e8f5720193eab38e8e79842e858a266073;p=civicrm-core.git Fix is_primary handling --- diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index cfd2fb10ca..40e746088d 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -3000,19 +3000,22 @@ LEFT JOIN civicrm_address add2 ON ( add1.master_id = add2.id ) else { return FALSE; } - $dao = new $daoName(); - $dao->contact_id = $contactId; - $dao->is_primary = 1; - // Pick another record to be primary (if one isn't already) - if (!$dao->find(TRUE)) { - $dao->is_primary = 0; - $dao->find(); - if ($dao->fetch()) { - $dao->is_primary = 1; - $dao->save(); - } + // is_primary is only relavent if this field belongs to a contact + if ($contactId) { + $dao = new $daoName(); + $dao->contact_id = $contactId; + $dao->is_primary = 1; + // Pick another record to be primary (if one isn't already) + if (!$dao->find(TRUE)) { + $dao->is_primary = 0; + $dao->find(); + if ($dao->fetch()) { + $dao->is_primary = 1; + $dao->save(); + } + } + $dao->free(); } - $dao->free(); CRM_Utils_Hook::post('delete', $type, $id, $obj); $obj->free(); return TRUE; diff --git a/CRM/Core/BAO/Block.php b/CRM/Core/BAO/Block.php index 92ff98a561..f901457a3b 100644 --- a/CRM/Core/BAO/Block.php +++ b/CRM/Core/BAO/Block.php @@ -435,19 +435,17 @@ class CRM_Core_BAO_Block { $table = 'civicrm_address'; break; } - // if id is set & we don't have contact_id we need to retrieve it - $contactId = null; - if (!empty($params['id']) && empty($params['contact_id'])) { + // contact_id in params might be empty or the string 'null' so cast to integer + $contactId = (int) CRM_Utils_Array::value('contact_id', $params); + // If id is set & we haven't been passed a contact_id, retrieve it + if (!empty($params['id']) && !isset($params['contact_id'])) { $entity = new $class(); $entity->id = $params['id']; $entity->find(TRUE); $contactId = $entity->contact_id; } - elseif (CRM_Utils_Array::value('contact_id', $params)) { - $contactId = $params['contact_id']; - } - if ( !$contactId ) { - // entity not associated with contact so concept of is_primary not relevant + // If entity is not associated with contact, concept of is_primary not relevant + if (!$contactId) { return; }