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) »
  • Problem calling civicrm_participant_update API from hook
Pages: [1]

Author Topic: Problem calling civicrm_participant_update API from hook  (Read 716 times)

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Problem calling civicrm_participant_update API from hook
October 18, 2010, 07:12:34 am
I have implemented the hook "mymodule_civicrm_buildForm" . It only does anything on one particular profile. ( A profile I call "Attendance", which only includes first and last name. )

For this specific profile, I call the API   "civicrm_participant_update($params);"

( The affect is that by the time the user sees the profile, they  have been marked as "attended".  )  They can click the "save" or "cancel" button, which has the affect of simply saving their first and last name. ( I have not implemented the hook "civicrm_postprocess()"  )

Everything was working before I upgraded the site to 3.2.3. The "mymodule_civicrm_buildForm" hook still works ( ie they are marked as attended. )

However, if the user clicks the "save" button on the profile,  they get this following error:

-------------------------------------------------------------------------------------

Database Error Code: Cannot add or update a child row: a foreign key constraint fails (`newsholo_drp1`.`civicrm_participant`, CONSTRAINT `FK_civicrm_participant_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE), 1452
Additional Details:
Array
(
    [callback] => Array
        (
           
  • => CRM_Core_Error
  • [1] => handle
            )

       
Code: [Select]
=> -3
    [message] => DB Error: constraint violation
    [mode] => 16
    [debug_info] => INSERT INTO civicrm_participant (event_id , status_id ) VALUES ( 0 ,  2 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`newsholo_drp1`.`civicrm_participant`, CONSTRAINT `FK_civicrm_participant_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)]
    [type] => DB_Error
    [user_info] => INSERT INTO civicrm_participant (event_id , status_id ) VALUES ( 0 ,  2 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`newsholo_drp1`.`civicrm_participant`, CONSTRAINT `FK_civicrm_participant_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)]
    [to_string] => [db_error: message="DB Error: constraint violation" code=-3 mode=callback callback=CRM_Core_Error::handle prefix="" info="INSERT INTO civicrm_participant (event_id , status_id ) VALUES ( 0 ,  2 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`newsholo_drp1`.`civicrm_participant`, CONSTRAINT `FK_civicrm_participant_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)]"]
)

---------------------------------------------
 If I eliminate the call to the civicrm_participant_update API, then I don't get the error. ( But, obviously they are not marked as attended, which is what I really want. )

Any ideas?
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Problem calling civicrm_participant_update API from hook
October 18, 2010, 07:33:33 am
Hi,

Seems that your event id is 0. somehow, you have this info lost somewhere.

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

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Problem calling civicrm_participant_update API from hook
October 18, 2010, 08:23:50 am
I evaluated the event id in the hook "civicrm_buildForm", and it has the correct event id.

I am confused why CiviCRM is trying to update the table "civicrm_participant" on the profile form submission, since I do not implement the hook "civicrm_postProcess"
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Problem calling civicrm_participant_update API from hook
October 18, 2010, 08:02:38 pm
I found a solution to my problem.  I added some code to check if the event id <> 0 before calling the API.

I am still perplexed as to why the hook "mymodule_civicrm_buildForm" is called both when getting ready to display the profile, as well as being called when the profile is saved. 
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Problem calling civicrm_participant_update API from hook

This forum was archived on 2017-11-26.