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 Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Errors on profile search form with civicrm_cache, undefined custom data type
Pages: [1]

Author Topic: Errors on profile search form with civicrm_cache, undefined custom data type  (Read 2547 times)

davej

  • Ask me questions
  • ****
  • Posts: 404
  • Karma: 21
Errors on profile search form with civicrm_cache, undefined custom data type
May 05, 2009, 10:36:03 am
Hi,

I'm getting three occurrences of the following error on profile search forms, i.e. civicrm/profile?reset=1&gid=N:

Code: [Select]
"warning: Invalid argument supplied for foreach() in <snip>/sites/all/modules/civicrm/CRM/Core/BAO/CustomField.php on line 451."
All of the searchable custom fields are missing from the search form. On profiles where there are no searchable custom fields, this results in the following error too:

Code: [Select]
"No fields in this Profile have been configured as searchable. Ask the site administrator to check the Profile setup."
This is on a site that has been recently upgraded from Civi 1.8 to 2.2.2, apparently successfully. I haven't so far been able to replicate the issue on demo. The profiles have a mix of Contact and Organization fields.

I put a backtrace in CRM/Core/BAO/CustomField.php getFieldsForImport, conditional on !is_array($fields), just before the foreach that triggers the above warning. The backtrace is different in the three occurrences:

First, with some additional debug info (the customised CRM/Core/BAO/CustomField.php is just the original plus debug statements):
Code: [Select]
CRM/Core/BAO/CustomField.php getFieldsForImport: contactType is null.
CRM/Core/BAO/CustomField.php getFields: customDataType is null.
CRM/Core/BAO/CustomField.php getFieldsForImport: getFields returned non-array, backtrace...
backTrace
<snip>/sites/mysite.org/civicrm_custom_php/CRM/Core/BAO/CustomField.php, backtrace, 468
<snip>/sites/all/modules/civicrm/CRM/Core/BAO/UFGroup.php, getFieldsForImport, 337
<snip>/sites/all/modules/civicrm/CRM/Core/BAO/UFGroup.php, getFields, 194
<snip>/sites/all/modules/civicrm/CRM/Profile/Page/Listings.php, getListingFields, 117
<snip>/sites/all/modules/civicrm/CRM/Profile/Page/Listings.php, preProcess, 210
<snip>/sites/all/modules/civicrm/CRM/Core/Invoke.php, run, 314
, profile,
<snip>/sites/all/modules/civicrm/CRM/Core/Invoke.php, call_user_func, 172
<snip>/sites/all/modules/civicrm/drupal/civicrm.module, invoke, 339
, civicrm_invoke,
<snip>/includes/menu.inc, call_user_func_array, 348
<snip>/index.php, menu_execute_active_handler, 18

Second:
Code: [Select]
CRM/Core/BAO/CustomField.php getFieldsForImport: contactType is null.
CRM/Core/BAO/CustomField.php getFields: customDataType is null.
CRM/Core/BAO/CustomField.php getFieldsForImport: getFields returned non-array, backtrace...
backTrace
<snip>/sites/mysite.org/civicrm_custom_php/CRM/Core/BAO/CustomField.php, backtrace, 468
<snip>/sites/all/modules/civicrm/CRM/Profile/Page/Listings.php, getFieldsForImport, 119
<snip>/sites/all/modules/civicrm/CRM/Profile/Page/Listings.php, preProcess, 210
<snip>/sites/all/modules/civicrm/CRM/Core/Invoke.php, run, 314
, profile,
<snip>/sites/all/modules/civicrm/CRM/Core/Invoke.php, call_user_func, 172
<snip>/sites/all/modules/civicrm/drupal/civicrm.module, invoke, 339
, civicrm_invoke,
<snip>/includes/menu.inc, call_user_func_array, 348
<snip>/index.php, menu_execute_active_handler, 18

