Fix missing contact in notification emails for new infolog entries

This commit is contained in:
nathangray 2016-12-05 10:51:17 -07:00
parent 6d24ba6e29
commit ba61821d4d
2 changed files with 78 additions and 53 deletions

View File

@ -890,11 +890,6 @@ class infolog_bo
$values['info_owner'] = $this->so->user; $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; $to_write = $values;
if ($user2server) if ($user2server)
{ {
@ -949,6 +944,25 @@ class infolog_bo
$values['info_responsible'] = $values['info_responsible'] ? explode(',',$values['info_responsible']) : array(); $values['info_responsible'] = $values['info_responsible'] ? explode(',',$values['info_responsible']) : array();
$to_write['info_responsible'] = $values['info_responsible']; $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 "<p>writing links for new entry $info_id</p>\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 // create (and remove) links in custom fields
if(!is_array($old)) if(!is_array($old))
{ {
@ -1015,6 +1029,64 @@ class infolog_bo
return $info_id; 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 * Query the number of children / subs for one or more info_id's
* *

View File

@ -1736,48 +1736,7 @@ class infolog_ui
if (($button == 'save' || $button == 'apply') && (!$info_id || $edit_acl || $status_only || $undelete)) if (($button == 'save' || $button == 'apply') && (!$info_id || $edit_acl || $status_only || $undelete))
{ {
$operation = $info_id ? 'edit' : 'add'; $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'])) 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 $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']; $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 "<p>writing links for new entry $info_id</p>\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; $content['link_to']['to_id'] = $info_id;
if ($info_link_id && strpos($info_link_id,':') !== false) // updating info_link_id if necessary if ($info_link_id && strpos($info_link_id,':') !== false) // updating info_link_id if necessary