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

1404: Dont delete field data on p2b API error #1393

Merged
merged 1 commit into from
Mar 28, 2019

Conversation

holt83
Copy link
Member

@holt83 holt83 commented Mar 22, 2019

Link to issue

https://platform.dandigbib.org/issues/1404

Description

I discovered this while testing the new integration module on our production database:

If something goes wrong communicating with p2b API when updating existing event that is sync'ed with p2b, the code will override the field data with empty array, destroying the the link between p2b and CMS.

This PR introduces some better handling of these situations.

Screenshot of the result

If your change affects the user interface you should include a screenshot of the result with the pull request.

Checklist

  • My complies with our coding guidelines.
  • My code passes our static analysis suite. If not then I have added a comment explaining why this change should be exempt from the code standards and process.
  • My code passes our continuous integration process. If not then I have added a comment explaining why this change should be exempt from the code standards and process.

@holt83 holt83 force-pushed the 1404-p2b-error-handling branch 3 times, most recently from 9a69f99 to 99c9972 Compare March 22, 2019 13:49
// Ensure that both 'synchronize' and 'do_sync' is set and TRUE, before
// making any requests to p2b API. This is to ensure we don't make lots
// of unneeded requests when nodes are saved programmatically or updated
// in bulk via the UI.
// See ding_place2book_field_widget_form() for more info.
if ($settings['synchronize'] && !empty($settings['do_sync'])) {
$items = _ding_place2book_sync_p2b_entities($entity, $settings);
$synchronized = _ding_place2book_sync_p2b_entities($entity, $settings);
Copy link
Member

Choose a reason for hiding this comment

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

This seems odd to me. According to the DocBlock _ding_place2book_sync_p2b_entities returns an array. This change seems to assume that it can be a boolean. Does the DocBlock need updating or are we handling a case where we might get an empty array returned in case on an error?

Could we simplify the change to something like:

$synchronized_items = _ding_place2book_sync_p2b_entities($entity, $settings);
// Only update field data if synchronization was successful.
if (!empty($synchronized_items)) {
  $items = $synchronized_items;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

With your suggestion we don't have to change return value and update docblock, so I think we should go with that. I'll update PR.

}
catch (Exception $ex) {
watchdog_exception('ding_place2book', $ex);
drupal_set_message($ex->getMessage(), 'error');
return $items;
return FALSE;
Copy link
Member

Choose a reason for hiding this comment

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

This seems to indicate that the DocBlock should be updated or that we should just make it explicit that returning an empty array means that no items are sync'ed.

@kasperg kasperg merged commit 9acbdf9 into ding2:master Mar 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants