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

Undefined index notice due to disabled memberships in CRM_Member_BAO_Membership::updateAllMembershipStatus()

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Trivial
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.4.1
    • Fix Version/s: 4.4.3
    • Component/s: CiviMember
    • Labels:
      None

      Description

      In file /CRM/Member/BAO/Membership.php, Undefined Index notices are being fired when the Update Membership Statuses scheduled job is run when there are memberships with disabled membership types.

      In the updateAllMembershipStatus() function, the following call returns a list of only enabled (is_active) membership types:
      $allTypes = CRM_Member_PseudoConstant::membershipType();

      The following query returns a list of memberships that include both enabled and disabled membership types:
      $query = "
      SELECT civicrm_membership.id as membership_id,
      civicrm_membership.is_override as is_override,
      civicrm_membership.membership_type_id as membership_type_id,
      civicrm_membership.status_id as status_id,
      civicrm_membership.join_date as join_date,
      civicrm_membership.start_date as start_date,
      civicrm_membership.end_date as end_date,
      civicrm_membership.source as source,
      civicrm_contact.id as contact_id,
      civicrm_contact.is_deceased as is_deceased,
      civicrm_membership.owner_membership_id as owner_membership_id,
      civicrm_membership.contribution_recur_id as recur_id
      FROM civicrm_membership
      INNER JOIN civicrm_contact ON ( civicrm_membership.contact_id = civicrm_contact.id )
      WHERE civicrm_membership.is_test = 0";

      When the following call tries to access $allTypes[$dao->membership_type_id] for the disabled memberships, it throws an "Undefined Index" notice.
      // Put common parameters into array for easy access
      $memberParams = array(
      'id' => $dao->membership_id,
      'status_id' => $dao->status_id,
      'contact_id' => $dao->contact_id,
      'membership_type_id' => $dao->membership_type_id,
      'membership_type' => $allTypes[$dao->membership_type_id],
      'join_date' => $dao->join_date,
      'start_date' => $dao->start_date,
      'end_date' => $dao->end_date,
      'source' => $dao->source,
      'skipStatusCal' => TRUE,
      'skipRecentView' => TRUE,
      );

      Adding an additional INNER JOIN on the civicrm_membership_type table seems to stop these notices by excluding memberships with disabled membership types from the result set.
      INNER JOIN civicrm_membership_type ON ( civicrm_membership.membership_type_id = civicrm_membership_type.id AND civicrm_membership_type.is_active = 1)

      New query:
      $query = "
      SELECT civicrm_membership.id as membership_id,
      civicrm_membership.is_override as is_override,
      civicrm_membership.membership_type_id as membership_type_id,
      civicrm_membership.status_id as status_id,
      civicrm_membership.join_date as join_date,
      civicrm_membership.start_date as start_date,
      civicrm_membership.end_date as end_date,
      civicrm_membership.source as source,
      civicrm_contact.id as contact_id,
      civicrm_contact.is_deceased as is_deceased,
      civicrm_membership.owner_membership_id as owner_membership_id,
      civicrm_membership.contribution_recur_id as recur_id
      FROM civicrm_membership
      INNER JOIN civicrm_contact ON ( civicrm_membership.contact_id = civicrm_contact.id )
      INNER JOIN civicrm_membership_type ON ( civicrm_membership.membership_type_id = civicrm_membership_type.id AND civicrm_membership_type.is_active = 1)
      WHERE civicrm_membership.is_test = 0";

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              hbergin Helen Bergin
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: