-
Notifications
You must be signed in to change notification settings - Fork 191
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
Fatal Error when setting donation date to future #6698
Comments
Hey @flack - thanks for the bug report. I'm surprised that I wasn't able to find a duplicate issue for this 😅. Seems to be one of those bugs that goes unreported. Somewhat related is #6595 (mentioning here for cross-reference). Perhaps @ravinderk has some related historical knowledge as to why We are generally protective of that status list, but whether we add I'll bring this to the team for prioritization. |
@kjohnson Current issue and #6595 are separate. #6595 has a logical error in the donation importer and we should fix it. The author mentioned that this issue is caused by a future donation date. I did not see any reason to adjust the donation date in the future, so we should not allow a @Benunc Do you think the donation date can be set to the future? |
Good point, @ravinderk - thank you. |
This issue has been linked to a Canny post: Fatal Error when setting donation date to future 🎉 |
Summary from Slack converstaion:
|
I do not think donations should be able to be set in the future. Sorry I missed this ping. @ravinderk |
Any news on solving this? It's still happening on production for us, so I have to hack the deployed Give code to make the backend useable again |
Hi @flack! This is a UI issue that will be resolved in a future version of GiveWP. In the meantime, I threw together this snippet that you can add somewhere, which will prevent donations from being saved in the future and thus changing the post status: add_filter('wp_insert_post_data', static function(array $data, array $postarr) {
if ($data['post_type'] !== 'give_payment') {
return $data;
}
// Check if $data date is in the future, and set it to now if so.
if ( strtotime($data['post_date']) >= strtotime('+1 second') ) {
$oldPost = get_post($postarr['ID']);
$data['post_date'] = current_time('mysql');
$data['post_date_gmt'] = current_time('mysql', true);
$data['post_status'] = $oldPost->post_status;
}
return $data;
}, 10, 2); We may consider adding a guard rail like this in GiveWP to help as well, but I don't want that decision to prevent you from having something in place. This should be future-safe from any changes made on our end. |
@JasonTheAdams thanks, I added this to our code. Fingers crossed that we can delete it soon! :-) |
@JasonTheAdams did you test this code? Because I've added it on our site, and now I can't create any donations anymore. The |
P.S.: Just a guess: We're in GMT+1 timezone, probably the check is always true because of that? but even if I change to |
Hi @flack! Yeah, I did test it. Apparently I dropped the Friendly note, I would always make sure to test a snippet (or any code change) locally before applying it to production — no matter who gives it to you. Obviously, we can't test it on your exact environment, so whatever we send you may not be appropriately fine-tuned. |
@JasonTheAdams yeah, no worries, we didn't apply to production right away, it was caught on the staging server, so no actual users were affected :-) I'll try your suggestions tomorrow, thanks for following up! |
Hahah! Oh good! I'm glad! If you wouldn't mind dropping the snippet that ends up working here for others to glean from that would be awesome! |
@JasonTheAdams so the version that works in principle for me looks like this: add_filter('wp_insert_post_data', static function(array $data) {
if ($data['post_type'] === 'give_payment') {
// Check if $data date is in the future, and set it to now if so.
if ( strtotime($data['post_date_gmt']) >= strtotime('+1 second') ) {
$data['post_date'] = current_time('mysql');
$data['post_date_gmt'] = current_time('mysql', true);
}
}
return $data;
}, 10); I've removed the |
User Story
As an admin, I want to set offline donations to Completed in the backend. If I mis-click in the date selector for some reason, I get a Fatal Error and an email is sent to the site administrator
Details
When you set the date of a donation to the future (most likely by accident), the follwing Fatal Error occurs:
Expected Behavior
Steps to Reproduce
Additional Context
The easiest fix would probably be to add
to the constants here:
givewp/src/Donations/ValueObjects/DonationStatus.php
Lines 33 to 41 in 41a1b43
It does fix the Fatal Error, but I didn't test if it has any side effects
System Information
Details
Acceptance Criteria
The text was updated successfully, but these errors were encountered: