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 CiviEvent (Moderator: Yashodha Chaku) »
  • CiviEvent deleting contact after creation
Pages: [1]

Author Topic: CiviEvent deleting contact after creation  (Read 968 times)

bpmccain

  • I post frequently
  • ***
  • Posts: 255
  • Karma: 5
  • CiviCRM version: 4.1
  • CMS version: Drupal 7.12
  • MySQL version: 5.2
  • PHP version: 5.2
CiviEvent deleting contact after creation
October 22, 2013, 02:16:17 pm
I have a strange issue with CiviEvent. Basically it seems as though the creation of a contact is not happening properly, and so when it tries to create the contribution with the contact ID, it gives a foreign key error as the contact id does not exist in civicrm_contact.

I'm using a custom profile to get the contact information, and that profile operates perfectly normally on its own, correctly creating a new contact.

I put some code in a post hook to have a look at what was happening post contact creation. The hook runs, so civi is creating a contact and all of the correct contact info is in the $objectRef (name, etc). However, when I look in the database seconds after, the contact does not actually exist.

Below is the code in my post hook.
Code: [Select]
if ( ($op == 'create') && ($objectName == 'Individual') ){
              print_r($objectId);
              print_r($objectRef);
              CRM_Core_Error::backtrace( );
              CRM_Core_Error::debug( 'T', $type );
              exit( );
}

And below is the output of the two print_r statements:
Code: [Select]
945938CRM_Contact_DAO_Contact Object ( [id] => 945938 [contact_type] => Individual [contact_sub_type] => null [do_not_email] => [do_not_phone] => [do_not_mail] => [do_not_sms] => [do_not_trade] => [is_opt_out] => [legal_identifier] => [external_identifier] => [sort_name] => Tester, Testing [display_name] => Testing Tester [nick_name] => [legal_name] => [image_URL] => [preferred_communication_method] => [preferred_language] => en_CA [preferred_mail_format] => [hash] => 0a66ed4078fd314ffdbc80a5dc1dd11b [api_key] => [source] => [first_name] => Testing [middle_name] => null [last_name] => Tester [prefix_id] => null [suffix_id] => [email_greeting_id] => 1 [email_greeting_custom] => [email_greeting_display] => [postal_greeting_id] => 1 [postal_greeting_custom] => [postal_greeting_display] => [addressee_id] => 1 [addressee_custom] => [addressee_display] => [job_title] => [gender_id] => null [birth_date] => null [is_deceased] => [deceased_date] => [household_name] => [primary_contact_id] => [organization_name] => [sic_code] => [user_unique_id] => [employer_id] => [is_deleted] => [created_date] => [modified_date] => [_DB_DataObject_version] => 1.8.12 [__table] => civicrm_contact [N] => 0 [_database_dsn] => [_database_dsn_md5] => 32ae8a3ab826a9a3886c1e1183f3b6e2 [_database] => civinbla [_query] => Array ( [condition] => [group_by] => [order_by] => [having] => [limit_start] => [limit_count] => [data_select] => * ) [_DB_resultid] => [_resultFields] => [_link_loaded] => [_join] => [_lastError] => [phone] => Array ( [0] => CRM_Core_DAO_Phone Object ( [id] => 47058 [contact_id] => 945938 [location_type_id] => 1 [is_primary] => 1 [is_billing] => 0 [mobile_provider_id] => [phone] => 5069991940 [phone_ext] => [phone_numeric] => [phone_type_id] => 1 [_DB_DataObject_version] => 1.8.12 [__table] => civicrm_phone [N] => 0 [_database_dsn] => [_database_dsn_md5] => 32ae8a3ab826a9a3886c1e1183f3b6e2 [_database] => civinbla [_query] => Array ( [condition] => [group_by] => [order_by] => [having] => [limit_start] => [limit_count] => [data_select] => * ) [_DB_resultid] => [_resultFields] => [_link_loaded] => [_join] => [_lastError] => ) ) [email] => Array ( ) [im] => [openid] => [address] => Array ( [0] => CRM_Core_DAO_Address Object ( [id] => 945133 [contact_id] => 945938 [location_type_id] => 5 [is_primary] => 1 [is_billing] => 1 [street_address] => 21872 laskjhdka [street_number] => [street_number_suffix] => [street_number_predirectional] => [street_name] => [street_type] => [street_number_postdirectional] => [street_unit] => [supplemental_address_1] => [supplemental_address_2] => [supplemental_address_3] => [city] => Fredericton [county_id] => [state_province_id] => 1103 [postal_code_suffix] => [postal_code] => E3B 2M4 [usps_adc] => [country_id] => 1039 [geo_code_1] => 45.9601958 [geo_code_2] => -66.6615021 [manual_geo_code] => 0 [timezone] => [name] => Testing Tester [master_id] => [_DB_DataObject_version] => 1.8.12 [__table] => civicrm_address [N] => 0 [_database_dsn] => [_database_dsn_md5] => 32ae8a3ab826a9a3886c1e1183f3b6e2 [_database] => civinbla [_query] => Array ( [condition] => [group_by] => [order_by] => [having] => [limit_start] => [limit_count] => [data_select] => * ) [_DB_resultid] => [_resultFields] => [_link_loaded] => [_join] => [_lastError] => ) [1] => CRM_Core_DAO_Address Object ( [id] => 945134 [contact_id] => 945938 [location_type_id] => 1 [is_primary] => 1 [is_billing] => 0 [street_address] => 21872 laskjhdka [street_number] => [street_number_suffix] => [street_number_predirectional] => [street_name] => [street_type] => [street_number_postdirectional] => [street_unit] => [supplemental_address_1] => null [supplemental_address_2] => [supplemental_address_3] => [city] => Fredericton [county_id] => [state_province_id] => 1103 [postal_code_suffix] => [postal_code] => E3B 2M4 [usps_adc] => [country_id] => 1039 [geo_code_1] => 45.9601958 [geo_code_2] => -66.6615021 [manual_geo_code] => 0 [timezone] => [name] => [master_id] => [_DB_DataObject_version] => 1.8.12 [__table] => civicrm_address [N] => 0 [_database_dsn] => [_database_dsn_md5] => 32ae8a3ab826a9a3886c1e1183f3b6e2 [_database] => civinbla [_query] => Array ( [condition] => [group_by] => [order_by] => [having] => [limit_start] => [limit_count] => [data_select] => * ) [_DB_resultid] => [_resultFields] => [_link_loaded] => [_join] => [_lastError] => ) ) [contact_type_display] => Individual )
So as you can see, it appears the contact did exist, and then somehow disappeared, which leads to an error on the Contribution insert, as the contact_id field is set to 945938 which doesn't exist - and so giving me the foreign key constraint

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: CiviEvent deleting contact after creation
October 22, 2013, 02:49:40 pm

all that db query code is being run under a database transaction. if there is a fatal error / exit, all of it gets rolled back and hence the contact which u saw with an id disappears into the ether

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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: CiviEvent deleting contact after creation
October 22, 2013, 05:35:19 pm
When we have lost information due to transaction rollbacks it has often turned out to be the cmsuser create function that failed. I think in 4.4 I have patched the contribution form such that the CMS User fn cannot trigger a rollback.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

bpmccain

  • I post frequently
  • ***
  • Posts: 255
  • Karma: 5
  • CiviCRM version: 4.1
  • CMS version: Drupal 7.12
  • MySQL version: 5.2
  • PHP version: 5.2
Re: CiviEvent deleting contact after creation
October 22, 2013, 07:31:36 pm
Thanks, that's helpful. Is there a way to see all of the queries in the database transaction together so that I can figure out what is going on?

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: CiviEvent deleting contact after creation
October 22, 2013, 08:09:45 pm

i would enable mysql query logging and see the queries it logs (and where it fails). alternatively u can ask civi to dump all queries (check civicrm.settings.php)

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

bpmccain

  • I post frequently
  • ***
  • Posts: 255
  • Karma: 5
  • CiviCRM version: 4.1
  • CMS version: Drupal 7.12
  • MySQL version: 5.2
  • PHP version: 5.2
Re: CiviEvent deleting contact after creation
October 23, 2013, 06:27:55 pm
I've been looking at that, and where it fails is with the following query:

Code: [Select]
INSERT INTO civicrm_address (location_type_id , is_billing , street_address , city , state_province_id , postal_code , country_id , name ) VALUES ( 5 ,  1 , 'Steet Address' , 'City' ,  1103 , 'A1A1A1' ,  1039 , 'Name' )
which doesn't make any sense to me as there is no contact_id. I have logging enabled and this causes a constraint violation, as altered contact in the logs cannot be undefined as it is in the above statement.

Backtrace is shown at the bottom - this one has me at a loss. I've dug around in CRM_Core_BAO_Address and there is no contact id present when it tries to create the address. I know it was present, as this was a query run by the same ID according to my log just before hand:

Code: [Select]
UPDATE civicrm_contact SET  email_greeting_custom = NULL, email_greeting_display = 'Dear Mary', postal_greeting_custom = NULL, postal_greeting_display = 'Dear Mary', addressee_custom = NULL, addressee_display = 'Mary', WHERE id = 946030            


