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 Drupal Modules (Moderator: Donald Lobo) »
  • Having CiviMember Roles Sync only act on Member records, skip Organization ones
Pages: [1]

Author Topic: Having CiviMember Roles Sync only act on Member records, skip Organization ones  (Read 2047 times)

mdlueck

  • Ask me questions
  • ****
  • Posts: 382
  • Karma: 4
  • CiviCRM version: 4.7.24
  • CMS version: Drupal 6.x
  • MySQL version: 5.5.54
  • PHP version: 5.3.10
Having CiviMember Roles Sync only act on Member records, skip Organization ones
April 11, 2011, 06:53:41 am
We are using CiviMember Roles Sync to correctly establish Drupal group perms for Member Drupal user accounts.

We have another portion of contacts in CiviCRM that are Organization records, not site members. Thus no Drupal ID exists for these contacts.

We are running into the following error while trying to update an Organization record:

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

    [code] => -3
    [message] => DB Error: constraint violation
    [mode] => 16
    [debug_info] => INSERT INTO civicrm_subscription_history (date , method , status ) VALUES ( 20110411 , 'Admin' , 'Added' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`cir_civicrm/civicrm_subscription_history`, CONSTRAINT `FK_civicrm_subscription_history_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)]
    [type] => DB_Error
    [user_info] => INSERT INTO civicrm_subscription_history (date , method , status ) VALUES ( 20110411 , 'Admin' , 'Added' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`cir_civicrm/civicrm_subscription_history`, CONSTRAINT `FK_civicrm_subscription_history_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_subscription_history (date , method , status ) VALUES ( 20110411 , 'Admin' , 'Added' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`cir_civicrm/civicrm_subscription_history`, CONSTRAINT `FK_civicrm_subscription_history_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)]"]
)

Seems that people have encountered such with CiviMember Roles Sync enabled. "Ja, we need it!"

I quickly checked the CiviMember Roles Sync settings, an no where does it specify what type of record to perform the sync upon. So I would guess that it is trying to sync for both Member and Organization records.

Is there some way to stipulate that it must be a "Member" contact in order to qualify for a sync and/or exclude "Organization" records?
--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/

mdlueck

  • Ask me questions
  • ****
  • Posts: 382
  • Karma: 4
  • CiviCRM version: 4.7.24
  • CMS version: Drupal 6.x
  • MySQL version: 5.5.54
  • PHP version: 5.3.10
Re: Having CiviMember Roles Sync only act on Member records, skip Organization ones
April 15, 2011, 02:17:39 pm
Now I am not so sure that CiviMember Roles Sync is to blame. For one thing, I disabled that module and we can still not successfully save an update to an Organization record.

Secondly looking at the table structure, why would this code be trying to only input values to three of the columns in the civicrm_subscription_history table? Namely the (date , method , status ) columns. There are several other column names in that table. What values was the code trying to put into those fields? Or was the code trying to leave them null which causes the error?

I could see that having a null value in a field protected by a FK constraint would not be a good thing indeed. Was Civi really not trying to specify a value for the contact_id and group_id columns?

There were two errors logged for this situation, perhaps including both will be of assistance:

Code: [Select]
Apr 15 09:46:21  [info] $backTrace = /srv/www/sites/orgname.org/www/sites/all/modules/civicrm/CRM/Core/Error.php, backtrace, 205
, handle,
/srv/www/sites/orgname.org/www/sites/all/modules/civicrm/packages/PEAR.php, call_user_func, 931
/srv/www/sites/orgname.org/www/sites/all/modules/civicrm/packages/DB.php, PEAR_Error, 968
/srv/www/sites/orgname.org/www/sites/all/modules/civicrm/packages/PEAR.php, DB_Error, 564
/srv/www/sites/orgname.org/www/sites/all/modules/civicrm/packages/DB/common.php, raiseError, 1903
/srv/www/sites/orgname.org/www/sites/all/modules/civicrm/packages/DB/mysqli.php, raiseError, 928
/srv/www/sites/orgname.org/www/sites/all/modules/civicrm/packages/DB/mysqli.php, mysqliRaiseError, 402
/srv/www/sites/orgname.org/www/sites/all/modules/civicrm/packages/DB/common.php, simpleQuery, 1216
/srv/www/sites/orgname.org/www/sites/all/modules/civicrm/packages/DB/DataObject.php, query, 2421
/srv/www/sites/orgname.org/www/sites/all/modules/civicrm/packages/DB/DataObject.php, _query, 1053
/srv/www/sites/orgname.org/www/sites/all/modules/civicrm/CRM/Core/DAO.php, insert, 281
/srv/www/sites/orgname.org/www/sites/all/modules/civicrm/CRM/Contact/BAO/SubscriptionHistory.php, save, 60
/srv/www/sites/orgname.org/www/sites/all/modules/civicrm/CRM/Contact/BAO/Contact.php, create, 384
/srv/www/sites/orgname.org/www/sites/all/modules/civicrm/CRM/Contact/Form/Contact.php, create, 903
/srv/www/sites/orgname.org/www/sites/all/modules/civicrm/CRM/Core/Form.php, postProcess, 250
/srv/www/sites/orgname.org/www/sites/all/modules/civicrm/CRM/Core/QuickForm/Action/Upload.php, mainProcess, 153
/srv/www/sites/orgname.org/www/sites/all/modules/civicrm/CRM/Core/QuickForm/Action/Upload.php, realPerform, 130
/srv/www/sites/orgname.org/www/sites/all/modules/civicrm/packages/HTML/QuickForm/Controller.php, perform, 203
/srv/www/sites/orgname.org/www/sites/all/modules/civicrm/packages/HTML/QuickForm/Page.php, handle, 103
/srv/www/sites/orgname.org/www/sites/all/modules/civicrm/CRM/Core/Controller.php, handle, 284
/srv/www/sites/orgname.org/www/sites/all/modules/civicrm/CRM/Utils/Wrapper.php, run, 115
/srv/www/sites/orgname.org/www/sites/all/modules/civicrm/CRM/Core/Invoke.php, run, 191
/srv/www/sites/orgname.org/www/sites/all/modules/civicrm/drupal/civicrm.module, invoke, 355
, civicrm_invoke,
/srv/www/sites/orgname.org/www/includes/menu.inc, call_user_func_array, 348
/srv/www/sites/orgname.org/www/index.php, menu_execute_active_handler, 18

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

    [code] => -3
    [message] => DB Error: constraint violation
    [mode] => 16
    [debug_info] => INSERT INTO civicrm_subscription_history (date , method , status ) VALUES ( 20110415 , 'Admin' , 'Added' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`cir_civicrm/civicrm_subscription_history`, CONSTRAINT `FK_civicrm_subscription_history_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)]
    [type] => DB_Error
    [user_info] => INSERT INTO civicrm_subscription_history (date , method , status ) VALUES ( 20110415 , 'Admin' , 'Added' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`cir_civicrm/civicrm_subscription_history`, CONSTRAINT `FK_civicrm_subscription_history_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_subscription_history (date , method , status ) VALUES ( 20110415 , 'Admin' , 'Added' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`cir_civicrm/civicrm_subscription_history`, CONSTRAINT `FK_civicrm_subscription_history_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)]"]
)
--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/

mdlueck

  • Ask me questions
  • ****
  • Posts: 382
  • Karma: 4
  • CiviCRM version: 4.7.24
  • CMS version: Drupal 6.x
  • MySQL version: 5.5.54
  • PHP version: 5.3.10
Re: Having CiviMember Roles Sync only act on Member records, skip Organization ones
April 15, 2011, 02:39:39 pm
Digging a bit further... Why would this code get run while editing / making an update to a organization contact?

In CRM/Contact/BAO/Contact.php
Code: [Select]
        // make a civicrm_subscription_history entry only on contact create (CRM-777)
        if ( ! CRM_Utils_Array::value( 'contact_id', $params ) ) {
            $subscriptionParams = array('contact_id' => $contact->id,
                                        'status' => 'Added',
                                        'method' => 'Admin');
            CRM_Contact_BAO_SubscriptionHistory::create($subscriptionParams);
        }

Per the comment, should only execute at creation? But this is being executed when updating an existing Civi record. Thus confused...
--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/

mdlueck

  • Ask me questions
  • ****
  • Posts: 382
  • Karma: 4
  • CiviCRM version: 4.7.24
  • CMS version: Drupal 6.x
  • MySQL version: 5.5.54
  • PHP version: 5.3.10
Re: Having CiviMember Roles Sync only act on Member records, skip Organization ones
April 15, 2011, 04:21:21 pm
<dlobo>   so the mystery is how/why did the db have contact_sub_type set to people's names
<dlobo>   that was causing our code to do the wrong thing (bug)
<dlobo>   and we were not reporting it nicely
<dlobo>   i'll file an issue and fix for 3.4
<dlobo>   so future folks dont spend forever on this

Thank you lobo for the 1 on 1 assistance with this issue today. Problem solved for us, and he said an update would be forthcoming in the 3.4 release.  ;D
« Last Edit: April 15, 2011, 06:24:23 pm by mdlueck »
--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/

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: Having CiviMember Roles Sync only act on Member records, skip Organization ones
April 15, 2011, 04:28:30 pm

issue here:

http://issues.civicrm.org/jira/browse/CRM-7925

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

mdlueck

  • Ask me questions
  • ****
  • Posts: 382
  • Karma: 4
  • CiviCRM version: 4.7.24
  • CMS version: Drupal 6.x
  • MySQL version: 5.5.54
  • PHP version: 5.3.10
Re: Having CiviMember Roles Sync only act on Member records, skip Organization ones
May 02, 2011, 10:45:10 am
Aaaahhh, our Application Team finally tracked down how this happened!!!

Back in Civi 2.0.7 when they created this organization database type data, then there was an available field named "contact".

In current Civi this has been removed, and Civi ended up mapping the field to contact_sub_type.

They have now mapped the data to "Field Name" \ "Contacts" \ "Addressee"
--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: Having CiviMember Roles Sync only act on Member records, skip Organization ones
September 21, 2011, 04:45:25 pm
Hi Lobo,
I think I've run into the same issue with a civiCRM 3.1 site so I didn't want to post a duplicate issue.

We are updating to civiCRM 3.4.5 and I wonder will the updated version have some way of consolidating or detecting and reporting the duplicate problem rather than throwing the error. I found one this afternoon and I have a feeling that there will be others.

In the case of the one I found today, the user logged into the Drupal site just fine but when they tried to gain access to the civi side of their account, the "already exists" error was thrown with the following details (I've obfuscated the email address):
Code: [Select]
Array
(
    [callback] => Array
        (
            [0] => CRM_Core_Error
            [1] => handle
        )

    [code] => -5
    [message] => DB Error: already exists
    [mode] => 16
    [debug_info] => INSERT INTO civicrm_uf_match (domain_id , uf_id , uf_name , contact_id ) VALUES ( 1 ,  859 , 'email-address@provider.com' ,  983 )  [nativecode=1062 ** Duplicate entry '983-1' for key 3]
    [type] => DB_Error
    [user_info] => INSERT INTO civicrm_uf_match (domain_id , uf_id , uf_name , contact_id ) VALUES ( 1 ,  859 , 'email-address@provider.com' ,  983 )  [nativecode=1062 ** Duplicate entry '983-1' for key 3]
    [to_string] => [db_error: message="DB Error: already exists" code=-5 mode=callback callback=CRM_Core_Error::handle prefix="" info="INSERT INTO civicrm_uf_match (domain_id , uf_id , uf_name , contact_id ) VALUES ( 1 ,  859 , 'email-address@provider.com' ,  983 )  [nativecode=1062 ** Duplicate entry '983-1' for key 3]"]
)
 

As it turned out the member had two Drupal accounts (with two different email addresses) and my guess is that they were both pointing to the same civiCRM contact record. Does that sound about right?

At any rate, I deleted the one that was throwing the errors and asked the member to use the one that works.

I think I will find a number of these duplicates in the system because I get a similar error when I try to synch users to contacts. Is there anyway to run a report so that I can find all the duplicates?

Thanks,
Andrew
My CiviCRM Extension Workshop: https://github.com/awasson

mdlueck

  • Ask me questions
  • ****
  • Posts: 382
  • Karma: 4
  • CiviCRM version: 4.7.24
  • CMS version: Drupal 6.x
  • MySQL version: 5.5.54
  • PHP version: 5.3.10
Re: Having CiviMember Roles Sync only act on Member records, skip Organization ones
September 21, 2011, 06:56:30 pm
@awasson: The issue we were facing was some invalid data somehow got into a Civi DB column. For a Civi capability we are not using.

That bogus data caused the upgrade to bomb.

Fortunately Lobo was able to quickly track down the error, wipe the unused col in the DB, and the upgrade went smoothly.

Definitely not people with multiple ID's in our case.
--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: Having CiviMember Roles Sync only act on Member records, skip Organization ones
September 21, 2011, 07:39:30 pm
@mdlueck: Thanks for clarifying that. I'll start a new thread then.

Cheers,
Andrew
My CiviCRM Extension Workshop: https://github.com/awasson

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Having CiviMember Roles Sync only act on Member records, skip Organization ones

This forum was archived on 2017-11-26.