CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMember (Moderator: Deepak Srivastava) »
  • Failed attempt to renew membership
Pages: [1]

Author Topic: Failed attempt to renew membership  (Read 2927 times)

adixon

  • I post frequently
  • ***
  • Posts: 314
  • Karma: 19
    • Blackfly Solutions
Failed attempt to renew membership
March 18, 2009, 02:39:28 pm
Here's the message in CiviCRM.log:

Mar 18 15:17:52  [info] $Fatal Error Details = Array
(
    [callback] => Array
        (
           
  • => CRM_Core_Error
  • [1] => handle
            )

       
Code: [Select]
=> -1
    [message] => DB Error: unknown error
    [mode] => 16
    [debug_info] => INSERT INTO civicrm_membership_log (membership_id , start_date , end_date , modified_id , modified_date , renewal_reminder_date ) VALUES ( 414 ,  20080227 ,  20090225 ,  1181 ,  20090318 ,  NULL )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrm_fairvote_ca/civicrm_membership_log`, CONSTRAINT `FK_civicrm_membership_log_status_id` FOREIGN KEY (`status_id`) REFERENCES `civicrm_membership_status` (`id`) ON DELETE CASCADE)]
    [type] => DB_Error
    [user_info] => INSERT INTO civicrm_membership_log (membership_id , start_date , end_date , modified_id , modified_date , renewal_reminder_date ) VALUES ( 414 ,  20080227 ,  20090225 ,  1181 ,  20090318 ,  NULL )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrm_fairvote_ca/civicrm_membership_log`, CONSTRAINT `FK_civicrm_membership_log_status_id` FOREIGN KEY (`status_id`) REFERENCES `civicrm_membership_status` (`id`) ON DELETE CASCADE)]
    [to_string] => [db_error: message="DB Error: unknown error" code=-1 mode=callback callback=CRM_Core_Error::handle prefix="" info="INSERT INTO civicrm_membership_log (membership_id , start_date , end_date , modified_id , modified_date , renewal_reminder_date ) VALUES ( 414 ,  20080227 ,  20090225 ,  1181 ,  20090318 ,  NULL )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrm_fairvote_ca/civicrm_membership_log`, CONSTRAINT `FK_civicrm_membership_log_status_id` FOREIGN KEY (`status_id`) REFERENCES `civicrm_membership_status` (`id`) ON DELETE CASCADE)]"]
)


Mar 18 15:17:52  [info] $backTrace = /var/www/drupal/5/sites/all/modules/civicrm/CRM/Core/Error.php, backtrace, 192
, handle,
/var/www/drupal/5/sites/all/modules/civicrm/packages/PEAR.php, call_user_func, 901
/var/www/drupal/5/sites/all/modules/civicrm/packages/DB.php, PEAR_Error, 888
/var/www/drupal/5/sites/all/modules/civicrm/packages/PEAR.php, DB_Error, 563
/var/www/drupal/5/sites/all/modules/civicrm/packages/DB/common.php, raiseError, 1849
/var/www/drupal/5/sites/all/modules/civicrm/packages/DB/mysql.php, raiseError, 894
/var/www/drupal/5/sites/all/modules/civicrm/packages/DB/mysql.php, mysqlRaiseError, 324
/var/www/drupal/5/sites/all/modules/civicrm/packages/DB/common.php, simpleQuery, 1162
/var/www/drupal/5/sites/all/modules/civicrm/packages/DB/DataObject.php, query, 2343
/var/www/drupal/5/sites/all/modules/civicrm/packages/DB/DataObject.php, _query, 1033
/var/www/drupal/5/sites/all/modules/civicrm/CRM/Core/DAO.php, insert, 248
/var/www/drupal/5/sites/all/modules/civicrm/CRM/Member/BAO/MembershipLog.php, save, 56
/var/www/drupal/5/sites/all/modules/civicrm/CRM/Member/BAO/Membership.php, add, 1269
/var/www/drupal/5/sites/all/modules/civicrm/CRM/Member/BAO/Membership.php, fixMembershipStatusBeforeRenew, 957
/var/www/drupal/5/sites/all/modules/civicrm/CRM/Member/Form/MembershipRenewal.php, renewMembership, 245
/var/www/drupal/5/sites/all/modules/civicrm/CRM/Core/StateMachine.php, postProcess, 166
/var/www/drupal/5/sites/all/modules/civicrm/CRM/Core/QuickForm/Action/Next.php, perform, 63
/var/www/drupal/5/sites/all/modules/civicrm/packages/HTML/QuickForm/Controller.php, perform, 195
/var/www/drupal/5/sites/all/modules/civicrm/packages/HTML/QuickForm/Page.php, handle, 95
/var/www/drupal/5/sites/all/modules/civicrm/CRM/Core/Controller.php, handle, 223
/var/www/drupal/5/sites/all/modules/civicrm/CRM/Contact/Page/View/Membership.php, run, 165
[etc.]

