/**
 * Sets the changeset's user id by looking up email address or name
 * Generic code for both Author and Committer, based on the given properties
 * @param object $p_changeset
 * @param string $p_user_type 'author' or 'committer'
 */
function Source_set_changeset_user(&$p_changeset, $p_user_type)
{
    static $s_vcs_names;
    static $s_names = array();
    static $s_emails = array();
    # Set the fields
    switch ($p_user_type) {
        case 'committer':
            list($t_id_prop, $t_name_prop, $t_email_prop) = explode(' ', 'committer_id committer committer_email');
            break;
        case 'author':
        default:
            list($t_id_prop, $t_name_prop, $t_email_prop) = explode(' ', 'user_id author author_email');
            break;
    }
    # The user's id is already set, nothing to do
    if ($p_changeset->{$t_id_prop}) {
        return;
    }
    # cache the vcs username mappings
    if (is_null($s_vcs_names)) {
        $s_vcs_names = SourceUser::load_mappings();
    }
    # Check username associations
    if (isset($s_vcs_names[$p_changeset->{$t_name_prop}])) {
        $p_changeset->{$t_id_prop} = $s_vcs_names[$p_changeset->{$t_name_prop}];
        return;
    }
    # Look up the email address if given
    if ($t_email = $p_changeset->{$t_email_prop}) {
        if (isset($s_emails[$t_email])) {
            $p_changeset->{$t_id_prop} = $s_emails[$t_email];
            return;
        } else {
            if (false !== ($t_email_id = user_get_id_by_email($t_email))) {
                $s_emails[$t_email] = $p_changeset->{$t_id_prop} = $t_email_id;
                return;
            }
        }
    }
    # Look up the name if the email failed
    if ($t_name = $p_changeset->{$t_name_prop}) {
        if (isset($s_names[$t_name])) {
            $p_changeset->{$t_id_prop} = $s_names[$t_name];
            return;
        } else {
            if (false !== ($t_user_id = user_get_id_by_realname($t_name))) {
                $s_names[$t_name] = $p_changeset->{$t_id_prop} = $t_user_id;
                return;
            } else {
                if (false !== ($t_user_id = user_get_id_by_name($p_changeset->{$t_name_prop}))) {
                    $s_names[$t_name] = $p_changeset->{$t_id_prop} = $t_user_id;
                    return;
                }
            }
        }
    }
}
示例#2
0
require_api('gpc_api.php');
require_api('helper_api.php');
require_api('print_api.php');
require_api('user_api.php');
require_api('utility_api.php');
form_security_validate('bug_monitor_add');
$f_bug_id = gpc_get_int('bug_id');
$t_bug = bug_get($f_bug_id, true);
$f_username = gpc_get_string('username', '');
$t_logged_in_user_id = auth_get_current_user_id();
if (is_blank($f_username)) {
    $t_user_id = $t_logged_in_user_id;
} else {
    $t_user_id = user_get_id_by_name($f_username);
    if ($t_user_id === false) {
        $t_user_id = user_get_id_by_realname($f_username);
        if ($t_user_id === false) {
            error_parameters($f_username);
            trigger_error(ERROR_USER_BY_NAME_NOT_FOUND, E_USER_ERROR);
        }
    }
}
if (user_is_anonymous($t_user_id)) {
    trigger_error(ERROR_PROTECTED_ACCOUNT, E_USER_ERROR);
}
bug_ensure_exists($f_bug_id);
if ($t_bug->project_id != helper_get_current_project()) {
    # in case the current project is not the same project of the bug we are viewing...
    # ... override the current project. This to avoid problems with categories and handlers lists etc.
    $g_project_override = $t_bug->project_id;
}
示例#3
0
 /**
  * Return the user id in the destination tracker
  *
  * Current logic is: try to find the same user by username;
  * if it fails, use $p_squash_userid
  *
  * @param string $p_username username as imported
  * @param int $p_squash_userid fallback userid
  * @return int
  */
 private function get_user_id($p_username, $p_squash_userid = 0)
 {
     $t_user_id = user_get_id_by_name($p_username);
     if ($t_user_id === false) {
         // user not found by username -> check real name
         // keep in mind that the setting config_get( 'show_user_realname_threshold' ) may differ between import and export system!
         $t_user_id = user_get_id_by_realname($p_username);
         if ($t_user_id === false) {
             //not found
             $t_user_id = $p_squash_userid;
         }
     }
     return $t_user_id;
 }
/**
 * Determine the user ID for both the author and committer.
 * First checks the email address for a matching user, then
 * checks the name for a matching username or realname.
 * @param object Changeset object
 */
function Source_Parse_Users($p_changeset)
{
    static $s_vcs_names;
    static $s_names = array();
    static $s_emails = array();
    # cache the vcs username mappings
    if (is_null($s_vcs_names)) {
        $s_vcs_names = SourceUser::load_mappings();
    }
    # Handle the changeset author
    while (!$p_changeset->user_id) {
        # Check username associations
        if (isset($s_vcs_names[$p_changeset->author])) {
            $p_changeset->user_id = $s_vcs_names[$p_changeset->author];
            break;
        }
        # Look up the email address if given
        if ($t_email = $p_changeset->author_email) {
            if (isset($s_emails[$t_email])) {
                $p_changeset->user_id = $s_emails[$t_email];
                break;
            } else {
                if (false !== ($t_email_id = user_get_id_by_email($t_email))) {
                    $s_emails[$t_email] = $p_changeset->user_id = $t_email_id;
                    break;
                }
            }
        }
        # Look up the name if the email failed
        if ($t_name = $p_changeset->author) {
            if (isset($s_names[$t_name])) {
                $p_changeset->user_id = $s_names[$t_name];
                break;
            } else {
                if (false !== ($t_user_id = user_get_id_by_realname($t_name))) {
                    $s_names[$t_name] = $p_changeset->user_id = $t_user_id;
                    break;
                } else {
                    if (false !== ($t_user_id = user_get_id_by_name($p_changeset->author))) {
                        $s_names[$t_name] = $p_changeset->user_id = $t_user_id;
                        break;
                    }
                }
            }
        }
        # Don't actually loop
        break;
    }
    # Handle the changeset committer
    while (!$p_changeset->committer_id) {
        # Check username associations
        if (isset($s_vcs_names[$p_changeset->committer])) {
            $p_changeset->user_id = $s_vcs_names[$p_changeset->committer];
            break;
        }
        # Look up the email address if given
        if ($t_email = $t_email) {
            if (isset($s_emails[$t_email])) {
                $p_changeset->committer_id = $s_emails[$t_email];
                break;
            } else {
                if (false !== ($t_email_id = user_get_id_by_email($t_email))) {
                    $s_emails[$t_email] = $p_changeset->committer_id = $t_email_id;
                    break;
                }
            }
        }
        # Look up the name if the email failed
        if ($t_name = $p_changeset->committer) {
            if (isset($s_names[$t_name])) {
                $p_changeset->committer_id = $s_names[$t_name];
                break;
            } else {
                if (false !== ($t_user_id = user_get_id_by_realname($t_name))) {
                    $s_names[$t_name] = $p_changeset->committer_id = $t_user_id;
                    break;
                } else {
                    if (false !== ($t_user_id = user_get_id_by_name($t_name))) {
                        $s_names[$t_name] = $p_changeset->committer_id = $t_user_id;
                        break;
                    }
                }
            }
        }
        # Don't actually loop
        break;
    }
    return $p_changeset;
}