From ba61821d4d6074d398d31db536f017e4755441aa Mon Sep 17 00:00:00 2001 From: nathangray Date: Mon, 5 Dec 2016 10:51:17 -0700 Subject: [PATCH] Fix missing contact in notification emails for new infolog entries --- infolog/inc/class.infolog_bo.inc.php | 82 ++++++++++++++++++++++++++-- infolog/inc/class.infolog_ui.inc.php | 49 +---------------- 2 files changed, 78 insertions(+), 53 deletions(-) diff --git a/infolog/inc/class.infolog_bo.inc.php b/infolog/inc/class.infolog_bo.inc.php index 85d2a1b8cc..42365c47f5 100644 --- a/infolog/inc/class.infolog_bo.inc.php +++ b/infolog/inc/class.infolog_bo.inc.php @@ -890,11 +890,6 @@ class infolog_bo $values['info_owner'] = $this->so->user; } - if (($info_from_set = ($values['info_link_id'] && isset($values['info_from']) && empty($values['info_from'])))) - { - $values['info_from'] = $this->link_id2from($values); - } - $to_write = $values; if ($user2server) { @@ -949,6 +944,25 @@ class infolog_bo $values['info_responsible'] = $values['info_responsible'] ? explode(',',$values['info_responsible']) : array(); $to_write['info_responsible'] = $values['info_responsible']; } + + // writing links for a new entry + if (!$old && is_array($to_write['link_to']['to_id']) && count($to_write['link_to']['to_id'])) + { + //echo "

writing links for new entry $info_id

\n"; _debug_array($content['link_to']['to_id']); + Link::link('infolog',$info_id,$to_write['link_to']['to_id']); + $values['link_to']['to_id'] = $info_id; + } + $this->write_check_links($to_write); + if(!$values['info_link_id'] && $to_write['info_link_id']) + { + $values['info_link_id'] = $to_write['info_link_id']; + } + + if (($info_from_set = ($values['info_link_id'] && isset($values['info_from']) && empty($values['info_from'])))) + { + $values['info_from'] = $to_write['info_from'] = $this->link_id2from($values); + } + // create (and remove) links in custom fields if(!is_array($old)) { @@ -1015,6 +1029,64 @@ class infolog_bo return $info_id; } + /** + * Check links when writing an infolog entry + * + * Checks for info_contact properly linked, project properly linked and + * adds or removes to correct. + * + * @param Array $values + */ + protected function write_check_links(&$values) + { + if ($values['info_contact']) + { + $old_link_id = (int)$values['info_link_id']; + if(is_array($values['info_contact'])) + { + // eTemplate2 returns the array all ready + $app = $values['info_contact']['app']; + $id = $values['info_contact']['id']; + } + // if project has been removed, but is still info_contact --> also remove it + if ($app == 'projectmanager' && $id && $id == $values['old_pm_id'] && !$values['pm_id']) + { + unset($values['info_link_id'], $id, $values['info_contact']['id']); + } + elseif ($app && $id) + { + if(!is_array($values['link_to'])) + { + $values['link_to'] = array(); + } + $values['info_link_id'] = (int)($info_link_id = Link::link( + 'infolog', + $values['info_id'], + $app,$id + )); + } + else + { + unset($values['info_link_id']); + } + if ($old_link_id && $old_link_id != $values['info_link_id']) + { + $link = Link::get_link($old_link_id); + // remove selected project, if removed link is that project + if($link['link_app2'] == 'projectmanager' && $link['link_id2'] == $values['old_pm_id']) + { + unset($values['pm_id'], $values['old_pm_id']); + } + Link::unlink($old_link_id); + } + // if added link is a project and no other project selected, also add as project + if ($app == 'projectmanager' && $id && !$values['pm_id']) + { + $values['old_pm_id'] = $values['pm_id'] = $id; + } + } + } + /** * Query the number of children / subs for one or more info_id's * diff --git a/infolog/inc/class.infolog_ui.inc.php b/infolog/inc/class.infolog_ui.inc.php index dafd86bc07..ddc66f474d 100644 --- a/infolog/inc/class.infolog_ui.inc.php +++ b/infolog/inc/class.infolog_ui.inc.php @@ -1736,48 +1736,7 @@ class infolog_ui if (($button == 'save' || $button == 'apply') && (!$info_id || $edit_acl || $status_only || $undelete)) { $operation = $info_id ? 'edit' : 'add'; - if ($content['info_contact']) - { - $old_link_id = (int)$content['info_link_id']; - if(is_array($content['info_contact'])) - { - // eTemplate2 returns the array all ready - $app = $content['info_contact']['app']; - $id = $content['info_contact']['id']; - } - // if project has been removed, but is still info_contact --> also remove it - if ($app == 'projectmanager' && $id && $id == $content['old_pm_id'] && !$content['pm_id']) - { - unset($content['info_link_id'], $id, $content['info_contact']['id']); - } - elseif ($app && $id) - { - if(!is_array($content['link_to'])) - { - $content['link_to'] = array(); - } - $content['info_link_id'] = (int)($info_link_id = Link::link('infolog',$content['link_to']['to_id'],$app,$id)); - } - else - { - unset($content['info_link_id']); - } - if ($old_link_id && $old_link_id != $content['info_link_id']) - { - $link = Link::get_link($old_link_id); - // remove selected project, if removed link is that project - if($link['link_app2'] == 'projectmanager' && $link['link_id2'] == $content['old_pm_id']) - { - unset($content['pm_id'], $content['old_pm_id']); - } - Link::unlink($old_link_id); - } - // if added link is a project and no other project selected, also add as project - if ($app == 'projectmanager' && $id && !$content['pm_id']) - { - $content['old_pm_id'] = $content['pm_id'] = $id; - } - } + if (is_array($content['link_to']['to_id']) && count($content['link_to']['to_id'])) { $content['info_link_id'] = 0; // as field has to be int @@ -1826,12 +1785,6 @@ class infolog_ui } $content['old_pm_id'] = $content['pm_id']; } - // writing links for a new entry - if ($info_id && is_array($content['link_to']['to_id']) && count($content['link_to']['to_id'])) - { - //echo "

writing links for new entry $info_id

\n"; _debug_array($content['link_to']['to_id']); - Link::link('infolog',$info_id,$content['link_to']['to_id']); - } $content['link_to']['to_id'] = $info_id; if ($info_link_id && strpos($info_link_id,':') !== false) // updating info_link_id if necessary