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) »
  • Discussion (deprecated) »
  • Alpha and Beta Release Testing »
  • 3.1 Release Testing »
  • civicrm_contact_add for subtype worked in beta6, fails in 3.1.1
Pages: [1]

Author Topic: civicrm_contact_add for subtype worked in beta6, fails in 3.1.1  (Read 4932 times)

davej

  • Ask me questions
  • ****
  • Posts: 404
  • Karma: 21
civicrm_contact_add for subtype worked in beta6, fails in 3.1.1
February 02, 2010, 06:07:12 am
Just upgraded a site from 3.1.beta6 to 3.1.1 . A call to civicrm_contact_add that worked previously now fails.

Call:

Code: [Select]
  $orgParams = array(
    'contact_type'      => 'Organization',
    'contact_sub_type'  => 'Care_Provider',
    'organization_name' => $params['orgname'],
    'email'             => $params['email'],
    'custom_15'         => trim($params['firstname'] . ' ' . $params['lastname']),
    'custom_16'          => $params['jobrole'],
  );
  $org = civicrm_contact_add($orgParams);

 Error:

Code: [Select]
Invalid Custom Field Contact Type: Organization or Mismatched SubType: Care_Provider.
Custom fields 15 and 16 are in a custom group specified for Organization -> Care Provider:

Code: [Select]
mysql> select * from civicrm_custom_group where id = 3\G
*************************** 1. row ***************************
                         id: 3
                       name: EOI_SECTION_A_Applying_Service_Provider_Details
                      title: EOI SECTION A: Applying Service Provider Details
                    extends: Organization
   extends_entity_column_id: NULL
extends_entity_column_value: *Care_Provider*
                      style: Inline
           collapse_display: 0
                   help_pre:
                  help_post:
                     weight: 1
                  is_active: 1
                 table_name: civicrm_value_eoi_section_a_applying_service_p_3
                is_multiple: 0
               min_multiple: NULL
               max_multiple: NULL
       collapse_adv_display: 0
                 created_id: 1
               created_date: 2009-12-16 18:13:58

Note: for extends_entity_column_value, I replaced the separator characters with asterisks when pasting the above, as the forum preview chokes on the ASCII 1 characters.

Dave

Shailesh Lende

  • Guest
Re: civicrm_contact_add for subtype worked in beta6, fails in 3.1.1
February 02, 2010, 09:42:08 pm
Hi Dave,
I followed exactly what you told but still fail to replicate.
Actually bellow error
Code: [Select]
Invalid Custom Field Contact Type: Organization or Mismatched SubType: Care_Provider.
is get fired only if Custom Group is not extending subtype 'Care_Provider' or custom fields 'custom_15' or 'custom_16' are not of custom group.

I might be wrong or missing anything.

So Can you please give me exact steps to replicate.

-thanks,
Shailesh

davej

  • Ask me questions
  • ****
  • Posts: 404
  • Karma: 21
Re: civicrm_contact_add for subtype worked in beta6, fails in 3.1.1
February 03, 2010, 07:44:41 am
Hi Shailesh,

