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 CiviContribute (Moderator: Donald Lobo) »
  • Recurring contributions: sql error in civicrm 2.0.1 ?
Pages: [1]

Author Topic: Recurring contributions: sql error in civicrm 2.0.1 ?  (Read 1632 times)

mathieu

  • Administrator
  • Ask me questions
  • *****
  • Posts: 620
  • Karma: 36
    • Work
  • CiviCRM version: 4.7
  • CMS version: Drupal
  • MySQL version: MariaDB 10
  • PHP version: 7
Recurring contributions: sql error in civicrm 2.0.1 ?
April 14, 2008, 06:58:18 pm
Hi,

We are having a problem with recurring transactions: the insert statement into civicrm_contribution_recur complains that "Duplicate entry '1' for key 2, 1062". From what I understand, it seems that the insert causes a duplicate entry on the key (domain_id, trxn_id).

The insert statement doesn't seem to insert the "trxn_id". The existing entry in the database has a null value for trxn_id, and the insert statement shown in the backtrace does not insert the trxn_id either. However, the payment gateway code (authorize.net) returns a valid trxn_id (I did a var_dump before returning the $params).

I modified CRM/Contribute/Form/Contribution/Confirm.php to add:
 
 $recurParams['trxn_id'] = $params['trxn_id'];

a bit before the call to "$recurring =& CRM_Contribute_BAO_ContributionRecur::add( $recurParams, $ids );" (i.e. around line 689). And it seems to fix the problem, i.e. the trxn_id is stored in the database, and inserts no longer cause a duplicate key error.

However, I am wondering maybe this was intentional. Recurring transactions are processed by the gateway, and I guess that it will send the donor a new receipt every time the credit card is billed. I do not feel very comfortable editing the code related to the processing of transactions. I am offtrack?

We are using CiviCRM 2.0.1, PHP5, Drupal 5. I made a diff with civicrm 2.0.2 and did not see any fix on that specific issue.

Here is the full backtrace of the insert statement which was causing problems:

Code: [Select]
Database Error Code: Duplicate entry '1' for key 2, 1062

Array
(
[callback] => Array
(
[0] => CRM_Core_Error
[1] => handle
)

[code] => -5
[message] => DB Error: already exists
[mode] => 16
[debug_info] => INSERT INTO civicrm_contribution_recur (domain_id , contact_id , amount , frequency_unit , frequency_interval , start_date , create_date , invoice_id , contribution_status_id ) VALUES ( 1 , 5 , 1 , 'month' , 1 , 20080414174555 , 20080414174555 , 'f920b2c738c79dffd3fdd22668127e0b' , 2 ) [nativecode=1062 ** Duplicate entry '1' for key 2]
[type] => DB_Error
[user_info] => INSERT INTO civicrm_contribution_recur (domain_id , contact_id , amount , frequency_unit , frequency_interval , start_date , create_date , invoice_id , contribution_status_id ) VALUES ( 1 , 5 , 1 , 'month' , 1 , 20080414174555 , 20080414174555 , 'f920b2c738c79dffd3fdd22668127e0b' , 2 ) [nativecode=1062 ** Duplicate entry '1' for key 2]
[to_string] => [db_error: message="DB Error: already exists" code=-5 mode=callback callback=CRM_Core_Error::handle prefix="" info="INSERT INTO civicrm_contribution_recur (domain_id , contact_id , amount , frequency_unit , frequency_interval , start_date , create_date , invoice_id , contribution_status_id ) VALUES ( 1 , 5 , 1 , 'month' , 1 , 20080414174555 , 20080414174555 , 'f920b2c738c79dffd3fdd22668127e0b' , 2 ) [nativecode=1062 ** Duplicate entry '1' for key 2]"]
)

Backtrace:


backTrace

