-
Notifications
You must be signed in to change notification settings - Fork 51
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
Conversation
9a69f99
to
99c9972
Compare
// 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); |
There was a problem hiding this comment.
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;
}
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
99c9972
to
b8f3193
Compare
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