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) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Bug on 4.3? Can't update the status of a contribution
Pages: [1]

Author Topic: Bug on 4.3? Can't update the status of a contribution  (Read 524 times)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Bug on 4.3? Can't update the status of a contribution
April 30, 2013, 04:08:49 pm
Hi,

So I have a normal contribution, created normally from a donation page. I'm trying to use the api to changes its status:

Code: [Select]
$params = array(
  'version' => 3,
  'id' => 42,
  'contribution_status_id' => 2,
  'sequential' => 1,
);
$result = civicrm_api('Contribution', 'create', $params);

Was expecting to have the status changed, but got a constraint violation on the financial item. On a different/previous test, I had a different message about an activity (can't reproduce)

Is this an error that the BAO create doesn't check enough if the id is set (ie update instead of create) and tries to create related items where they have already been created?

I'm a bit unsure about if the financial_item has to be created when updated. Pretty sure not being able to change the status is a bug, but not sure what to report.

Result as created by the api explorer (with debug on)

Code: [Select]
{
"error_code":"constraint violation",
"sql":"INSERT INTO civicrm_financial_item (transaction_date , description , amount , currency , financial_account_id , status_id , entity_table , entity_id ) VALUES ( 0 , ' gev' ,  125.00 , 'CHF' ,  3 ,  3 , 'civicrm_line_item' ,  1 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civi_demo`.`civicrm_financial_item`, CONSTRAINT `FK_civicrm_financial_item_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)]",
"debug_info":"INSERT INTO civicrm_financial_item (transaction_date , description , amount , currency , financial_account_id , status_id , entity_table , entity_id ) VALUES ( 0 , ' gev' ,  125.00 , 'CHF' ,  3 ,  3 , 'civicrm_line_item' ,  1 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civi_demo`.`civicrm_financial_item`, CONSTRAINT `FK_civicrm_financial_item_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)]",
"trace":"#0 [internal function]: CRM_Core_Error::exceptionHandler(Object(DB_Error))\n#1 \/var\/projects\/civi.43\/packages\/PEAR.php(931): call_user_func(Array, Object(DB_Error))\n#2 \/var\/projects\/civi.43\/packages\/DB.php(969): PEAR_Error->PEAR_Error('DB Error: const...', -3, 16, Array, 'INSERT INTO civ...')\n#3 \/var\/projects\/civi.43\/packages\/PEAR.php(564): DB_Error->DB_Error(-3, 16, Array, 'INSERT INTO civ...')\n#4 \/var\/projects\/civi.43\/packages\/DB\/common.php(1905): PEAR->raiseError(NULL, -3, NULL, NULL, 'INSERT INTO civ...', 'DB_Error', true)\n#5 \/var\/projects\/civi.43\/packages\/DB\/mysql.php(898): DB_common->raiseError(-3, NULL, NULL, NULL, '1452 ** Cannot ...')\n#6 \/var\/projects\/civi.43\/packages\/DB\/mysql.php(327): DB_mysql->mysqlRaiseError()\n#7 \/var\/projects\/civi.43\/packages\/DB\/common.php(1216): DB_mysql->simpleQuery('INSERT INTO civ...')\n#8 \/var\/projects\/civi.43\/packages\/DB\/DataObject.php(2421): DB_common->query('INSERT INTO civ...')\n#9 \/var\/projects\/civi.43\/packages\/DB\/DataObject.php(1055): DB_DataObject->_query('INSERT INTO civ...')\n#10 \/var\/projects\/civi.43\/CRM\/Core\/DAO.php(287): DB_DataObject->insert()\n#11 \/var\/projects\/civi.43\/CRM\/Financial\/BAO\/FinancialItem.php(136): CRM_Core_DAO->save()\n#12 \/var\/projects\/civi.43\/CRM\/Financial\/BAO\/FinancialItem.php(115): CRM_Financial_BAO_FinancialItem::create(Array, NULL, Array)\n#13 \/var\/projects\/civi.43\/CRM\/Price\/BAO\/LineItem.php(294): CRM_Financial_BAO_FinancialItem::add(Object(CRM_Price_BAO_LineItem), Object(CRM_Contribute_BAO_Contribution))\n#14 \/var\/projects\/civi.43\/CRM\/Contribute\/BAO\/Contribution.php(2784): CRM_Price_BAO_LineItem::processPriceSet('1', Array, Object(CRM_Contribute_BAO_Contribution), 'civicrm_contrib...', false)\n#15 \/var\/projects\/civi.43\/CRM\/Contribute\/BAO\/Contribution.php(178): CRM_Contribute_BAO_Contribution::recordFinancialAccounts(Array, Array)\n#16 \/var\/projects\/civi.43\/CRM\/Contribute\/BAO\/Contribution.php(266): CRM_Contribute_BAO_Contribution::add(Array, Array)\n#17 \/var\/projects\/civi.43\/api\/v3\/Contribution.php(66): CRM_Contribute_BAO_Contribution::create(Array, Array)\n#18 \/var\/projects\/civi.43\/api\/api.php(75): civicrm_api3_contribution_create(Array)\n#19 \/var\/projects\/civi.43\/CRM\/Utils\/REST.php(412): civicrm_api('Contribution', 'create', Array)\n#20 \/var\/projects\/civi.43\/CRM\/Utils\/REST.php(634): CRM_Utils_REST::process(Array, false)\n#21 [internal function]: CRM_Utils_REST::ajax(Array)\n#22 \/var\/projects\/civi.43\/CRM\/Core\/Invoke.php(258): call_user_func(Array, Array)\n#23 \/var\/projects\/civi.43\/CRM\/Core\/Invoke.php(70): CRM_Core_Invoke::runItem(Array)\n#24 \/var\/projects\/civi.43\/CRM\/Core\/Invoke.php(52): CRM_Core_Invoke::_invoke(Array)\n#25 \/var\/projects\/civi.43\/drupal\/civicrm.module(436): CRM_Core_Invoke::invoke(Array)\n#26 [internal function]: civicrm_invoke('ajax', 'rest')\n#27 \/var\/projects\/drupal\/43\/includes\/menu.inc(517): call_user_func_array('civicrm_invoke', Array)\n#28 \/var\/projects\/drupal\/43\/index.php(21): menu_execute_active_handler()\n#29 {main}",
"is_error":1,
"error_message":"DB Error: constraint violation"
}

-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Bug on 4.3? Can't update the status of a contribution

This forum was archived on 2017-11-26.