Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-14501

Inconsistent custom field behaviour under some circumstances

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Trivial
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.4.5
    • Fix Version/s: 4.4.6
    • Component/s: None
    • Labels:
      None

      Description

      I have 2 sites reporting erratic custom field behaviour & have identified one possible cause. The reported behaviours are
      1) custom fields sometimes not showing in Search Builder
      2) custom tokens sometimes not rendering

      In both cases these problems come & go and are hard to replicate. I did however, find that forcing the contact::exportable fields to generate the cache for that function fixed the problem (until next time)

      ie. commenting out
      $fields = CRM_Core_BAO_Cache::getItem('contact fields', $cacheKeyString);

      So that seems a pretty good clue that the problem is in the caching of exportable contact fields. When I look at the cache there are 3 entries (variations of the cache key - one, inexplicably, does not have any custom fields - even though the variation is on the $export var - which is a formatting variable).

      I have been through the code pretty carefully & I think the problem is because both these sites have less permissioned users access the site from time to time. If that cache key was generated while a less permissioned user were logged in the fields are generated with $checkPermissions enabled But that is not reflected in the cachestring.

      Note that CRM_Core_BAO_CustomField::getFieldsForImport does reflect the permissions in it's cache string.

      I'm not sure that things are 'being done in the right place' - ie the permissioning seems to be 'too deep'. However, given that that altering that as a bug fix seems too much I'm thinking it is simply a case of making the cachestring more complex - the easiest thing seems to be to append the contact_id of the person doing the search to the string & apart from adding quite a few entries to the cache I'm not sure there is a downside.

      The alternative would be to add this to the exportable fields function (as per the function it calls). Note sure if that would be better or worse from a performance point of view - probably much of a muchness.

      $cgTable = CRM_Core_DAO_CustomGroup::getTableName();

      // also get the permission stuff here
      if ($checkPermission) {
      $permissionClause = CRM_Core_Permission::customGroupClause(CRM_Core_Permission::VIEW,
      "{$cgTable}."
      );
      }
      else

      { $permissionClause = '(1)'; }

      // lets md5 permission clause and take first 8 characters
      $cacheKey .= substr(md5($permissionClause), 0, 8);

        Attachments

          Activity

            People

            • Assignee:
              eileen Eileen McNaughton
              Reporter:
              eileen Eileen McNaughton
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: