/** * Update price option label in line_item, civicrm_contribution and civicrm_participant. * * @param int $id - id of the price_field_value * @param string $prevLabel * @param string $newLabel * */ public static function updateAmountAndFeeLevel($id, $prevLabel, $newLabel) { // update price field label in line item. $lineItem = new CRM_Price_DAO_LineItem(); $lineItem->price_field_value_id = $id; $lineItem->label = $prevLabel; $lineItem->find(); while ($lineItem->fetch()) { $lineItem->label = $newLabel; $lineItem->save(); // update amount and fee level in civicrm_contribution and civicrm_participant $params = array(1 => array(CRM_Core_DAO::VALUE_SEPARATOR . $prevLabel . ' -', 'String'), 2 => array(CRM_Core_DAO::VALUE_SEPARATOR . $newLabel . ' -', 'String')); if (!empty($lineItem->contribution_id)) { CRM_Core_DAO::executeQuery("UPDATE `civicrm_contribution` SET `amount_level` = REPLACE(amount_level, %1, %2) WHERE id = {$lineItem->contribution_id}", $params); $participantIds = CRM_Event_BAO_Participant::getParticipantIds($lineItem->contribution_id); foreach ($participantIds as $key => $id) { if (!empty($id)) { CRM_Core_DAO::executeQuery("UPDATE `civicrm_participant` SET `fee_level` = REPLACE(fee_level, %1, %2) WHERE id = {$id}", $params); } } } } }
/** * Update price option label in line_item, civicrm_contribution and civicrm_participant. * * @param int $id - id of the price_field_value * @param string $prevLabel * @param string $newLabel * */ public static function updateAmountAndFeeLevel($id, $prevLabel, $newLabel) { // update price field label in line item. $lineItem = new CRM_Price_DAO_LineItem(); $lineItem->price_field_value_id = $id; $lineItem->label = $prevLabel; $lineItem->find(); while ($lineItem->fetch()) { $lineItemParams['id'] = $lineItem->id; $lineItemParams['label'] = $newLabel; CRM_Price_BAO_LineItem::create($lineItemParams); // update amount and fee level in civicrm_contribution and civicrm_participant $params = array(1 => array(CRM_Core_DAO::VALUE_SEPARATOR . $prevLabel . ' -', 'String'), 2 => array(CRM_Core_DAO::VALUE_SEPARATOR . $newLabel . ' -', 'String')); // Update contribution if (!empty($lineItem->contribution_id)) { CRM_Core_DAO::executeQuery("UPDATE `civicrm_contribution` SET `amount_level` = REPLACE(amount_level, %1, %2) WHERE id = {$lineItem->contribution_id}", $params); } // Update participant if ($lineItem->entity_table == 'civicrm_participant') { CRM_Core_DAO::executeQuery("UPDATE `civicrm_participant` SET `fee_level` = REPLACE(fee_level, %1, %2) WHERE id = {$lineItem->entity_id}", $params); } } }