CRM-17557 remove deprecated concepts (focus on component, membership_payment vs line_...
authoreileen <emcnaughton@wikimedia.org>
Thu, 12 Nov 2015 19:14:07 +0000 (11:14 -0800)
committereileen <emcnaughton@wikimedia.org>
Thu, 12 Nov 2015 23:16:57 +0000 (15:16 -0800)
CRM/Contribute/BAO/Contribution.php

index 6a9dc16f7e4bd362e8a0edf3e444d97c554f49f4..d4be3fcd74e6d35fd72ad247bbcfabf5c3a32e11 100644 (file)
@@ -2220,47 +2220,46 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
       }
     }
 
-    if ($this->_component == 'contribute') {
-      // retrieve the other optional objects first so
-      // stuff down the line can use this info and do things
-      // CRM-6056
-      //in any case get the memberships associated with the contribution
-      //because we now support multiple memberships w/ price set
-      // see if there are any other memberships to be considered for same contribution.
-      $query = "
-            SELECT membership_id
-            FROM   civicrm_membership_payment
-WHERE  contribution_id = %1 ";
-      $params = array(1 => array($this->id, 'Integer'));
-
-      $dao = CRM_Core_DAO::executeQuery($query, $params);
-      while ($dao->fetch()) {
-        if ($dao->membership_id) {
-          if (!is_array($ids['membership'])) {
-            $ids['membership'] = array();
-          }
-          $ids['membership'][] = $dao->membership_id;
+    // retrieve the other optional objects first so
+    // stuff down the line can use this info and do things
+    // CRM-6056
+    //in any case get the memberships associated with the contribution
+    //because we now support multiple memberships w/ price set
+    // see if there are any other memberships to be considered for same contribution.
+    $query = "
+          SELECT entity_id as membership_id
+          FROM   civicrm_line_item
+WHERE  contribution_id = %1 AND entity_table = 'civicrm_membership'";
+    $params = array(1 => array($this->id, 'Integer'));
+
+    $dao = CRM_Core_DAO::executeQuery($query, $params);
+    while ($dao->fetch()) {
+      if ($dao->membership_id) {
+        if (!is_array($ids['membership'])) {
+          $ids['membership'] = array();
         }
+        $ids['membership'][] = $dao->membership_id;
       }
+    }
 
-      if (array_key_exists('membership', $ids) && is_array($ids['membership'])) {
-        foreach ($ids['membership'] as $id) {
-          if (!empty($id)) {
-            $membership = new CRM_Member_BAO_Membership();
-            $membership->id = $id;
-            if (!$membership->find(TRUE)) {
-              throw new Exception("Could not find membership record: $id");
-            }
-            $membership->join_date = CRM_Utils_Date::isoToMysql($membership->join_date);
-            $membership->start_date = CRM_Utils_Date::isoToMysql($membership->start_date);
-            $membership->end_date = CRM_Utils_Date::isoToMysql($membership->end_date);
-            $this->_relatedObjects['membership'][$membership->membership_type_id] = $membership;
-            $membership->free();
+    if (array_key_exists('membership', $ids) && is_array($ids['membership'])) {
+      foreach ($ids['membership'] as $id) {
+        if (!empty($id)) {
+          $membership = new CRM_Member_BAO_Membership();
+          $membership->id = $id;
+          if (!$membership->find(TRUE)) {
+            throw new Exception("Could not find membership record: $id");
           }
+          $membership->join_date = CRM_Utils_Date::isoToMysql($membership->join_date);
+          $membership->start_date = CRM_Utils_Date::isoToMysql($membership->start_date);
+          $membership->end_date = CRM_Utils_Date::isoToMysql($membership->end_date);
+          $this->_relatedObjects['membership'][$membership->membership_type_id] = $membership;
+          $membership->free();
         }
       }
     }
-    else {
+
+    if ($this->_component != 'contribute') {
       // we are in event mode
       // make sure event exists and is valid
       $event = new CRM_Event_BAO_Event();