Third:
Code: [Select]
CRM/Core/BAO/CustomField.php getFieldsForImport: contactType is null.
CRM/Core/BAO/CustomField.php getFields: customDataType is null.
CRM/Core/BAO/CustomField.php getFieldsForImport: getFields returned non-array, backtrace...
backTrace
<snip>/sites/mysite.org/civicrm_custom_php/CRM/Core/BAO/CustomField.php, backtrace, 468
<snip>/sites/all/modules/civicrm/CRM/Core/BAO/UFGroup.php, getFieldsForImport, 337
<snip>/sites/all/modules/civicrm/CRM/Core/BAO/UFGroup.php, getFields, 194
<snip>/sites/all/modules/civicrm/CRM/Profile/Form.php, getListingFields, 164
<snip>/sites/all/modules/civicrm/CRM/Profile/Form/Search.php, preProcess, 62
<snip>/sites/all/modules/civicrm/CRM/Core/Form.php, preProcess, 312
<snip>/sites/all/modules/civicrm/CRM/Core/QuickForm/Action/Display.php, buildForm, 98
<snip>/sites/all/modules/civicrm/packages/HTML/QuickForm/Controller.php, perform, 203
<snip>/sites/all/modules/civicrm/packages/HTML/QuickForm/Page.php, handle, 103
<snip>/sites/all/modules/civicrm/CRM/Core/Controller.php, handle, 245
<snip>/sites/all/modules/civicrm/CRM/Profile/Page/Listings.php, run, 281
<snip>/sites/all/modules/civicrm/CRM/Core/Invoke.php, run, 314
, profile,
<snip>/sites/all/modules/civicrm/CRM/Core/Invoke.php, call_user_func, 172
<snip>/sites/all/modules/civicrm/drupal/civicrm.module, invoke, 339
, civicrm_invoke,
<snip>/includes/menu.inc, call_user_func_array, 348
<snip>/index.php, menu_execute_active_handler, 18

I noticed that CRM/Core/BAO/CustomField.php getFields tries to retrieve data from CRM_Core_BAO_Cache. I tried removing all entries from table civicrm_cache and hey presto, the search forms worked - once. The errors returned as soon as the cache was repopulated. Examining civicrm_cache, I found that one row was missing a contact type - see id 98 below:

Code: [Select]
mysql> SELECT id, group_name, path, component_id, created_date, expired_date FROM civicrm_cache;
+-----+----------------+----------------------------------------------------------+--------------+--------------+--------------+
| id  | group_name     | path                                                     | component_id | created_date | expired_date |
+-----+----------------+----------------------------------------------------------+--------------+--------------+--------------+
|  91 | contact fields | custom importableFields Individual_0_0_0_0__0_86c19bb9   |         NULL | NULL         | NULL         |
|  92 | contact fields | custom importableFields Household_0_0_0_0__0_86c19bb9    |         NULL | NULL         | NULL         |
|  93 | contact fields | custom importableFields Organization_0_0_0_0__0_86c19bb9 |         NULL | NULL         | NULL         |
|  94 | contact fields | importableFields All                                     |         NULL | NULL         | NULL         |
|  95 | contact fields | importableFields Individual                              |         NULL | NULL         | NULL         |
|  96 | contact fields | custom importableFields Participant_0_0_0_0__0_86c19bb9  |         NULL | NULL         | NULL         |
|  97 | contact fields | custom importableFields Activity_0_0_0_0__0_86c19bb9     |         NULL | NULL         | NULL         |
|  98 | contact fields | custom importableFields _0_0_0_0__0_86c19bb9             |         NULL | NULL         | NULL         |
|  99 | contact fields | custom importableFields Contribution_0_0_0_0__0_86c19bb9 |         NULL | NULL         | NULL         |
| 100 | contact fields | custom importableFields Membership_0_0_0_0__0_86c19bb9   |         NULL | NULL         | NULL         |
+-----+----------------+----------------------------------------------------------+--------------+--------------+--------------+

Deleting just the spurious row was sufficient to get the form working, once.