I've got a bit further in investigating this. It seems to be an access control issue. The problem is occurring for non-admin users who don't have 'access all custom data' but have ACL Edit perm on the relevant custom group. (I tried adding View perm too, in case Edit no longer includes View, but this didn't help.) Here's an example of what I'm getting for $query in CRM_Core_BAO_CustomField::getFields:

Code: [Select]
SELECT civicrm_custom_field.id, civicrm_custom_field.label,
                            civicrm_custom_group.title,
                            civicrm_custom_field.data_type, civicrm_custom_field.html_type,
                            civicrm_custom_field.options_per_line,
                            civicrm_custom_group.extends, civicrm_custom_field.is_search_range,
                            civicrm_custom_group.extends_entity_column_value,
                            civicrm_custom_group.extends_entity_column_id,
                            civicrm_custom_field.is_view,
                            civicrm_custom_field.option_group_id,
                            civicrm_custom_field.date_format,
                            civicrm_custom_field.time_format,
                            civicrm_custom_group.is_multiple
                     FROM civicrm_custom_field
                     INNER JOIN civicrm_custom_group
                     ON civicrm_custom_field.custom_group_id = civicrm_custom_group.id
                     WHERE ( 1 )  AND civicrm_custom_field.is_active = 1 AND civicrm_custom_group.is_active = 1  AND ( civicrm_custom_group.extends_entity_column_value LIKE '%*Care_Provider*%' OR civicrm_custom_group.extends_entity_column_value IS NULL ) AND   civicrm_custom_group.extends IN ( 'Organization', 'Contact'  )  AND  ( 0 )
                        ORDER BY civicrm_custom_group.weight, civicrm_custom_group.title,
                                 civicrm_custom_field.weight, civicrm_custom_field.label

(Note: ASCII 01 changed to * 'cos it breaks the forum preview.)

The "AND  ( 0 )" comes from $permissionClause. I traced this through CRM_Core_Permission::customGroupClause, CRM_Core_Permission::customGroup, CRM_ACL_API::group to CRM_ACL_BAO_ACL::group, which runs this query:

Code: [Select]
SELECT   a.operation, a.object_id
  FROM   civicrm_acl_cache c, civicrm_acl a
 WHERE   c.acl_id       =  a.id
   AND   a.is_active    =  1
   AND   a.object_table = 'civicrm_custom_group'
   AND   a.id        IN ( 2,3,4,5,6,7,50,51,52,53,54,55,56 )
ORDER BY a.object_id

...which returns nothing, because the civicrm_acl object_table values for these ids are all permission names, like 'access all custom data' - there are entries with object_table = 'civicrm_custom_group' but these have ids 60, 62, 63 & 71:

Code: [Select]
mysql> select * from civicrm_acl where object_table = 'civicrm_custom_group';
+----+---------------------------------+------+------------------+-----------+-----------+----------------------+-----------+-----------+--------+-----------+
| id | name                            | deny | entity_table     | entity_id | operation | object_table         | object_id | acl_table | acl_id | is_active |
+----+---------------------------------+------+------------------+-----------+-----------+----------------------+-----------+-----------+--------+-----------+
| 60 | EOI Section C Custom Group Edit |    0 | civicrm_acl_role |         3 | Edit      | civicrm_custom_group |         2 | NULL      |   NULL |         1 |
| 62 | EOI Section A Custom Group Edit |    0 | civicrm_acl_role |         3 | Edit      | civicrm_custom_group |         3 | NULL      |   NULL |         1 |
| 63 | EOI Section B Custom Group Edit |    0 | civicrm_acl_role |         3 | Edit      | civicrm_custom_group |         4 | NULL      |   NULL |         1 |
| 71 | EOI Section A Custom Group View |    0 | civicrm_acl_role |         3 | View      | civicrm_custom_group |         3 | NULL      |   NULL |         1 |
+----+---------------------------------+------+------------------+-----------+-----------+----------------------+-----------+-----------+--------+-----------+


But civicrm_acl_cache at this point only has acl_ids 2,3,4,5,6,7,50,51,52,53,54,55,56.

Looks as though civicrm_acl_cache is populated by the call to CRM_ACL_BAO_Cache::build earlier in CRM_ACL_BAO_ACL::group. I've verified that the call to CRM_ACL_BAO_ACL::getAllByContact in CRM_ACL_BAO_Cache::build returns results, which all come from the call to getGroupACLRoles in getGroupACLs: ids 2,3,4,5,6,7,50,51,52,53,54,55,56.

That's as far as I've got, hope you'll now be able to replicate.

Thanks,

Dave

Shailesh Lende

  • Guest
Re: civicrm_contact_add for subtype worked in beta6, fails in 3.1.1
February 04, 2010, 05:59:32 am
Hi Dave,

I assign same permissions and configuration.I have also debug all queries as you have mentioned and got same. But still working fine for me.
Still fail to replicate  :(

davej

  • Ask me questions
  • ****
  • Posts: 404
  • Karma: 21
Re: civicrm_contact_add for subtype worked in beta6, fails in 3.1.1
February 04, 2010, 09:11:04 am
Hi Shailesh,

Deepak has been investigating on my server & says he's found the problem & will be able to replicate. :)

Thanks,

Dave J

davej

  • Ask me questions
  • ****
  • Posts: 404
  • Karma: 21
Re: civicrm_contact_add for subtype worked in beta6, fails in 3.1.1
February 05, 2010, 03:17:50 am
See http://issues.civicrm.org/jira/browse/CRM-5781 . Fixed and working here - thanks to Deepak.

Dave J

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Discussion (deprecated) »
  • Alpha and Beta Release Testing »
  • 3.1 Release Testing »
  • civicrm_contact_add for subtype worked in beta6, fails in 3.1.1

This forum was archived on 2017-11-26.