Example #1
0
/**
 * Get all categories of a project.
 *
 * @param string $p_username  The name of the user trying to access the categories.
 * @param string $p_password  The password of the user.
 * @param integer $p_project_id  The id of the project to retrieve the categories for.
 * @return Array  of categorie names
 */
function mc_project_get_categories($p_username, $p_password, $p_project_id)
{
    $t_user_id = mci_check_login($p_username, $p_password);
    if ($t_user_id === false) {
        return new soap_fault('Client', '', 'Access Denied');
    }
    if (!project_exists($p_project_id)) {
        return new soap_fault('Client', '', "Project '{$p_project_id}' does not exist.");
    }
    if (!mci_has_readonly_access($t_user_id, $p_project_id)) {
        return new soap_fault('Client', '', 'Access Denied');
    }
    return mci_category_get_all_rows($p_project_id, $t_user_id);
}
/**
 * Update Issue in database
 *
 * Created By KGB
 * @param string $p_username The name of the user trying to add the issue.
 * @param string $p_password The password of the user.
 * @param Array $p_issue A IssueData structure containing information about the new issue.
 * @return integer The id of the created issue.
 */
function mc_issue_update($p_username, $p_password, $p_issue_id, $p_issue)
{
    $t_user_id = mci_check_login($p_username, $p_password);
    if ($t_user_id === false) {
        return new soap_fault('Client', '', 'Access Denied');
    }
    if (!bug_exists($p_issue_id)) {
        return new soap_fault('Server', '', "Issue '{$p_issue_id}' does not exist.");
    }
    $t_project_id = bug_get_field($p_issue_id, 'project_id');
    if (!mci_has_readwrite_access($t_user_id, $t_project_id)) {
        return new soap_fault('Client', '', 'Access Denied');
    }
    extract($p_issue, EXTR_PREFIX_ALL, 'v');
    $t_project_id = mci_get_project_id($v_project);
    $t_handler_id = mci_get_user_id($v_handler);
    $t_priority_id = mci_get_priority_id($v_priority);
    $t_severity_id = mci_get_severity_id($v_severity);
    $t_status_id = mci_get_status_id($v_status);
    $t_reproducibility_id = mci_get_reproducibility_id($v_reproducibility);
    $t_resolution_id = mci_get_resolution_id($v_resolution);
    $t_projection_id = mci_get_projection_id($v_projection);
    $t_eta_id = mci_get_eta_id($v_eta);
    $t_view_state_id = mci_get_view_state_id($v_view_state);
    $t_reporter_id = mci_get_user_id($v_reporter);
    if ($t_reporter_id == 0) {
        $t_reporter_id = $t_user_id;
    }
    if ($t_project_id == 0 || !project_exists($t_project_id)) {
        if ($t_project_id == 0) {
            return new soap_fault('Client', '', "Project '" . $v_project['name'] . "' does not exist.");
        } else {
            return new soap_fault('Client', '', "Project '{$t_project_id}' does not exist.");
        }
    }
    if (!access_has_bug_level(config_get('update_bug_threshold'), $p_issue_id, $t_user_id)) {
        return new soap_fault('Client', '', "User '{$t_user_id}' does not have access right to report issues.");
    }
    if ($t_handler_id != 0 && !user_exists($t_handler_id)) {
        return new soap_fault('Client', '', "User '{$t_handler_id}' does not exist.");
    }
    if (!in_array($v_category, mci_category_get_all_rows($t_project_id, $t_user_id))) {
        $t_error_when_category_not_found = config_get('mc_error_when_category_not_found');
        if ($t_error_when_category_not_found == ON) {
            if (is_blank($v_category) && count(category_get_all_rows($t_project_id)) == 0) {
                $v_category = '';
                // it is ok to have category as empty if project has no categories
            } else {
                return new soap_fault('Client', '', "Category '{$v_category}' does not exist in project '{$t_project_id}'.");
            }
        } else {
            $t_category_when_not_found = config_get('mc_category_when_not_found');
            $v_category = $t_category_when_not_found;
        }
    }
    if (isset($v_version) && !is_blank($v_version) && !version_get_id($v_version, $t_project_id)) {
        $t_error_when_version_not_found = config_get('mc_error_when_version_not_found');
        if ($t_error_when_version_not_found == ON) {
            $t_project_name = project_get_name($t_project_id);
            return new soap_fault('Client', '', "Version '{$v_version}' does not exist in project '{$t_project_name}'.");
        } else {
            $t_version_when_not_found = config_get('mc_version_when_not_found');
            $v_version = $t_version_when_not_found;
        }
    }
    if (is_blank($v_summary)) {
        return new soap_fault('Client', '', "Mandatory field 'summary' is missing.");
    }
    if (is_blank($v_description)) {
        return new soap_fault('Client', '', "Mandatory field 'description' is missing.");
    }
    if ($v_priority == 0) {
        $v_priority = config_get('default_bug_priority');
    }
    if ($v_severity == 0) {
        $v_severity = config_get('default_bug_severity');
    }
    if ($v_view_state == 0) {
        $v_view_state = config_get('default_bug_view_status');
    }
    if ($v_reproducibility == 0) {
        $v_reproducibility = 10;
    }
    $t_bug_data = new BugData();
    $t_bug_data->project_id = $t_project_id;
    $t_bug_data->reporter_id = $t_reporter_id;
    $t_bug_data->handler_id = $t_handler_id;
    $t_bug_data->priority = $t_priority_id;
    $t_bug_data->severity = $t_severity_id;
    $t_bug_data->reproducibility = $t_reproducibility_id;
    $t_bug_data->status = $t_status_id;
    $t_bug_data->resolution = $t_resolution_id;
    $t_bug_data->projection = $t_projection_id;
    $t_bug_data->category = $v_category;
    $t_bug_data->date_submitted = isset($v_date_submitted) ? $v_date_submitted : '';
    $t_bug_data->last_updated = isset($v_last_updated) ? $v_last_updated : '';
    $t_bug_data->eta = $t_eta_id;
    $t_bug_data->os = isset($v_os) ? $v_os : '';
    $t_bug_data->os_build = isset($v_os_build) ? $v_os_build : '';
    $t_bug_data->platform = isset($v_platform) ? $v_platform : '';
    $t_bug_data->version = isset($v_version) ? $v_version : '';
    $t_bug_data->fixed_in_version = isset($v_fixed_in_version) ? $v_fixed_in_version : '';
    $t_bug_data->build = isset($v_build) ? $v_build : '';
    $t_bug_data->view_state = $t_view_state_id;
    $t_bug_data->summary = $v_summary;
    $t_bug_data->sponsorship_total = isset($v_sponsorship_total) ? $v_sponsorship_total : 0;
    # omitted:
    # var $bug_text_id
    # $t_bug_data->profile_id;
    # extended info
    $t_bug_data->description = $v_description;
    $t_bug_data->steps_to_reproduce = isset($v_steps_to_reproduce) ? $v_steps_to_reproduce : '';
    $t_bug_data->additional_information = isset($v_additional_information) ? $v_additional_information : '';
    # submit the issue
    $t_is_success = bug_update($p_issue_id, $t_bug_data, true, false);
    mci_issue_set_custom_fields($p_issue_id, $v_custom_fields);
    if (isset($v_notes) && is_array($v_notes)) {
        foreach ($v_notes as $t_note) {
            if (isset($t_note['view_state'])) {
                $t_view_state = $t_note['view_state'];
            } else {
                $t_view_state = config_get('default_bugnote_view_status');
            }
            // TODO: consider supporting updating of bugnotes and detecting the ones that haven't changed.
            $t_view_state_id = mci_get_enum_id_from_objectref('view_state', $t_view_state);
            bugnote_add($p_issue_id, $t_note['text'], '0:00', $t_view_state_id == VS_PRIVATE, BUGNOTE, '', $t_user_id, FALSE);
        }
    }
    return $t_is_success;
}