Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-20097 - Tweaks and fixes #10288

Merged
merged 4 commits into from
May 23, 2017
Merged

CRM-20097 - Tweaks and fixes #10288

merged 4 commits into from
May 23, 2017

Conversation

colemanw
Copy link
Member

@colemanw colemanw commented May 1, 2017

@colemanw colemanw requested a review from totten May 2, 2017 17:19
totten added a commit to colemanw/civicrm-core that referenced this pull request May 2, 2017
PR civicrm#10288 fixes an edge-case in plugging in a chained-value.  The scenario
originated in `org.civicrm.civicase` Angular UI.  I just copied/trimmed it
to reproduce the bug.
@@ -136,6 +136,10 @@ function _civicrm_api_replace_variables(&$params, &$parentResult, $separator = '
elseif (is_array($value) && is_string(reset($value)) && substr(reset($value), 0, 6) == '$value') {
$key = key($value);
$value[$key] = _civicrm_api_replace_variable($value[$key], $parentResult, $separator);
// A null value with an operator will cause an error, so remove it.
if ($value[$key] === NULL) {
$value = '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this merits a test-case. I copied the API call used by org.civicrm.civicase, trimmed it down a bit, and put that in a new test (on your branch).

@@ -471,7 +471,7 @@ function _civicrm_api3_activity_get_formatResult($params, $activities, $options)
$dao = CRM_Core_DAO::executeQuery("SELECT activity_id, case_id FROM civicrm_case_activity WHERE activity_id IN (%1)",
array(1 => array(implode(',', array_keys($activities)), 'String', CRM_Core_DAO::QUERY_FORMAT_NO_QUOTES)));
while ($dao->fetch()) {
$activities[$dao->activity_id]['case_id'] = $dao->case_id;
$activities[$dao->activity_id]['case_id'][] = $dao->case_id;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so repeating aloud to check my comprehension:

  • Activities are normally associated with zero or one cases, but in the scenario of linked-cases, you can have an activity which lives in multiple cases.
  • The old/existing API contract returns an int or null, which is fine for the normal scenario. The new/proposed API contract returns an array of ints, which is more generally correct.
  • Problem: Changing the data-structure of case_id will break any API consumers who use it.
  • Suggestion: The Activity API should support two different return notations, case_id (singular, legacy behavior) or case_ids (array, new behavior).
  • Suggestion: Whether returning case_id or case_ids, the query which reads civicrm_case_activity should include an ORDER BY clause to ensure that the result is deterministic.

Copy link
Member Author

@colemanw colemanw May 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The case_id return value is brand-new and I don't think it's even been documented yet, so most likely the only consumer so far is the civicase extension. IMO it's not too late to change it now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. It's only been in 4.7.18 and the upcoming 4.7.19:

git show bc4b6f0f5694d1a5b8e2151e6dcf9a394c300df4 | head
commit bc4b6f0f5694d1a5b8e2151e6dcf9a394c300df4
Author: Coleman Watts <coleman@civicrm.org>
Date:   Mon Mar 6 22:49:00 2017 -0500

    CRM-20102 - Return case_id from activity api

$ git tag --contains bc4b6f0f5694d1a5b8e2151e6dcf9a394c300df4
4.7.18

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I highly doubt anyone has used it let alone noticed it yet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI in theory we might start using multiple case ids per activity in more than just the "link cases" scenario. For example sending a mail blast across multiple cases.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you break something that did not have a unit test, it ain't broken ;)
Question on create, does it work with both case_id =int or case_id=array? Breaking on read is IMO not a huge issue, breaking on create risks loosing data.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point @tttp I've just updated the PR to cover that.

@totten
Copy link
Member

totten commented May 2, 2017

@colemanw I did a general sniff-test of using "Linked Cases" in the main UI, and this seems to still work. My only real hangup is changing the contract for the Activity field case_id. If that's addressed, then it's mergeable.

Tangentially, it seems weird that the "Linked Case" activity has status "Scheduled"... and that you can't change it. This is a pre-existing issue (and god knows there's probably someone who relies on it), but hopefully the new UI can default to status "Completed".

@totten
Copy link
Member

totten commented May 23, 2017

My previous concerns were addressed in the code-level discussion. 👍

@totten totten merged commit fff0e08 into civicrm:master May 23, 2017
@colemanw colemanw deleted the CRM-20097 branch May 23, 2017 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants