Beispiel #1
0
function bugCreateHelper($reproducibility, $severity, $priority, $summary, $description, $project_id, $reporter_id)
{
    # Change this path to point to the Mantis installation core.php file
    require_once '../core.php';
    $t_core_path = config_get('core_path');
    require_once $t_core_path . 'bug_api.php';
    access_ensure_project_level(config_get('report_bug_threshold'));
    $t_bug_data = new BugData();
    $t_bug_data->view_state = config_get('default_bug_view_status');
    $t_bug_data->reproducibility = $reproducibility;
    $t_bug_data->severity = $severity;
    $t_bug_data->priority = $priority;
    $t_bug_data->summary = $summary;
    $t_bug_data->description = $description;
    $t_bug_data->project_id = $project_id;
    $t_bug_data->reporter_id = user_get_id_by_name($reporter_id);
    if ($t_bug_data->reporter_id == "") {
        $tmp = "Reported by: " . $reporter_id . "\n---------------------------------------------------\n\n";
        $tmp .= $t_bug_data->description;
        $t_bug_data->description = $tmp;
    }
    $t_bug_data->summary = trim($t_bug_data->summary);
    # Create the bug
    $t_bug_id = bug_create($t_bug_data);
    email_new_bug($t_bug_id);
    return $t_bug_id;
}
 public function addIssue($issue)
 {
     if (MANTIS_LOCAL) {
         $t_bug_data = new BugData();
         $t_bug_data->project_id = $issue->project->id;
         $t_bug_data->reporter_id = $this->userID;
         $t_bug_data->priority = $issue->priority['id'];
         $t_bug_data->severity = $issue->severity['id'];
         $t_bug_data->reproducibility = $issue->reproducibility['id'];
         $t_bug_data->status = $issue->status['id'];
         $t_bug_data->resolution = $issue->resolution['id'];
         $t_bug_data->projection = $issue->projection['id'];
         $t_bug_data->category = $issue->category;
         $t_bug_data->eta = $issue->eta['id'];
         $t_bug_data->version = $issue->version;
         $t_bug_data->view_state = $issue->view_state['id'];
         $t_bug_data->summary = $issue->summary;
         # extended info
         $t_bug_data->description = $issue->description;
         $t_bug_data->additional_information = $issue->additional_information;
         # submit the issue
         $ret = bug_create($t_bug_data);
         email_new_bug($ret);
     } else {
         $ret = $this->client->mc_issue_add(MANTIS_USER, MANTIS_PWD, $issue);
     }
     return $ret;
 }
helper_call_custom_function('issue_create_validate', array($t_bug_data));
# Validate the custom fields before adding the bug.
$t_related_custom_field_ids = custom_field_get_linked_ids($t_bug_data->project_id);
foreach ($t_related_custom_field_ids as $t_id) {
    $t_def = custom_field_get_definition($t_id);
    if ($t_def['require_report'] && gpc_get_custom_field("custom_field_{$t_id}", $t_def['type'], '') == '') {
        error_parameters(lang_get_defaulted(custom_field_get_field($t_id, 'name')));
        trigger_error(ERROR_EMPTY_FIELD, ERROR);
    }
    if (!custom_field_validate($t_id, gpc_get_custom_field("custom_field_{$t_id}", $t_def['type'], $t_def['default_value']))) {
        error_parameters(lang_get_defaulted(custom_field_get_field($t_id, 'name')));
        trigger_error(ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR);
    }
}
# Create the bug
$t_bug_id = bug_create($t_bug_data);
# Handle the file upload
if (!is_blank($f_file['tmp_name']) && 0 < $f_file['size']) {
    $f_file_error = isset($f_file['error']) ? $f_file['error'] : 0;
    file_add($t_bug_id, $f_file['tmp_name'], $f_file['name'], $f_file['type'], 'bug', $f_file_error);
}
# Handle custom field submission
foreach ($t_related_custom_field_ids as $t_id) {
    # Do not set custom field value if user has no write access.
    if (!custom_field_has_write_access($t_id, $t_bug_id)) {
        continue;
    }
    $t_def = custom_field_get_definition($t_id);
    if (!custom_field_set_value($t_id, $t_bug_id, gpc_get_custom_field("custom_field_{$t_id}", $t_def['type'], $t_def['default_value']))) {
        error_parameters(lang_get_defaulted(custom_field_get_field($t_id, 'name')));
        trigger_error(ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR);
/**
 * Add an issue to the database.
 *
 * @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_add($p_username, $p_password, $p_issue)
{
    $t_user_id = mci_check_login($p_username, $p_password);
    if ($t_user_id === false) {
        return new soap_fault('Client', '', 'Access Denied');
    }
    extract($p_issue, EXTR_PREFIX_ALL, 'v');
    $t_project_id = mci_get_project_id($v_project);
    if (!mci_has_readwrite_access($t_user_id, $t_project_id)) {
        return new soap_fault('Client', '', 'Access Denied');
    }
    $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;
    } else {
        if ($t_reporter_id != $t_user_id) {
            # Make sure that active user has access level required to specify a different reporter.
            $t_specify_reporter_access_level = config_get('mc_specify_reporter_on_add_access_level_threshold');
            if (!access_has_project_level($t_specify_reporter_access_level, $t_project_id, $t_user_id)) {
                return new soap_fault('Client', '', "Active user does not have access level required to specify a different issue reporter.");
            }
        }
    }
    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_project_level(config_get('report_bug_threshold'), $t_project_id, $t_user_id)) {
        return new soap_fault('Client', '', "User '{$t_user_id}' does not have access right to report issues.");
    }
    #if ( !access_has_project_level( config_get( 'report_bug_threshold' ), $t_project_id ) ||
    #	!access_has_project_level( config_get( 'report_bug_threshold' ), $t_project_id, $v_reporter ) ) {
    #	return new soap_fault( 'Client', '', "User 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_issue_id = bug_create($t_bug_data);
    mci_issue_set_custom_fields($t_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');
            }
            $t_view_state_id = mci_get_enum_id_from_objectref('view_state', $t_view_state);
            bugnote_add($t_issue_id, $t_note['text'], '0:00', $t_view_state_id == VS_PRIVATE, BUGNOTE, '', $t_user_id, FALSE);
        }
    }
    email_new_bug($t_issue_id);
    return $t_issue_id;
}
Beispiel #5
0
function bug_copy($p_bug_id, $p_target_project_id = null, $p_copy_custom_fields = false, $p_copy_relationships = false, $p_copy_history = false, $p_copy_attachments = false, $p_copy_bugnotes = false, $p_copy_monitoring_users = false)
{
    global $g_db;
    $t_mantis_custom_field_string_table = config_get('mantis_custom_field_string_table');
    $t_mantis_bug_file_table = config_get('mantis_bug_file_table');
    $t_mantis_bugnote_table = config_get('mantis_bugnote_table');
    $t_mantis_bugnote_text_table = config_get('mantis_bugnote_text_table');
    $t_mantis_bug_monitor_table = config_get('mantis_bug_monitor_table');
    $t_mantis_bug_history_table = config_get('mantis_bug_history_table');
    $t_mantis_db = $g_db;
    $t_bug_id = db_prepare_int($p_bug_id);
    $t_target_project_id = db_prepare_int($p_target_project_id);
    $t_bug_data = new BugData();
    $t_bug_data = bug_get($t_bug_id, true);
    # retrieve the project id associated with the bug
    if ($p_target_project_id == null || is_blank($p_target_project_id)) {
        $t_target_project_id = $t_bug_data->project_id;
    }
    $t_bug_data->project_id = $t_target_project_id;
    $t_new_bug_id = bug_create($t_bug_data);
    # MASC ATTENTION: IF THE SOURCE BUG HAS TO HANDLER THE bug_create FUNCTION CAN TRY TO AUTO-ASSIGN THE BUG
    # WE FORCE HERE TO DUPLICATE THE SAME HANDLER OF THE SOURCE BUG
    # @@@ VB: Shouldn't we check if the handler in the source project is also a handler in the destination project?
    bug_set_field($t_new_bug_id, 'handler_id', $t_bug_data->handler_id);
    bug_set_field($t_new_bug_id, 'duplicate_id', $t_bug_data->duplicate_id);
    bug_set_field($t_new_bug_id, 'status', $t_bug_data->status);
    bug_set_field($t_new_bug_id, 'resolution', $t_bug_data->resolution);
    bug_set_field($t_new_bug_id, 'projection', $t_bug_data->projection);
    bug_set_field($t_new_bug_id, 'date_submitted', $t_mantis_db->DBTimeStamp($t_bug_data->date_submitted), false);
    bug_set_field($t_new_bug_id, 'last_updated', $t_mantis_db->DBTimeStamp($t_bug_data->last_updated), false);
    bug_set_field($t_new_bug_id, 'eta', $t_bug_data->eta);
    bug_set_field($t_new_bug_id, 'fixed_in_version', $t_bug_data->fixed_in_version);
    bug_set_field($t_new_bug_id, 'target_version', $t_bug_data->target_version);
    bug_set_field($t_new_bug_id, 'sponsorship_total', 0);
    bug_set_field($t_new_bug_id, 'sticky', 0);
    # COPY CUSTOM FIELDS
    if ($p_copy_custom_fields) {
        $query = "SELECT field_id, bug_id, value\n\t\t\t\t\t   FROM {$t_mantis_custom_field_string_table}\n\t\t\t\t\t   WHERE bug_id = '{$t_bug_id}';";
        $result = db_query($query);
        $t_count = db_num_rows($result);
        for ($i = 0; $i < $t_count; $i++) {
            $t_bug_custom = db_fetch_array($result);
            $c_field_id = db_prepare_int($t_bug_custom['field_id']);
            $c_new_bug_id = db_prepare_int($t_new_bug_id);
            $c_value = db_prepare_string($t_bug_custom['value']);
            $query = "INSERT INTO {$t_mantis_custom_field_string_table}\n\t\t\t\t\t\t   ( field_id, bug_id, value )\n\t\t\t\t\t\t   VALUES ('{$c_field_id}', '{$c_new_bug_id}', '{$c_value}')";
            db_query($query);
        }
    }
    # COPY RELATIONSHIPS
    if ($p_copy_relationships) {
        if (ON == config_get('enable_relationship')) {
            relationship_copy_all($t_bug_id, $t_new_bug_id);
        }
    }
    # Copy bugnotes
    if ($p_copy_bugnotes) {
        $query = "SELECT *\n\t\t\t\t\t  FROM {$t_mantis_bugnote_table}\n\t\t\t\t\t  WHERE bug_id = '{$t_bug_id}';";
        $result = db_query($query);
        $t_count = db_num_rows($result);
        for ($i = 0; $i < $t_count; $i++) {
            $t_bug_note = db_fetch_array($result);
            $t_bugnote_text_id = $t_bug_note['bugnote_text_id'];
            $query2 = "SELECT *\n\t\t\t\t\t\t   FROM {$t_mantis_bugnote_text_table}\n\t\t\t\t\t\t   WHERE id = '{$t_bugnote_text_id}';";
            $result2 = db_query($query2);
            $t_count2 = db_num_rows($result2);
            $t_bugnote_text_insert_id = -1;
            if ($t_count2 > 0) {
                $t_bugnote_text = db_fetch_array($result2);
                $t_bugnote_text['note'] = db_prepare_string($t_bugnote_text['note']);
                $query2 = "INSERT INTO {$t_mantis_bugnote_text_table}\n\t\t\t\t\t\t\t   ( note )\n\t\t\t\t\t\t\t   VALUES ( '" . $t_bugnote_text['note'] . "' );";
                db_query($query2);
                $t_bugnote_text_insert_id = db_insert_id($t_mantis_bugnote_text_table);
            }
            $query2 = "INSERT INTO {$t_mantis_bugnote_table}\n\t\t\t\t\t\t   ( bug_id, reporter_id, bugnote_text_id, view_state, date_submitted, last_modified )\n\t\t\t\t\t\t   VALUES ( '{$t_new_bug_id}',\n\t\t\t\t\t\t   \t\t\t'" . $t_bug_note['reporter_id'] . "',\n\t\t\t\t\t\t   \t\t\t'{$t_bugnote_text_insert_id}',\n\t\t\t\t\t\t   \t\t\t'" . $t_bug_note['view_state'] . "',\n\t\t\t\t\t\t   \t\t\t'" . $t_bug_note['date_submitted'] . "',\n\t\t\t\t\t\t   \t\t\t'" . $t_bug_note['last_modified'] . "' );";
            db_query($query2);
        }
    }
    # Copy attachments
    if ($p_copy_attachments) {
        $query = "SELECT *\n\t\t\t\t\t  FROM {$t_mantis_bug_file_table}\n\t\t\t\t\t  WHERE bug_id = '{$t_bug_id}';";
        $result = db_query($query);
        $t_count = db_num_rows($result);
        $t_bug_file = array();
        for ($i = 0; $i < $t_count; $i++) {
            $t_bug_file = db_fetch_array($result);
            # prepare the new diskfile name and then copy the file
            $t_file_path = dirname($t_bug_file['folder']);
            $t_new_diskfile_name = $t_file_path . file_generate_unique_name('bug-' . $p_file_name, $t_file_path);
            $t_new_file_name = file_get_display_name($t_bug_file['filename']);
            if (config_get('file_upload_method') == DISK) {
                copy($t_bug_file['diskfile'], $t_new_diskfile_name);
                chmod($t_new_diskfile_name, config_get('attachments_file_permissions'));
            }
            $query = "INSERT INTO {$t_mantis_bug_file_table}\n\t\t\t\t\t\t( bug_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content )\n\t\t\t\t\t\tVALUES ( '{$t_new_bug_id}',\n\t\t\t\t\t\t\t\t '" . db_prepare_string($t_bug_file['title']) . "',\n\t\t\t\t\t\t\t\t '" . db_prepare_string($t_bug_file['description']) . "',\n\t\t\t\t\t\t\t\t '" . db_prepare_string($t_new_diskfile_name) . "',\n\t\t\t\t\t\t\t\t '" . db_prepare_string($t_new_file_name) . "',\n\t\t\t\t\t\t\t\t '" . db_prepare_string($t_bug_file['folder']) . "',\n\t\t\t\t\t\t\t\t '" . db_prepare_int($t_bug_file['filesize']) . "',\n\t\t\t\t\t\t\t\t '" . db_prepare_string($t_bug_file['file_type']) . "',\n\t\t\t\t\t\t\t\t '" . db_prepare_string($t_bug_file['date_added']) . "',\n\t\t\t\t\t\t\t\t '" . db_prepare_string($t_bug_file['content']) . "');";
            db_query($query);
        }
    }
    # Copy users monitoring bug
    if ($p_copy_monitoring_users) {
        $query = "SELECT *\n\t\t\t\t\t  FROM {$t_mantis_bug_monitor_table}\n\t\t\t\t\t  WHERE bug_id = '{$t_bug_id}';";
        $result = db_query($query);
        $t_count = db_num_rows($result);
        for ($i = 0; $i < $t_count; $i++) {
            $t_bug_monitor = db_fetch_array($result);
            $query = "INSERT INTO {$t_mantis_bug_monitor_table}\n\t\t\t\t\t\t ( user_id, bug_id )\n\t\t\t\t\t\t VALUES ( '" . $t_bug_monitor['user_id'] . "', '{$t_new_bug_id}' );";
            db_query($query);
        }
    }
    # COPY HISTORY
    history_delete($t_new_bug_id);
    # should history only be deleted inside the if statement below?
    if ($p_copy_history) {
        $query = "SELECT *\n\t\t\t\t\t  FROM {$t_mantis_bug_history_table}\n\t\t\t\t\t  WHERE bug_id = '{$t_bug_id}';";
        $result = db_query($query);
        $t_count = db_num_rows($result);
        for ($i = 0; $i < $t_count; $i++) {
            $t_bug_history = db_fetch_array($result);
            $query = "INSERT INTO {$t_mantis_bug_history_table}\n\t\t\t\t\t\t  ( user_id, bug_id, date_modified, field_name, old_value, new_value, type )\n\t\t\t\t\t\t  VALUES ( '" . db_prepare_int($t_bug_history['user_id']) . "',\n\t\t\t\t\t\t  \t\t   '{$t_new_bug_id}',\n\t\t\t\t\t\t  \t\t   '" . db_prepare_string($t_bug_history['date_modified']) . "',\n\t\t\t\t\t\t  \t\t   '" . db_prepare_string($t_bug_history['field_name']) . "',\n\t\t\t\t\t\t  \t\t   '" . db_prepare_string($t_bug_history['old_value']) . "',\n\t\t\t\t\t\t  \t\t   '" . db_prepare_string($t_bug_history['new_value']) . "',\n\t\t\t\t\t\t  \t\t   '" . db_prepare_int($t_bug_history['type']) . "' );";
            db_query($query);
        }
    }
    return $t_new_bug_id;
}
 public function post($request)
 {
     /**
      * 	Creates a new bug.
      *
      * 	Sets the location header and returns the main URL of the created resource,
      * 	as RFC2616 says we SHOULD.
      *
      * 	@param $request - The Request we're responding to
      */
     # This is all copied from Mantis's bug_report.php.
     $new_bug = new Bug();
     $new_bug->populate_from_repr($request->body);
     $new_bugdata = $new_bug->to_bugdata();
     if (!access_has_project_level(config_get('report_bug_threshold'), $new_bugdata->project_id)) {
         throw new HTTPException(403, "Access denied to report bug");
     }
     $new_bug_id = bug_create($new_bugdata);
     email_new_bug($new_bug_id);
     if ($new_bug_id) {
         $new_bug_url = Bug::get_url_from_mantis_id($new_bug_id);
         $this->rsrc_data = $new_bug_url;
         $resp = new Response();
         $resp->status = 201;
         $resp->headers[] = "location: {$new_bug_url}";
         $resp->body = $this->_repr($request);
         return $resp;
     } else {
         throw new HTTPException(500, "Failed to create bug");
     }
 }