sites/all/modules/civicrm/CRM/Core/Error.php, backtrace, 148, handle,
sites/all/modules/civicrm/packages/PEAR.php, call_user_func, 901
sites/all/modules/civicrm/packages/DB.php, PEAR_Error, 888
sites/all/modules/civicrm/packages/PEAR.php, DB_Error, 563
sites/all/modules/civicrm/packages/DB/common.php, raiseError, 1849
sites/all/modules/civicrm/packages/DB/mysql.php, raiseError, 894
sites/all/modules/civicrm/packages/DB/mysql.php, mysqlRaiseError, 324
sites/all/modules/civicrm/packages/DB/common.php, simpleQuery, 1162
sites/all/modules/civicrm/packages/DB/DataObject.php, query, 2343
sites/all/modules/civicrm/packages/DB/DataObject.php, _query, 1033
sites/all/modules/civicrm/CRM/Core/DAO.php, insert, 248
sites/all/modules/civicrm/CRM/Contribute/BAO/ContributionRecur.php, save, 71
sites/all/modules/civicrm/CRM/Contribute/Form/Contribution/Confirm.php, add, 694
sites/all/modules/civicrm/CRM/Contribute/Form/Contribution/Confirm.php, processRecurringContribution, 520
sites/all/modules/civicrm/CRM/Contribute/BAO/Contribution.php, processContribution, 859
sites/all/modules/civicrm/CRM/Contribute/Form/Contribution/Confirm.php, processConfirm, 407
sites/all/modules/civicrm/CRM/Core/StateMachine.php, postProcess, 166
sites/all/modules/civicrm/CRM/Core/QuickForm/Action/Next.php, perform, 63
sites/all/modules/civicrm/packages/HTML/QuickForm/Controller.php, perform, 195
sites/all/modules/civicrm/packages/HTML/QuickForm/Page.php, handle, 95
sites/all/modules/civicrm/CRM/Core/Controller.php, handle, 223
sites/all/modules/civicrm/CRM/Contribute/Invoke.php, run, 106
sites/all/modules/civicrm/CRM/Core/Component.php, main, 130
sites/all/modules/civicrm/CRM/Core/Invoke.php, invoke, 158
sites/all/modules/civicrm/drupal/civicrm.module, invoke, 321, civicrm_invoke,
includes/menu.inc, call_user_func_array, 418
index.php, menu_execute_active_handler, 15

The $recurParams in CRM/Contribute/BAO/Contribution.php before my edit:

array(9) { ["contact_id"]=> string(1) "5" ["amount"]=> string(1) "1" ["frequency_unit"]=> string(5) "month" ["frequency_interval"]=> string(1) "1" ["installments"]=> NULL ["create_date"]=> string(14) "20080414174555" ["start_date"]=> string(14) "20080414174555" ["invoice_id"]=> string(32) "f920b2c738c79dffd3fdd22668127e0b" ["contribution_status_id"]=> int(2) }

thanks,
matt (bgm on freenode)[/code]
CiviCamp Montréal, 29 septembre 2017 | Co-founder / consultant / turn-key CiviCRM hosting for Quebec/Canada @ SymbioTIC.coop

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Recurring contributions: sql error in civicrm 2.0.1 ?
April 14, 2008, 08:00:51 pm

please file and issue and we'll incorporate a version of your patch for 2.0.3

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

mathieu

  • Administrator
  • Ask me questions
  • *****
  • Posts: 620
  • Karma: 36
    • Work
  • CiviCRM version: 4.7
  • CMS version: Drupal
  • MySQL version: MariaDB 10
  • PHP version: 7
Re: Recurring contributions: sql error in civicrm 2.0.1 ?
April 23, 2008, 11:09:15 am
Thanks lobo. I have opened CRM-3024.
CiviCamp Montréal, 29 septembre 2017 | Co-founder / consultant / turn-key CiviCRM hosting for Quebec/Canada @ SymbioTIC.coop

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Recurring contributions: sql error in civicrm 2.0.1 ?

This forum was archived on 2017-11-26.