Fix 'sleeper-bug' in api.
authoreileen <emcnaughton@wikimedia.org>
Wed, 23 Sep 2020 02:22:07 +0000 (14:22 +1200)
committereileen <emcnaughton@wikimedia.org>
Fri, 25 Sep 2020 08:17:28 +0000 (20:17 +1200)
commit2bd8b0289cfcf6934601b88ba179b23cacf82ade
tree44c4fa41255a4c4d5a2dc76dc3b379d629045f41
parent97ff3c552fa4d6125ccbfdfd05dfae0d2e498d3d
Fix 'sleeper-bug' in api.

It turns out that the Activity.create BAO
- deletes the existing source contact for an activity if the param 'source_contact_id' is set
- deletes existing assignee contacts for an activity if the param 'assignee_contact_id' is empty
- deletes existing target contacts for an activity if the param 'target_contact_id' is empty

The v3 api provides some fairly convoluted wrapping to effectively convert is empty
to isset (via 2 params deleteActivityAssignment, deleteActivityTarget which would only
be anything other than true if the relevant value key is not set or we are operating from
the one place in universe that passes in this param (well actually it's true then too
https://github.com/eileenmcnaughton/civicrm_entity/commit/bd779c19bbf82ca22260615b4f7667d02eee1200
)

The v4 api does no handling and we can expect that on update activity contact records are
likely being lost - ditto with direct BAO calls that were probably QAd at some point but
may have changed over time.

This changes the BAO to treat the assignee & target params the same way as source
- ie do nothing if not set, but empty means to delete them

Remove support for api param deleteActivityAssignment, deleteActivityTarget

I did a universe search & it was only called from one place which
I fixed
https://github.com/eileenmcnaughton/civicrm_entity/commit/bd779c19bbf82ca22260615b4f7667d02eee1200

- it's never been a tested param so technically not supported

This is part of my effort to fix redundant queries in Activity.create regarding
activity contacts
CRM/Activity/BAO/Activity.php
Civi/Test/ContactTestTrait.php
api/v3/Activity.php
tests/phpunit/api/v3/ActivityTest.php