CRM-9910 pre/post hooks not called when pending contribution updates membership

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Major
    • Resolution: Fixed/Completed
    • Affects Version/s: 3.4.8, 4.1.1
    • Fix Version/s: 4.2.0
    • Component/s: CiviMember
    • Labels:
      None

      Description

      I ran into an issue where the pre/post hooks were not getting called for memberships during renewal. I traced the issue to how we handle the membership update tied to a pending/pay later contribution.

      If we use pending/pay later with a new membership, the membership is constructed (hooks are called) and then the start/end dates are assigned when the contribution status is changed from pending to completed. The same thing happens with renewal, but we don't actually save the membership record when the renewal takes place – we just store values in the membership_log table and then update when the contribution is updated – and consequently, pre/post are not called. But regardless, we really need to be able to access at the contribution update point as that is where the membership is getting saved.

      See attached patch. The weakness of this patch is that the pre hook passes the formattedParams, which is not the full membership record. Not sure if we want to handle that differently.

        Attachments

          Activity

          [CRM-9910] pre/post hooks not called when pending contribution updates membership
          David Greenberg added a comment -

          Brian - Probably obvious to you but ... the reason we don't update the membership record at renewal time in the pay later flow is that the payment may never actually come in.

          Brian Shaughnessy added a comment -

          right – which is why I think the attached patch is sufficient for addressing the existing gap.
          it's a bit confusing – most would think that at the time a renewal takes place the object is being updated, but it does make sense that for renewals via pay later that doesn't actually happen until payment is received.

          Donald A. Lobo added a comment -

          thanx for the patch.

          the one thing which i did not incorporate from the patch was retrieving the membership object before calling the hook. We typically dont do that and for most sites its a wasted query (since they dont implement the hook)

          lobo

            People

            • Assignee:
              Donald A. Lobo
              Reporter:
              Brian Shaughnessy

              Dates

              • Created:
                Updated:
                Resolved: