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-21854 - Contribution start date and end dates are not respected #11881

Merged
merged 3 commits into from
Jun 14, 2018

Conversation

yashodha
Copy link
Contributor

@yashodha yashodha commented Mar 27, 2018

Overview

Steps to replicate :

  1. Create a contribution page with end date earlier than today.
  2. Go to live mode, the page is still active and nothing changes.
  3. Similarly, if the start date is set in future, that's also not disabling the page.

Before

able to access the contribution page

After

not able to access the contribution page

Comments

Users are getting confused as to why the contribution continued to accept payments after the end date. There is no way to set a contribution to end without manually going in to inactivate.


@eileenmcnaughton
Copy link
Contributor

@yashodha whenever we touch a datefield in a form we should change it to use datepicker - I'm guessing these fields aren't since CRM_Utils_Date::processDate shouldn't be needed for a datepicker field (also you need to strtotime before comparing)

$endDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('end_date', $this->_values));
$now = date('YmdHis');
if ($endDate && $endDate < $now) {
throw new Exception(ts('The page you requested has past its end date on '. CRM_Utils_Date::customFormat($endDate) ), $this->_id);
Copy link
Contributor

Choose a reason for hiding this comment

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

should we be chucking Exception or CRM_Contribute_Exception_InactiveContributionPageException exception? @eileenmcnaughton

Copy link
Contributor

Choose a reason for hiding this comment

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

ohh clever spotting!

@yashodha
Copy link
Contributor Author

yashodha commented Apr 4, 2018

@eileenmcnaughton : used datepicker instead. Should we do a grep and replace in the code base for consistency.

@eileenmcnaughton
Copy link
Contributor

@yashodha - it would be great to clean them all up in one fell swoop- - but a bit risky since we need to test each one :-(

@@ -0,0 +1,25 @@
<?php

class CRM_Contribute_Exception_FutureContributionPageException extends Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

@@ -313,6 +313,17 @@ public function preProcess() {
throw new CRM_Contribute_Exception_InactiveContributionPageException(ts('The page you requested is currently unavailable.'), $this->_id);
}

$endDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('end_date', $this->_values));
Copy link
Contributor

Choose a reason for hiding this comment

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

so I wonder why $this->_values is not in iso format then? -

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eileenmcnaughton : it is in iso format as well but needs to be compared to $now

$this->_values['end_date'] = 2021-04-27 00:00:00
$now = 20180523123026

Copy link
Contributor

Choose a reason for hiding this comment

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

OK - so I guess the readability thing is that instead of using standard php functions we have to dig into a custom function to realise it's basically not doing anything a std function doesn't.

To make it more readable we should make it clear we are comparing like with like - ie preferably compare timestamps

if (!empty[ $this->_values['end_date']) {
$timestamp = strtotime(CRM_Utils_Array::value('end_date', $this->_values));
if ( $timestamp < time())
....

But if for some reason that is going to be a problem then at least format $this->_values['end_date'] the same way as $now ie.

if (!empty[ $this->_values['end_date']) {
$timestamp = strtotime(CRM_Utils_Array::value('end_date', $this->_values));
if ( date('YmdHis', $timestamp)  < date('YmdHis'))
....

Copy link
Contributor Author

@yashodha yashodha May 23, 2018

Choose a reason for hiding this comment

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

@eileenmcnaughton
how about using CRM_Utils_Date::isoToMysql which makes it clearer?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm - I feel like for most devs using straight php functions makes is clearer since they are highly used to those & the Civi date functions can be a bit weird & wonderful - but I do agree that is a lot clearer than 'processDate'

Is it really ISO format ? I mean there would never timezone info on the date?

@eileenmcnaughton
Copy link
Contributor

I'm just looking through PRs & assessing this one. It seems to be that it was just about merge-ready but the last comment wasn't replied to so it dropped off my radar.

I'm not loving the user experience of this -

screenshot 2018-06-14 19 45 10

I think a bounce + a message would be better and I think the processDate function is unnecessary & hampers readability.

However, it's the user experience worse than it is without the patch (given that the field is ignored), the Exception structure is nice & it removes technical debt on the datepicker field.

So I'm opting to merge it.

@eileenmcnaughton
Copy link
Contributor

@yashodha looks like we missed something here #12504 - picked up in rc though

eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Jul 18, 2018
Unreleased regression from civicrm#11881
see https://lab.civicrm.org/dev/core/issues/263

Change-Id: Ida8a07cf0d641008a099dfdbe87acf6ebfab3e51
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Jul 18, 2018
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