About the previous post… as a quick fix is valid but I’ve found a side effect, sometimes you don’t get the full name but the username… this is valid for me because, at least, my users don’t get the required field error (for the assigned user field) when they are saving.
But I felt I could do it better so I kept researching
So I removed the empty($this->focus->assigned_user_name) condition and got into the get_assigned_user_name function.
I placed an echo to see what was going on:
echo($assigned_user_id . " - " .$saved_user_list[$assigned_user_id] . "<br />");
This showed that I saw that $saved_user_list[$assigned_user_id] was empty for some users and had the full name for others…
I suppose that the error is on the cache construction of {user_array} value… I didn’t want to go further, so I decided to clean that cache value to rebuild it… so I created a function to clean that cache value and get_assigned_user_name function ended as:
function get_assigned_user_name($assigned_user_id, $is_group = '')
{
static $saved_user_list = null;
if (empty($saved_user_list)) {
$saved_user_list = get_user_array(false, '', '', false, null, $is_group);
}
// echo($assigned_user_id . " - " .$saved_user_list[$assigned_user_id] . "<br />");
if (isset($saved_user_list[$assigned_user_id])) {
return $saved_user_list[$assigned_user_id];
}
//Added code
clear_user_array_from_cache(false, '', '', false, null, $is_group);
$saved_user_list = get_user_array(false, '', '', false, null, $is_group);
if (isset($saved_user_list[$assigned_user_id])) {
return $saved_user_list[$assigned_user_id];
}
//End Added code
return '';
}
function clear_user_array_from_cache($add_blank = true, $status = 'Active', $user_id = '', $use_real_name = false, $user_name_filter = '',
$portal_filter = ' AND portal_only=0 ', $from_cache = true){
$name = $add_blank.$status.$user_id.$use_real_name.$user_name_filter.$portal_filter;
sugar_cache_clear("{user_array}:{$name}");
}
Yes, not an optimal solution, but now it’s loading full names.
I will report any bug or side effect if I notice something!