From 944014b50cb53985bb30cbe76ecdc1174fb16d2a Mon Sep 17 00:00:00 2001 From: deepak-srivastava Date: Thu, 2 Oct 2014 17:00:41 +0100 Subject: [PATCH] make sure recurring set has a parent-parent entry --- CRM/Core/BAO/RecurringEntity.php | 19 ++++++++++++++++--- CRM/Core/Page/AJAX/RecurringEntity.php | 4 ++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CRM/Core/BAO/RecurringEntity.php b/CRM/Core/BAO/RecurringEntity.php index c48be354ce..1fb4d9f713 100644 --- a/CRM/Core/BAO/RecurringEntity.php +++ b/CRM/Core/BAO/RecurringEntity.php @@ -592,8 +592,9 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity { $processedEntities[$key] = 1; // get related entities for table being saved - $repeatingEntities = self::getEntitiesFor($obj->id, $obj->__table, FALSE, NULL); - if (empty($repeatingEntities)) { + $hasaRecurringRecord = self::getParentFor($obj->id, $obj->__table); + + if (empty($hasaRecurringRecord)) { // check if its a linked entity if (array_key_exists($obj->__table, self::$_linkedEntitiesInfo)) { $linkedDAO = new self::$_tableDAOMapper[$obj->__table](); @@ -606,11 +607,23 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity { $pEntityTable = $linkedDAO->$tableCol; // find all parent recurring entity set - $pRepeatingEntities = self::getEntitiesFor($pEntityID, $pEntityTable, FALSE, NULL); + $pRepeatingEntities = self::getEntitiesFor($pEntityID, $pEntityTable); if (!empty($pRepeatingEntities)) { // for each parent entity in the set, find out a similar linked entity, // if doesn't exist create one, and also create entries in recurring_entity table + + foreach($pRepeatingEntities as $key => $val) { + if (array_key_exists($key, $processedEntities)) { + // this graph is already being processed + return NULL; + } + $processedEntities[$key] = 1; + } + + // start with first entry with just itself + CRM_Core_BAO_RecurringEntity::quickAdd($obj->id, $obj->id, $obj->__table); + foreach($pRepeatingEntities as $key => $val) { $rlinkedDAO = new self::$_tableDAOMapper[$obj->__table](); $rlinkedDAO->$idCol = $val['id']; diff --git a/CRM/Core/Page/AJAX/RecurringEntity.php b/CRM/Core/Page/AJAX/RecurringEntity.php index 1bdc309356..061a177364 100644 --- a/CRM/Core/Page/AJAX/RecurringEntity.php +++ b/CRM/Core/Page/AJAX/RecurringEntity.php @@ -30,10 +30,10 @@ class CRM_Core_Page_AJAX_RecurringEntity { $dao = new CRM_Core_DAO_RecurringEntity(); if(!empty($result)){ $dao->entity_id = $result['entityId']; - $dao->entityTable = $result['entityTable']; + $dao->entity_table = $result['entityTable']; }else{ $dao->entity_id = $entityId; - $dao->entityTable = $entityTable; + $dao->entity_table = $entityTable; } if($dao->find(TRUE)){ -- 2.25.1