From 43b07dfb044d3b83585d501cb66a36e6db22e39f Mon Sep 17 00:00:00 2001 From: nathangray Date: Wed, 21 Dec 2016 10:02:26 -0700 Subject: [PATCH] Fix some more contact bugs: - Contact would only actually change every second time you changed it - Contact would sometimes stay even after being removed --- infolog/inc/class.infolog_bo.inc.php | 89 ++++++++++++++-------------- infolog/inc/class.infolog_ui.inc.php | 9 +++ 2 files changed, 53 insertions(+), 45 deletions(-) diff --git a/infolog/inc/class.infolog_bo.inc.php b/infolog/inc/class.infolog_bo.inc.php index 5bd896d81a..be3dc5af67 100644 --- a/infolog/inc/class.infolog_bo.inc.php +++ b/infolog/inc/class.infolog_bo.inc.php @@ -953,11 +953,13 @@ class infolog_bo $values['link_to']['to_id'] = $info_id; } $this->write_check_links($to_write); - if(!$values['info_link_id'] && $to_write['info_link_id']) + if(!$values['info_link_id'] || $values['info_link_id'] != $to_write['info_link_id']) { // Just got a link ID, need to save it $this->so->write($to_write); $values['info_link_id'] = $to_write['info_link_id']; + $values['info_contact'] = $to_write['info_contact']; + $this->link_id2from($values); } if (($info_from_set = ($values['info_link_id'] && isset($values['info_from']) && empty($values['info_from'])))) @@ -1041,55 +1043,52 @@ class infolog_bo */ protected function write_check_links(&$values) { - if ($values['info_contact']) + $old_link_id = (int)$values['info_link_id']; + if(is_array($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']; + } + else if ($values['info_contact']) + { + list($app, $id) = explode(':', $values['info_contact'], 2); + } + // 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'])) { - // eTemplate2 returns the array all ready - $app = $values['info_contact']['app']; - $id = $values['info_contact']['id']; + $values['link_to'] = array(); } - else if ($values['info_contact']) + $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']) { - list($app, $id) = explode(':', $values['info_contact'], 2); - } - // 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; + 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; } } diff --git a/infolog/inc/class.infolog_ui.inc.php b/infolog/inc/class.infolog_ui.inc.php index 0cb53414bc..2a6e770b39 100644 --- a/infolog/inc/class.infolog_ui.inc.php +++ b/infolog/inc/class.infolog_ui.inc.php @@ -1741,6 +1741,14 @@ class infolog_ui { $content['info_link_id'] = 0; // as field has to be int } + if (is_array($content['info_contact']) && $content['info_contact']['id']) + { + $content['info_contact'] = $content['info_contact']['app'] . ':' . $content['info_contact']['id']; + } + else + { + $content['info_contact'] = false; + } $active_tab = $content['tabs']; if (!($info_id = $this->bo->write($content, true, true, true, $content['no_notifications']))) { @@ -1785,6 +1793,7 @@ class infolog_ui } $content['old_pm_id'] = $content['pm_id']; } + $content['link_to']['to_app'] = 'infolog'; $content['link_to']['to_id'] = $info_id; if ($info_link_id && strpos($info_link_id,':') !== false) // updating info_link_id if necessary