Code: [Select]
$backTrace =
#0 /persistent/html/sites/all/modules/civicrm/CRM/Core/Error.php(196): CRM_Core_Error::backtrace("backTrace", TRUE)
#1 [internal function](): CRM_Core_Error::handle(Object(DB_Error))
#2 /persistent/html/sites/all/modules/civicrm/packages/PEAR.php(931): call_user_func((Array:2), Object(DB_Error))
#3 /persistent/html/sites/all/modules/civicrm/packages/DB.php(969): PEAR_Error->PEAR_Error("DB Error: constraint violation", -3, 16, (Array:2), "INSERT INTO civicrm_address (location_type_id , is_billing , street_address ,...")
#4 /persistent/html/sites/all/modules/civicrm/packages/PEAR.php(564): DB_Error->DB_Error(-3, 16, (Array:2), "INSERT INTO civicrm_address (location_type_id , is_billing , street_address ,...")
#5 /persistent/html/sites/all/modules/civicrm/packages/DB/common.php(1905): PEAR->raiseError(NULL, -3, NULL, NULL, "INSERT INTO civicrm_address (location_type_id , is_billing , street_address ,...", "DB_Error", TRUE)
#6 /persistent/html/sites/all/modules/civicrm/packages/DB/mysql.php(898): DB_common->raiseError(-3, NULL, NULL, NULL, "1048 ** Column 'altered_contact' cannot be null")
#7 /persistent/html/sites/all/modules/civicrm/packages/DB/mysql.php(327): DB_mysql->mysqlRaiseError()
#8 /persistent/html/sites/all/modules/civicrm/packages/DB/common.php(1216): DB_mysql->simpleQuery("INSERT INTO civicrm_address (location_type_id , is_billing , street_address ,...")
#9 /persistent/html/sites/all/modules/civicrm/packages/DB/DataObject.php(2436): DB_common->query("INSERT INTO civicrm_address (location_type_id , is_billing , street_address ,...")
#10 /persistent/html/sites/all/modules/civicrm/packages/DB/DataObject.php(1055): DB_DataObject->_query("INSERT INTO civicrm_address (location_type_id , is_billing , street_address ,...")
#11 /persistent/html/sites/all/modules/civicrm/CRM/Core/DAO.php(287): DB_DataObject->insert()
#12 /persistent/html/sites/all/modules/civicrm/CRM/Core/BAO/Address.php(164): CRM_Core_DAO->save()
#13 /persistent/html/sites/all/modules/civicrm/CRM/Contribute/BAO/Contribution.php(1217): CRM_Core_BAO_Address::add((Array:8), FALSE)
#14 /persistent/html/sites/all/modules/civicrm/CRM/Event/Form/Registration/Confirm.php(964): CRM_Contribute_BAO_Contribution::createAddress((Array:64), 5)
#15 /persistent/html/sites/all/modules/civicrm/CRM/Event/Form/Registration/Confirm.php(661): CRM_Event_Form_Registration_Confirm::processContribution(Object(CRM_Event_Form_Registration_Confirm), (Array:64), (Array:63), 946030, FALSE, FALSE)
#16 /persistent/html/sites/all/modules/civicrm/CRM/Core/Form.php(246): CRM_Event_Form_Registration_Confirm->postProcess()
#17 /persistent/html/sites/all/modules/civicrm/CRM/Core/StateMachine.php(160): CRM_Core_Form->mainProcess()
#18 /persistent/html/sites/all/modules/civicrm/CRM/Core/QuickForm/Action/Next.php(60): CRM_Core_StateMachine->perform(Object(CRM_Event_Form_Registration_Confirm), "next", "Next")
#19 /persistent/html/sites/all/modules/civicrm/packages/HTML/QuickForm/Controller.php(203): CRM_Core_QuickForm_Action_Next->perform(Object(CRM_Event_Form_Registration_Confirm), "next")
#20 /persistent/html/sites/all/modules/civicrm/packages/HTML/QuickForm/Page.php(103): HTML_QuickForm_Controller->handle(Object(CRM_Event_Form_Registration_Confirm), "next")
#21 /persistent/html/sites/all/modules/civicrm/CRM/Core/Controller.php(316): HTML_QuickForm_Page->handle("next")
#22 /persistent/html/sites/all/modules/civicrm/CRM/Core/Invoke.php(295): CRM_Core_Controller->run((Array:3), NULL)
#23 /persistent/html/sites/all/modules/civicrm/CRM/Core/Invoke.php(70): CRM_Core_Invoke::runItem((Array:15))
#24 /persistent/html/sites/all/modules/civicrm/CRM/Core/Invoke.php(52): CRM_Core_Invoke::_invoke((Array:3))
#25 /persistent/html/sites/all/modules/civicrm/drupal/civicrm.module(436): CRM_Core_Invoke::invoke((Array:3))
#26 [internal function](): civicrm_invoke("event", "register")
#27 /persistent/html/includes/menu.inc(517): call_user_func_array("civicrm_invoke", (Array:2))
#28 /persistent/html/index.php(21): menu_execute_active_handler()
 #29 {main}

normanr

  • I’m new here
  • *
  • Posts: 11
  • Karma: 1
  • CiviCRM version: 3.3.5
  • CMS version: 6
  • MySQL version: 5.1.3.6
  • PHP version: 5.3.0
Re: CiviEvent deleting contact after creation
May 15, 2014, 06:31:48 am
Have had similar issue. Participant tries to register for an event and saves but participant/contact does not appear to be written away - unless he is hiding in Bermuda Triangle.
The cms company looking after the website did a Joomla upgrade earlier and all phone entries in civi bomb out. here is part of backtrace
Error("DB Error: unknown error", -1, 16, (Array:2), "INSERT INTO civicrm_phone (contact_id , location_type_id , is_primary , is_bi...")
Any ideas??

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviEvent (Moderator: Yashodha Chaku) »
  • CiviEvent deleting contact after creation

This forum was archived on 2017-11-26.