From 867c66179678fa0a1b2641ffe2bf2690bcb3e9dd Mon Sep 17 00:00:00 2001 From: nathangray Date: Wed, 15 Nov 2017 15:41:12 -0700 Subject: [PATCH] Fix missing fields in merge if info_contact is not a addressbook entry --- api/src/Storage/Merge.php | 46 +++++++++++++++++++++---- infolog/inc/class.infolog_merge.inc.php | 19 +++++----- 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/api/src/Storage/Merge.php b/api/src/Storage/Merge.php index fdd3944154..0e11c62b96 100644 --- a/api/src/Storage/Merge.php +++ b/api/src/Storage/Merge.php @@ -1427,13 +1427,7 @@ abstract class Merge // Get replacements for that application if(!$app_replacements[$field]) { - $classname = "{$field_app}_merge"; - $class = new $classname(); - // If we send the real content it can result in infinite loop of lookups - // so we send only the used fields - $content = $expand_sub_cfs[$field] ? $expand_sub_cfs[$field] : ''; - - $app_replacements[$field] = $class->get_replacements($values['#'.$field], $content); + $app_replacements[$field] = $this->get_app_replacements($field_app, $values['#'.$field], $content); } $replacements[$placeholders[$index]] = $app_replacements[$field]['$$'.$sub[$index].'$$']; } @@ -1444,6 +1438,44 @@ abstract class Merge } } + /** + * Get the replacements for any entry specified by app & id + * + * @param stribg $app + * @param string $id + * @param string $content + * @return array + */ + protected function get_app_replacements($app, $id, $content, $prefix) + { + $replacements = array(); + if($app == 'addressbook') + { + return $this->contact_replacements($id, $prefix); + } + + try + { + $classname = "{$app}_merge"; + $class = new $classname(); + $method = $app.'_replacements'; + if(method_exists($class,$method)) + { + $replacements = $class->$method($id, $prefix, $content); + } + else + { + $replacements = $class->get_replacements($id, $content); + } + } + catch (\Exception $e) + { + // Don't break merge, just log it + error_log($e->getMessage()); + } + return $replacements; + } + /** * Process special flags, such as IF or NELF * diff --git a/infolog/inc/class.infolog_merge.inc.php b/infolog/inc/class.infolog_merge.inc.php index e3f6126c29..4d720f3f37 100644 --- a/infolog/inc/class.infolog_merge.inc.php +++ b/infolog/inc/class.infolog_merge.inc.php @@ -69,15 +69,6 @@ class infolog_merge extends Api\Storage\Merge { return false; } - if (!(strpos($content,'$$info_contact/') === false)) - { - // Check to see if it's actually a contact, then load - if(is_array($replacements['$$info_link$$']) && $replacements['$$info_link$$']['app'] == 'addressbook') - { - $replacements += $this->contact_replacements($replacements['$$info_link$$']['id'],'info_contact'); - } - if(is_array($replacements['$$info_link$$'])) unset($replacements['$$info_link$$']); - } return $replacements; } @@ -108,7 +99,7 @@ class infolog_merge extends Api\Storage\Merge } importexport_export_csv::convert($record, $types, 'infolog', $selects); - + $array = $record->get_record_array(); if($record->info_contact) { @@ -154,7 +145,7 @@ class infolog_merge extends Api\Storage\Merge $pm_merge = new projectmanager_merge($array['pm_id']); $info += $pm_merge->projectmanager_replacements($array['pm_id'],'project',$content); } - + // Add markers foreach($array as $key => &$value) { @@ -162,6 +153,12 @@ class infolog_merge extends Api\Storage\Merge $info['$$'.($prefix ? $prefix.'/':'').$key.'$$'] = $value; } + // Add contact fields + if($array['info_link']['app'] && $array['info_link']['id']) + { + $info+=$this->get_app_replacements($array['info_link']['app'], $array['info_link']['id'], $content, 'info_contact'); + } + // Add parent if($record->info_id_parent) {