I've found what looks to me like a coding error that seems relevant:
  • CRM/Core/BAO/UFGroup.php getListingFields line 191 calls self::getFields with no ninth argument ($ctype), so in getFields, $ctype defaults to null.
  • CRM/Core/BAO/UFGroup.php getFields line 337 calls CRM_Core_BAO_CustomField::getFieldsForImport( $ctype ). $ctype is not modified prior to this, so is still null.
  • CRM/Core/BAO/CustomField.php getFieldsForImport gets passed first parameter ($contactType) = null, which means the default value of 'Individual' is NOT applied (see http://www.php.net/manual/en/functions.arguments.php Example #3 and comment #62803) and so $contactType takes value null, which it passes to self::getFields.
  • CRM/Core/BAO/CustomField.php getFields gets passed first parameter ($customDataType) = null, which means the default value of 'Individual' is NOT applied and so $customDataType takes value null, which becomes the first component of $cacheKey, which is passed to CRM_Core_BAO_Cache::setItem. This fits with the missing contact type seen in civicrm_cache id 98, above.

That's as far as I've got. I'm guessing the intention of the code is that contact type should default to 'Individual' here, though I'm not sure how this case arises because the profiles in question have no Individual fields, just Contact and Organization. In the list of profiles at civicrm/admin/uf/group, one of the profiles has type "Organization,Contact", the others just "Organization".

Drupal 6.10
CiviCRM 2.2.2
PHP 5.2.9
MySQL 5.0.45

Dave J

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Errors on profile search form with civicrm_cache, undefined custom data type
May 05, 2009, 02:01:49 pm
Dave J:

Can you investigate a bit on how you got this record:

Quote
|  98 | contact fields | custom importableFields _0_0_0_0__0_86c19bb9             |         NULL | NULL         | NULL         |

Also after clearing civicrm_cache table, is civicrm_cache table populated with same record ?

thanx,

Kurund
Found this reply helpful? Support CiviCRM

davej

  • Ask me questions
  • ****
  • Posts: 404
  • Karma: 21
Re: Errors on profile search form with civicrm_cache, undefined custom data type
May 06, 2009, 05:04:27 am
Hi Kurund,

Thanks for the reply.

Quote from: Kurund Jalmi on May 05, 2009, 02:01:49 pm
Can you investigate a bit on how you got this record:

Quote
|  98 | contact fields | custom importableFields _0_0_0_0__0_86c19bb9             |         NULL | NULL         | NULL         |

I believe it's as described above:

Quote from: davej on May 05, 2009, 10:36:03 am
I've found what looks to me like a coding error that seems relevant:
  • CRM/Core/BAO/UFGroup.php getListingFields line 191 calls self::getFields with no ninth argument ($ctype), so in getFields, $ctype defaults to null.
  • CRM/Core/BAO/UFGroup.php getFields line 337 calls CRM_Core_BAO_CustomField::getFieldsForImport( $ctype ). $ctype is not modified prior to this, so is still null.
  • CRM/Core/BAO/CustomField.php getFieldsForImport gets passed first parameter ($contactType) = null, which means the default value of 'Individual' is NOT applied (see http://www.php.net/manual/en/functions.arguments.php Example #3 and comment #62803) and so $contactType takes value null, which it passes to self::getFields.
  • CRM/Core/BAO/CustomField.php getFields gets passed first parameter ($customDataType) = null, which means the default value of 'Individual' is NOT applied and so $customDataType takes value null, which becomes the first component of $cacheKey, which is passed to CRM_Core_BAO_Cache::setItem. This fits with the missing contact type seen in civicrm_cache id 98, above.

Debug statements seem to confirm this: in CRM/Core/BAO/CustomField.php getFields, $customDataType is null and $cacheKey is '_0_0_0_0__0_86c19bb9'. The call to:
Code: [Select]
CRM_Core_BAO_Cache::setItem( $fields,
                                             'contact fields',
                                             "custom importableFields $cacheKey" );
near the end of CRM/Core/BAO/CustomField.php getFields therefore creates a cache entry with path "custom importableFields _0_0_0_0__0_86c19bb9", as observed.

This fits with the First and Third backtraces above. To clarify, these three backtraces were all triggered on a single load of the profile search form, by an if statement I added to CRM/Core/BAO/CustomField.php getFieldsForImport that checks for a non-array being returned by
Code: [Select]
$fields =& self::getFields($contactType, $showAll);. Which I checked for to catch the "Invalid argument supplied for foreach()" warning there.

In the second backtrace, the call to CRM/Core/BAO/CustomField.php getFieldsForImport is from CRM/Profile/Page/Listings.php line 119, again passing null for $contactType.

Quote from: Kurund Jalmi on May 05, 2009, 02:01:49 pm
Also after clearing civicrm_cache table, is civicrm_cache table populated with same record ?
Yes, consistently.

If I add this to the start of CRM/Core/BAO/CustomField.php getFields:
Code: [Select]
$customDataType = ( is_null($customDataType) ? 'Organization' : $customDataType);then the forms consistently work. This seems ad hoc though. If I change 'Organization' to 'Individual' in the above line (emptying civicrm_cache after making code changes), then the forms consistently fail to work (all custom fields missing), on both initial load when cache empty and subsequent loads.

Thanks,

Dave J

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: Errors on profile search form with civicrm_cache, undefined custom data type
May 06, 2009, 11:29:56 am

hey davej:

can u get in touch with us on IRC. we'll need ssh access to your box to help track and fix the issue

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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Errors on profile search form with civicrm_cache, undefined custom data type

This forum was archived on 2017-11-26.