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

Wrong line item updated when editing a contribution - database corruption

    Details

    • Type: Bug
    • Status: Reopened
    • Priority: Important
    • Resolution: Unresolved
    • Affects Version/s: 4.7.24, 4.7.28, 4.7.31
    • Fix Version/s: None
    • Component/s: None
    • Labels:
    • Versioning Impact:
      Patch (backwards-compatible bug fixes)
    • Documentation Required?:
      None
    • Funding Source:
      Needs Funding
    • Verified?:
      No

      Description

      I have some strange cases where a line item is wrongly updated instead of another giving 2 line items on the contribution instead of one.

      The contribution is attached to a membership so the entity_table is "civicrm_membership" in civicrm_line_items.

      In this context, CiviCRM seems to consider it's a special case by setting "isRelatedId = TRUE" :

      https://github.com/civicrm/civicrm-core/blob/master/CRM/Contribute/BAO/Contribution.php#L3173 :

       

      if (CRM_Utils_Array::value('contribution_mode', $params) == 'membership') {
         $isRelatedId = TRUE;
       }

       

       

      After that, when retrieving the line_items, in CRM_Price_BAO_LineItem::getLineItems, the query condition match the id against the contribution_id instead of membership_id which leads to wrongly updated data.

      https://github.com/civicrm/civicrm-core/blob/master/CRM/Price/BAO/LineItem.php#L225 :

      $condition = "li.entity_id = %2.id AND li.entity_table = 'civicrm_%2'";
      if ($relatedEntity) {
        $condition = "li.contribution_id = %2.id ";
      }

       

      Not sure how to fix it but here a way we should be able to reproduce it :

      • start from a completely empty database (ids must be as mentioned below)
      • create a contribution (id 1)
      • create a membership (id 1) with a contribution (id 2)
      • edit the contribution #2 and submit -> the line item from the contribution #1 should be on the contribution #2

       

       

        Attachments

          Activity

            People

            • Assignee:
              monish.deb Monish Deb
              Reporter:
              samuelsov Samuel Vanhove
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated: