Details
-
Type: Bug
-
Status: Done/Fixed
-
Priority: Major
-
Resolution: Fixed/Completed
-
Affects Version/s: 3.2.3
-
Fix Version/s: 3.3.beta
-
Component/s: CiviCRM API
-
Labels:None
Description
I just ran across this phenomenon twice in the same day with two different APIs. I hope this isn't the tip of the iceberg...
$params = array( 'id' => 123 //update mode
'contact_id_a' => 100,
'contact_id_b' => 101,
'relationship_type_id' => 4,
);
civicrm_relationship_create( $params ); //this will destroy all existing relationship data, start date, end date, is_active, etc
When updating a record, one expects to add new information or update existing information, but not delete existing info without explicitly doing so. Instead, this API call is removing all data that isn't passed in the params. So anyone trying to update a single relationship attribute (start date, for example) will inadvertently destroying all existing attributes (for example, is_active will be set to false unless it is passed in params as true). Not good!
One more thing while we're on the subject of relationship_api. When you attempt to create a new relationship that already exists, the error message you get simply says "Relationship already exist" Poor grammar aside, this isn't very helpful if you would like to go on to update that existing relationship with your new data. Where's the id?
Unfortunately, that's not the only case of inadvertent data loss. I just discovered that civicrm_activity_update will delete the target_contact_id if it is not passed as a param. Other data may be getting deleted as well, but this is the extent of my testing so far.