It's on Drupal 5, CiviCRM 2.06. The user has successfully done a lot of other renewals, this error occurs on two users. They tried logging in and out, same error.

Kiran Jagtap

  • Ask me questions
  • ****
  • Posts: 533
  • Karma: 51
Re: Failed attempt to renew membership
March 19, 2009, 12:08:04 am
hi,

Basically empty status value for given membership dates triggering this error.
I guess as per membership dates there is no membership status rule available in your CiviCRM db or rules might be disabled, so make sure you have properly configured status rules. 
Also our Test Plan for Membership Renewals might help you.

We have fixed this edge case for v2.2
Code: [Select]
        if ( empty( $status ) ||
             empty( $status['id'] ) ) {
            CRM_Core_Error::fatal( ts( 'Oops, it looks like there is no valid membership status corresponding to the membership start and end dates for this membership. Contact the site administrator for assistance.' ) );
        }

you can back port this code to CRM/Membership/BAO/Membership.php line around 1228
before 
Code: [Select]
$currentMembership['today_date'] = $today;
kiran


« Last Edit: March 19, 2009, 12:44:49 am by kiran »
You Are Designed To Choose... Defined By Choice.

adixon

  • I post frequently
  • ***
  • Posts: 314
  • Karma: 19
    • Blackfly Solutions
Re: Failed attempt to renew membership
March 19, 2009, 05:37:19 am
Hi Kiran:

Thanks for this, i think i'm understanding the error now. Your patch is helpful for being a better error, and the links are helpful for understanding membership status rules in general, but I still don't understand what is wrong with this particular setup. Specifically, the error as I understand it is here:

 $status = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate(
                                                                             $currentMembership['start_date'],
                                                                             $currentMembership['end_date'],
                                                                             $currentMembership['join_date'],
                                                                             $today
                                                                             );
in the fixMembershipStatus - i.e. before changing the status, CiviCRM wants to make sure the current membership is up-to-date, since the cron might not have run since the previous changes. That all makes sense...

In this case, the member had expired about a month before, and this client didn't want to make use of the grace period status. So here are the rules:

Status   Start Event   End Event   Member   Admin   Weight   Enabled?   
New   join date   join date   Yes    No      Move down one row Move to bottom   Yes    Edit | Disable | Delete
Current   start date   end date   Yes    No    Move to top Move up one row Move down one row Move to bottom   Yes    Edit | Disable | Delete
Grace   end date   end date   No    Yes    Move to top Move up one row Move down one row Move to bottom   Yes    Edit | Disable | Delete
Expired   end date      No    No    Move to top Move up one row Move down one row Move to bottom   Yes    Edit | Disable | Delete
Pending   join date   join date   No    No    Move to top Move up one row Move down one row Move to bottom   No    Edit | Enable | Delete
Cancelled   join date   join date   No    Yes    Move to top Move up one row     Yes    Edit | Disable | Delete

From my reading of this - the user should have been expired, though when I looked at it, it claimed it was current. On the other hand, it wasn't me getting the errors, perhaps this was just because I was an administrator of some kind?

Any other hints about why this was happenning or how to fix our rules?

adixon

  • I post frequently
  • ***
  • Posts: 314
  • Karma: 19
    • Blackfly Solutions
Re: Failed attempt to renew membership
April 10, 2009, 11:27:02 am
Okay, it turned out that there was a gap between the end of a membership and when it was marked as expired. This is because I removed the grace period. All I had to do was to update the corresponding start date of the expired rule.

I have to say though, this surely has to count as a code bug. Either the membership rule changes should alert me to the fact that there is a gap, or the handling when there's no valid membership should do something nicer. It's particularly irritating because when I was looking at the constituent, it showed up with a valid membership status [presumably some kind of error handling stuff].

I guess that's what the Test Plan for membership is trying to address, but in the meantime, it seems to me that there is some code that could be fixed as well.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMember (Moderator: Deepak Srivastava) »
  • Failed attempt to renew membership

This forum was archived on 2017-11-26.