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

custom_field options weighting breaks array keying

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Major
    • Resolution: Fixed/Completed
    • Affects Version/s: 3.4.1
    • Fix Version/s: 3.4.2
    • Component/s: None
    • Labels:
      None

      Description

      The current implementation of custom_field_create attempts to order option_values by weight when creating a new custom_field. However, it does this destructively and if multiple options have the same weight, the result is significant data loss.

      e.g. the foreach loop responsible can be found on line 91-95 of api/v3/CustomField.php. If the following data is passed into the loop:

      array(
      0 => array(
      'name' => 'Option 1'
      'weight' => 0
      ...
      ),

      1 => array(
      'name' => 'Option 2'
      'weight' => 0
      ...
      ),

      2 => array(
      'name' => 'Option 3'
      'weight' => 0
      ...
      )
      )

      The following item is returned:

      array(
      0 => array(
      'name' => 'Option 3'
      'weight' => 0
      ...
      )
      )

      Resulting in the loss of two items.

      Given that the API permits the creation of non-weighted option_values, this foreach should be removed. The weighted order of option_values should then be weighting determined on retrieval (non destructive) rather than on create (resulting in data loss).

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: