Пример #1
0
function custom_function_default_checkin($p_issue_id, $p_comment, $p_file, $p_new_version, $p_fixed)
{
    if (bug_exists($p_issue_id)) {
        history_log_event_special($p_issue_id, CHECKIN, $p_file, $p_new_version);
        bugnote_add($p_issue_id, $p_comment, VS_PRIVATE == config_get('source_control_notes_view_status'));
        $t_status = config_get('source_control_set_status_to');
        if (OFF != $t_status && $p_fixed) {
            bug_set_field($p_issue_id, 'status', $t_status);
            bug_set_field($p_issue_id, 'resolution', config_get('source_control_set_resolution_to'));
        }
    }
}
Пример #2
0
/**
 * Detach a tag from a bug.
 * @param integer Tag ID
 * @param integer Bug ID
 * @param boolean Add history entries to bug
 * @param integer User Id (or null for current logged in user)
 */
function tag_bug_detach($p_tag_id, $p_bug_id, $p_add_history = true, $p_user_id = null)
{
    if ($p_user_id === null) {
        $t_user_id = auth_get_current_user_id();
    } else {
        $t_user_id = $p_user_id;
    }
    if (!tag_bug_is_attached($p_tag_id, $p_bug_id)) {
        trigger_error(TAG_NOT_ATTACHED, ERROR);
    }
    $t_tag_row = tag_bug_get_row($p_tag_id, $p_bug_id);
    if ($t_user_id == tag_get_field($p_tag_id, 'user_id') || $t_user_id == $t_tag_row['user_id']) {
        $t_detach_level = config_get('tag_detach_own_threshold');
    } else {
        $t_detach_level = config_get('tag_detach_threshold');
    }
    access_ensure_bug_level($t_detach_level, $p_bug_id, $t_user_id);
    $c_tag_id = db_prepare_int($p_tag_id);
    $c_bug_id = db_prepare_int($p_bug_id);
    $t_bug_tag_table = db_get_table('bug_tag');
    $query = "DELETE FROM {$t_bug_tag_table}\n\t\t\t\t\tWHERE tag_id=" . db_param() . ' AND bug_id=' . db_param();
    db_query_bound($query, array($c_tag_id, $c_bug_id));
    if ($p_add_history) {
        $t_tag_name = tag_get_field($p_tag_id, 'name');
        history_log_event_special($p_bug_id, TAG_DETACHED, $t_tag_name);
    }
    # updated the last_updated date
    bug_update_date($p_bug_id);
    return true;
}
Пример #3
0
# Commit the bug updates to the database.
$t_text_field_update_required = $t_existing_bug->description !== $t_updated_bug->description || $t_existing_bug->additional_information !== $t_updated_bug->additional_information || $t_existing_bug->steps_to_reproduce !== $t_updated_bug->steps_to_reproduce;
$t_updated_bug->update($t_text_field_update_required, true);
# Update custom field values.
foreach ($t_custom_fields_to_set as $t_custom_field_to_set) {
    custom_field_set_value($t_custom_field_to_set['id'], $f_bug_id, $t_custom_field_to_set['value']);
}
# Add a bug note if there is one.
if ($t_bug_note->note || helper_duration_to_minutes($t_bug_note->time_tracking) > 0) {
    bugnote_add($f_bug_id, $t_bug_note->note, $t_bug_note->time_tracking, $t_bug_note->view_state == VS_PRIVATE, 0, '', null, false);
}
# Add a duplicate relationship if requested.
if ($t_updated_bug->duplicate_id !== 0) {
    relationship_add($f_bug_id, $t_updated_bug->duplicate_id, BUG_DUPLICATE);
    history_log_event_special($f_bug_id, BUG_ADD_RELATIONSHIP, BUG_DUPLICATE, $t_updated_bug->duplicate_id);
    history_log_event_special($t_updated_bug->duplicate_id, BUG_ADD_RELATIONSHIP, BUG_HAS_DUPLICATE, $f_bug_id);
    if (user_exists($t_existing_bug->reporter_id)) {
        bug_monitor($f_bug_id, $t_existing_bug->reporter_id);
    }
    if (user_exists($t_existing_bug->handler_id)) {
        bug_monitor($f_bug_id, $t_existing_bug->handler_id);
    }
    bug_monitor_copy($f_bug_id, $t_updated_bug->duplicate_id);
}
event_signal('EVENT_UPDATE_BUG', array($t_existing_bug, $t_updated_bug));
# Allow a custom function to respond to the modifications made to the bug. Note
# that custom functions are being deprecated in MantisBT. You should migrate to
# the new plugin system instead.
helper_call_custom_function('issue_update_notify', array($f_bug_id));
# Send a notification of changes via email.
if ($t_resolve_issue) {
Пример #4
0
 function save_bug($p_project_id, $p_user_id)
 {
     require 'ProfileAcraExt.php';
     $t_project_id = $p_project_id;
     global $g_cache_current_user_id;
     $g_cache_current_user_id = $p_user_id;
     $t_bug_data = new BugData();
     $t_bug_data->project_id = $t_project_id;
     $t_bug_data->reporter_id = $p_user_id;
     $t_bug_data->build = gpc_get_string('APP_VERSION_CODE', '');
     $t_bug_data->platform = "Android";
     $t_bug_data->os = gpc_get_string('ANDROID_VERSION', '');
     //gpc_get_string( 'os', '' );
     $t_os_build = gpc_get_string('BUILD', '');
     if (preg_match('/DISPLAY\\s*=\\s*(.*)/', $t_os_build, $t_match)) {
         var_dump($t_match);
         $t_os_build = $t_match[1];
     } else {
         $t_os_build = gpc_get_string('ANDROID_VERSION', '');
     }
     $t_bug_data->os_build = $t_os_build;
     //gpc_get_string( 'os_build', '' );
     $t_bug_data->version = gpc_get_string('APP_VERSION_NAME', '');
     $t_bug_data->profile_id = profile_create_unique(ALL_USERS, $t_bug_data->platform, $t_bug_data->os, $t_bug_data->os_build, "");
     $t_bug_data->handler_id = gpc_get_int('handler_id', 0);
     $t_bug_data->view_state = gpc_get_int('view_state', config_get('default_bug_view_status', 'VS_PRIVATE', 'acra_reporter'));
     $t_bug_data->category_id = $this->get_category_id($p_project_id);
     //gpc_get_int( 'category_id', 0 );
     $t_bug_data->reproducibility = 10;
     //gpc_get_int( 'reproducibility', config_get( 'default_bug_reproducibility' ) );
     $t_bug_data->severity = CRASH;
     //gpc_get_int( 'severity', config_get( 'default_bug_severity' ) );
     $t_bug_data->priority = HIGH;
     //gpc_get_int( 'priority', config_get( 'default_bug_priority' ) );
     $t_bug_data->projection = gpc_get_int('projection', config_get('default_bug_projection'));
     $t_bug_data->eta = gpc_get_int('eta', config_get('default_bug_eta'));
     $t_bug_data->resolution = OPEN;
     //gpc_get_string('resolution', config_get( 'default_bug_resolution' ) );
     $t_bug_data->status = NEW_;
     //gpc_get_string( 'status', config_get( 'bug_submit_status' ) );
     $t_bug_data->description = gpc_get_string('STACK_TRACE');
     //gpc_get_string( 'description' );
     $t_bug_data->summary = get_bug_summary_by_version(gpc_get_string('APP_VERSION_NAME', ''), $t_bug_data->description, $t_project_id);
     $t_bug_data->steps_to_reproduce = gpc_get_string('LOGCAT', "");
     $t_bug_data->additional_information = gpc_get_string('CRASH_CONFIGURATION', "");
     $t_bug_data->due_date = gpc_get_string('USER_CRASH_DATE', '');
     if (is_blank($t_bug_data->due_date)) {
         $t_bug_data->due_date = date_get_null();
     }
     $f_files = gpc_get_file('ufile', null);
     /** @todo (thraxisp) Note that this always returns a structure */
     $f_report_stay = gpc_get_bool('report_stay', false);
     $f_copy_notes_from_parent = gpc_get_bool('copy_notes_from_parent', false);
     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);
         # Produce an error if the field is required but wasn't posted
         if (!gpc_isset_custom_field($t_id, $t_def['type']) && $t_def['require_report']) {
             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'], NULL))) {
             error_parameters(lang_get_defaulted(custom_field_get_field($t_id, 'name')));
             trigger_error(ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR);
         }
     }
     # Allow plugins to pre-process bug data
     $t_bug_data = event_signal('EVENT_REPORT_BUG_DATA', $t_bug_data);
     # Ensure that resolved bugs have a handler
     if ($t_bug_data->handler_id == NO_USER && $t_bug_data->status >= config_get('bug_resolved_status_threshold')) {
         $t_bug_data->handler_id = $this->get_user_id();
     }
     # Create the bug
     $t_bug_id = $t_bug_data->create();
     # Mark the added issue as visited so that it appears on the last visited list.
     last_visited_issue($t_bug_id);
     # Handle the file upload
     if ($f_files != null) {
         $t_files = helper_array_transpose($f_files);
         if ($t_files != null) {
             foreach ($t_files as $t_file) {
                 if (!empty($t_file['name'])) {
                     file_add($t_bug_id, $t_file, 'bug');
                 }
             }
         }
     }
     # 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']), false)) {
             error_parameters(lang_get_defaulted(custom_field_get_field($t_id, 'name')));
             trigger_error(ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR);
         }
     }
     $f_master_bug_id = gpc_get_int('m_id', 0);
     $f_rel_type = gpc_get_int('rel_type', -1);
     if ($f_master_bug_id > 0) {
         # it's a child generation... let's create the relationship and add some lines in the history
         # update master bug last updated
         bug_update_date($f_master_bug_id);
         # Add log line to record the cloning action
         history_log_event_special($t_bug_id, BUG_CREATED_FROM, '', $f_master_bug_id);
         history_log_event_special($f_master_bug_id, BUG_CLONED_TO, '', $t_bug_id);
         if ($f_rel_type >= 0) {
             # Add the relationship
             relationship_add($t_bug_id, $f_master_bug_id, $f_rel_type);
             # Add log line to the history (both issues)
             history_log_event_special($f_master_bug_id, BUG_ADD_RELATIONSHIP, relationship_get_complementary_type($f_rel_type), $t_bug_id);
             history_log_event_special($t_bug_id, BUG_ADD_RELATIONSHIP, $f_rel_type, $f_master_bug_id);
             # update relationship target bug last updated
             bug_update_date($t_bug_id);
             # Send the email notification
             email_relationship_added($f_master_bug_id, $t_bug_id, relationship_get_complementary_type($f_rel_type));
         }
         # copy notes from parent
         if ($f_copy_notes_from_parent) {
             $t_parent_bugnotes = bugnote_get_all_bugnotes($f_master_bug_id);
             foreach ($t_parent_bugnotes as $t_parent_bugnote) {
                 $t_private = $t_parent_bugnote->view_state == VS_PRIVATE;
                 bugnote_add($t_bug_id, $t_parent_bugnote->note, $t_parent_bugnote->time_tracking, $t_private, $t_parent_bugnote->note_type, $t_parent_bugnote->note_attr, $t_parent_bugnote->reporter_id, FALSE, FALSE);
             }
         }
     }
     helper_call_custom_function('issue_create_notify', array($t_bug_id));
     # Allow plugins to post-process bug data with the new bug ID
     event_signal('EVENT_REPORT_BUG', array($t_bug_data, $t_bug_id));
     email_new_bug($t_bug_id);
     // log status and resolution changes if they differ from the default
     if ($t_bug_data->status != config_get('bug_submit_status')) {
         history_log_event($t_bug_id, 'status', config_get('bug_submit_status'));
     }
     if ($t_bug_data->resolution != config_get('default_bug_resolution')) {
         history_log_event($t_bug_id, 'resolution', config_get('default_bug_resolution'));
     }
     return $t_bug_id;
 }
Пример #5
0
function mci_file_add($p_id, $p_name, $p_content, $p_file_type, $p_table, $p_title = '', $p_desc = '', $p_user_id = null)
{
    if (!file_type_check($p_name)) {
        return new soap_fault('Client', '', 'File type not allowed.');
    }
    if (!file_is_name_unique($p_name, $p_id)) {
        return new soap_fault('Client', '', 'Duplicate filename.');
    }
    $t_file_size = strlen($p_content);
    $t_max_file_size = (int) min(ini_get_number('upload_max_filesize'), ini_get_number('post_max_size'), config_get('max_file_size'));
    if ($t_file_size > $t_max_file_size) {
        return new soap_fault('Client', '', 'File is too big.');
    }
    if ('bug' == $p_table) {
        $t_project_id = bug_get_field($p_id, 'project_id');
        $t_issue_id = bug_format_id($p_id);
    } else {
        $t_project_id = $p_id;
        $t_issue_id = 0;
    }
    # prepare variables for insertion
    $c_issue_id = db_prepare_int($t_issue_id);
    $c_project_id = db_prepare_int($t_project_id);
    $c_file_type = db_prepare_string($p_file_type);
    $c_title = db_prepare_string($p_title);
    $c_desc = db_prepare_string($p_desc);
    if ($p_user_id === null) {
        $c_user_id = auth_get_current_user_id();
    } else {
        $c_user_id = (int) $p_user_id;
    }
    if ($t_project_id == ALL_PROJECTS) {
        $t_file_path = config_get('absolute_path_default_upload_folder');
    } else {
        $t_file_path = project_get_field($t_project_id, 'file_path');
        if ($t_file_path == '') {
            $t_file_path = config_get('absolute_path_default_upload_folder');
        }
    }
    $c_file_path = db_prepare_string($t_file_path);
    $c_new_file_name = db_prepare_string($p_name);
    $t_file_hash = $t_issue_id;
    $t_disk_file_name = $t_file_path . file_generate_unique_name($t_file_hash . '-' . $p_name, $t_file_path);
    $c_disk_file_name = db_prepare_string($t_disk_file_name);
    $t_file_size = strlen($p_content);
    $c_file_size = db_prepare_int($t_file_size);
    $t_method = config_get('file_upload_method');
    switch ($t_method) {
        case FTP:
        case DISK:
            if (!file_exists($t_file_path) || !is_dir($t_file_path) || !is_writable($t_file_path) || !is_readable($t_file_path)) {
                return new soap_fault('Server', '', "Upload folder '{$t_file_path}' doesn't exist.");
            }
            file_ensure_valid_upload_path($t_file_path);
            if (!file_exists($t_disk_file_name)) {
                mci_file_write_local($t_disk_file_name, $p_content);
                if (FTP == $t_method) {
                    $conn_id = file_ftp_connect();
                    file_ftp_put($conn_id, $t_disk_file_name, $t_disk_file_name);
                    file_ftp_disconnect($conn_id);
                    file_delete_local($t_disk_file_name);
                } else {
                    chmod($t_disk_file_name, config_get('attachments_file_permissions'));
                }
                $c_content = "''";
            }
            break;
        case DATABASE:
            $c_content = db_prepare_binary_string($p_content);
            break;
    }
    $t_file_table = db_get_table($p_table . '_file');
    $c_id = 'bug' == $p_table ? $c_issue_id : $c_project_id;
    $query = "INSERT INTO {$t_file_table}\n\t\t\t(" . $p_table . "_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content, user_id)\n\t\tVALUES\n\t\t\t({$c_id}, '{$c_title}', '{$c_desc}', '{$c_disk_file_name}', '{$c_new_file_name}', '{$c_file_path}', {$c_file_size}, '{$c_file_type}', '" . db_now() . "', {$c_content}, {$c_user_id})";
    db_query($query);
    # get attachment id
    $t_attachment_id = db_insert_id($t_file_table);
    if ('bug' == $p_table) {
        # updated the last_updated date
        $result = bug_update_date($c_issue_id);
        # log new bug
        history_log_event_special($c_issue_id, FILE_ADDED, $c_new_file_name);
    }
    return $t_attachment_id;
}
Пример #6
0
    }
    # check if there is other relationship between the bugs...
    $t_old_id_relationship = relationship_same_type_exists($f_src_bug_id, $f_dest_bug_id, $f_rel_type);
    if ($t_old_id_relationship == -1) {
        # the relationship type is exactly the same of the new one. No sense to proceed
        trigger_error(ERROR_RELATIONSHIP_ALREADY_EXISTS, ERROR);
    } else {
        if ($t_old_id_relationship > 0) {
            # there is already a relationship between them -> we have to update it and not to add a new one
            helper_ensure_confirmed(lang_get('replace_relationship_sure_msg'), lang_get('replace_relationship_button'));
            # Update the relationship
            relationship_update($t_old_id_relationship, $f_src_bug_id, $f_dest_bug_id, $f_rel_type);
            # Add log line to the history (both bugs)
            history_log_event_special($f_src_bug_id, BUG_REPLACE_RELATIONSHIP, $f_rel_type, $f_dest_bug_id);
            history_log_event_special($f_dest_bug_id, BUG_REPLACE_RELATIONSHIP, relationship_get_complementary_type($f_rel_type), $f_src_bug_id);
        } else {
            # Add the new relationship
            relationship_add($f_src_bug_id, $f_dest_bug_id, $f_rel_type);
            # Add log line to the history (both bugs)
            history_log_event_special($f_src_bug_id, BUG_ADD_RELATIONSHIP, $f_rel_type, $f_dest_bug_id);
            history_log_event_special($f_dest_bug_id, BUG_ADD_RELATIONSHIP, relationship_get_complementary_type($f_rel_type), $f_src_bug_id);
        }
    }
    # update bug last updated (just for the src bug)
    bug_update_date($f_src_bug_id);
    # send email notification to the users addressed by both the bugs
    email_relationship_added($f_src_bug_id, $f_dest_bug_id, $f_rel_type);
    email_relationship_added($f_dest_bug_id, $f_src_bug_id, relationship_get_complementary_type($f_rel_type));
}
form_security_purge('bug_relationship_add');
print_header_redirect_view($f_src_bug_id);
Пример #7
0
/**
 * Add a file to the system using the configured storage method
 *
 * @param integer $p_bug_id          The bug id (should be 0 when adding project doc).
 * @param array   $p_file            The uploaded file info, as retrieved from gpc_get_file().
 * @param string  $p_table           Either 'bug' or 'project' depending on attachment type.
 * @param string  $p_title           File title.
 * @param string  $p_desc            File description.
 * @param integer $p_user_id         User id (defaults to current user).
 * @param integer $p_date_added      Date added.
 * @param boolean $p_skip_bug_update Skip bug last modification update (useful when importing bug attachments).
 * @return void
 */
function file_add($p_bug_id, array $p_file, $p_table = 'bug', $p_title = '', $p_desc = '', $p_user_id = null, $p_date_added = 0, $p_skip_bug_update = false)
{
    file_ensure_uploaded($p_file);
    $t_file_name = $p_file['name'];
    $t_tmp_file = $p_file['tmp_name'];
    if (!file_type_check($t_file_name)) {
        trigger_error(ERROR_FILE_NOT_ALLOWED, ERROR);
    }
    $t_org_filename = $t_file_name;
    $t_suffix_id = 1;
    while (!file_is_name_unique($t_file_name, $p_bug_id)) {
        $t_suffix_id++;
        $t_dot_index = strripos($t_org_filename, '.');
        if ($t_dot_index === false) {
            $t_file_name = $t_org_filename . '-' . $t_suffix_id;
        } else {
            $t_extension = substr($t_org_filename, $t_dot_index, strlen($t_org_filename) - $t_dot_index);
            $t_file_name = substr($t_org_filename, 0, $t_dot_index) . '-' . $t_suffix_id . $t_extension;
        }
    }
    antispam_check();
    $t_file_size = filesize($t_tmp_file);
    if (0 == $t_file_size) {
        trigger_error(ERROR_FILE_NO_UPLOAD_FAILURE, ERROR);
    }
    $t_max_file_size = (int) min(ini_get_number('upload_max_filesize'), ini_get_number('post_max_size'), config_get('max_file_size'));
    if ($t_file_size > $t_max_file_size) {
        trigger_error(ERROR_FILE_TOO_BIG, ERROR);
    }
    if ('bug' == $p_table) {
        $t_project_id = bug_get_field($p_bug_id, 'project_id');
        $t_id = (int) $p_bug_id;
    } else {
        $t_project_id = helper_get_current_project();
        $t_id = $t_project_id;
    }
    if ($p_user_id === null) {
        $p_user_id = auth_get_current_user_id();
    }
    if ($p_date_added <= 0) {
        $p_date_added = db_now();
    }
    if ($t_project_id == ALL_PROJECTS) {
        $t_file_path = config_get('absolute_path_default_upload_folder');
    } else {
        $t_file_path = project_get_field($t_project_id, 'file_path');
        if (is_blank($t_file_path)) {
            $t_file_path = config_get('absolute_path_default_upload_folder');
        }
    }
    $t_unique_name = file_generate_unique_name($t_file_path);
    $t_method = config_get('file_upload_method');
    switch ($t_method) {
        case DISK:
            file_ensure_valid_upload_path($t_file_path);
            $t_disk_file_name = $t_file_path . $t_unique_name;
            if (!file_exists($t_disk_file_name)) {
                if (!move_uploaded_file($t_tmp_file, $t_disk_file_name)) {
                    trigger_error(ERROR_FILE_MOVE_FAILED, ERROR);
                }
                chmod($t_disk_file_name, config_get('attachments_file_permissions'));
                $c_content = '';
            } else {
                trigger_error(ERROR_FILE_DUPLICATE, ERROR);
            }
            break;
        case DATABASE:
            $c_content = db_prepare_binary_string(fread(fopen($t_tmp_file, 'rb'), $t_file_size));
            $t_file_path = '';
            break;
        default:
            trigger_error(ERROR_GENERIC, ERROR);
    }
    $t_file_table = db_get_table($p_table . '_file');
    $t_id_col = $p_table . '_id';
    $t_param = array($t_id_col => $t_id, 'title' => $p_title, 'description' => $p_desc, 'diskfile' => $t_unique_name, 'filename' => $t_file_name, 'folder' => $t_file_path, 'filesize' => $t_file_size, 'file_type' => $p_file['type'], 'date_added' => $p_date_added, 'user_id' => (int) $p_user_id);
    # Oracle has to update BLOBs separately
    if (!db_is_oracle()) {
        $t_param['content'] = $c_content;
    }
    $t_query_param = db_param();
    for ($i = 1; $i < count($t_param); $i++) {
        $t_query_param .= ', ' . db_param();
    }
    $t_query = 'INSERT INTO ' . $t_file_table . '
		( ' . implode(', ', array_keys($t_param)) . ' )
	VALUES
		( ' . $t_query_param . ' )';
    db_query($t_query, array_values($t_param));
    if (db_is_oracle()) {
        db_update_blob($t_file_table, 'content', $c_content, "diskfile='{$t_unique_name}'");
    }
    if ('bug' == $p_table) {
        # update the last_updated date
        if (!$p_skip_bug_update) {
            bug_update_date($p_bug_id);
        }
        # log file added to bug history
        history_log_event_special($p_bug_id, FILE_ADDED, $t_file_name);
    }
}
Пример #8
0
/**
 * Add a file to the system using the configured storage method
 *
 * @param integer $p_bug_id          The bug id (should be 0 when adding project doc).
 * @param array   $p_file            The uploaded file info, as retrieved from gpc_get_file().
 * @param string  $p_table           Either 'bug' or 'project' depending on attachment type.
 * @param string  $p_title           File title.
 * @param string  $p_desc            File description.
 * @param integer $p_user_id         User id (defaults to current user).
 * @param integer $p_date_added      Date added.
 * @param boolean $p_skip_bug_update Skip bug last modification update (useful when importing bug attachments).
 * @return void
 */
function file_add($p_bug_id, array $p_file, $p_table = 'bug', $p_title = '', $p_desc = '', $p_user_id = null, $p_date_added = 0, $p_skip_bug_update = false)
{
    file_ensure_uploaded($p_file);
    $t_file_name = $p_file['name'];
    $t_tmp_file = $p_file['tmp_name'];
    if (!file_type_check($t_file_name)) {
        trigger_error(ERROR_FILE_NOT_ALLOWED, ERROR);
    }
    if (!file_is_name_unique($t_file_name, $p_bug_id)) {
        trigger_error(ERROR_FILE_DUPLICATE, ERROR);
    }
    $t_file_size = filesize($t_tmp_file);
    if (0 == $t_file_size) {
        trigger_error(ERROR_FILE_NO_UPLOAD_FAILURE, ERROR);
    }
    $t_max_file_size = (int) min(ini_get_number('upload_max_filesize'), ini_get_number('post_max_size'), config_get('max_file_size'));
    if ($t_file_size > $t_max_file_size) {
        trigger_error(ERROR_FILE_TOO_BIG, ERROR);
    }
    if ('bug' == $p_table) {
        $t_project_id = bug_get_field($p_bug_id, 'project_id');
        $t_id = (int) $p_bug_id;
        $t_bug_id = bug_format_id($p_bug_id);
    } else {
        $t_project_id = helper_get_current_project();
        $t_id = $t_project_id;
        $t_bug_id = 0;
    }
    if ($p_user_id === null) {
        $p_user_id = auth_get_current_user_id();
    }
    if ($p_date_added <= 0) {
        $p_date_added = db_now();
    }
    if ($t_project_id == ALL_PROJECTS) {
        $t_file_path = config_get('absolute_path_default_upload_folder');
    } else {
        $t_file_path = project_get_field($t_project_id, 'file_path');
        if (is_blank($t_file_path)) {
            $t_file_path = config_get('absolute_path_default_upload_folder');
        }
    }
    $t_unique_name = file_generate_unique_name($t_file_path);
    $t_method = config_get('file_upload_method');
    switch ($t_method) {
        case DISK:
            file_ensure_valid_upload_path($t_file_path);
            $t_disk_file_name = $t_file_path . $t_unique_name;
            if (!file_exists($t_disk_file_name)) {
                if (!move_uploaded_file($t_tmp_file, $t_disk_file_name)) {
                    trigger_error(ERROR_FILE_MOVE_FAILED, ERROR);
                }
                chmod($t_disk_file_name, config_get('attachments_file_permissions'));
                $c_content = '';
            } else {
                trigger_error(ERROR_FILE_DUPLICATE, ERROR);
            }
            break;
        case DATABASE:
            $c_content = db_prepare_binary_string(fread(fopen($t_tmp_file, 'rb'), $t_file_size));
            $t_file_path = '';
            break;
        default:
            trigger_error(ERROR_GENERIC, ERROR);
    }
    $t_file_table = db_get_table($p_table . '_file');
    $t_id_col = $p_table . '_id';
    $t_query = 'INSERT INTO ' . $t_file_table . ' ( ' . $t_id_col . ', title, description, diskfile, filename, folder,
		filesize, file_type, date_added, user_id )
	VALUES
		( ' . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ' )';
    db_query($t_query, array($t_id, $p_title, $p_desc, $t_unique_name, $t_file_name, $t_file_path, $t_file_size, $p_file['type'], $p_date_added, (int) $p_user_id));
    $t_attachment_id = db_insert_id($t_file_table);
    if (db_is_oracle()) {
        db_update_blob($t_file_table, 'content', $c_content, 'diskfile=\'$t_unique_name\'');
    } else {
        $t_query = 'UPDATE ' . $t_file_table . ' SET content=' . db_param() . ' WHERE id = ' . db_param();
        db_query($t_query, array($c_content, $t_attachment_id));
    }
    if ('bug' == $p_table) {
        # update the last_updated date
        if (!$p_skip_bug_update) {
            bug_update_date($p_bug_id);
        }
        # log file added to bug history
        history_log_event_special($p_bug_id, FILE_ADDED, $t_file_name);
    }
}
Пример #9
0
/**
 * Add a file
 * @param integer $p_id        File id.
 * @param string  $p_name      File name.
 * @param string  $p_content   File content to write.
 * @param string  $p_file_type File type.
 * @param string  $p_table     Database table name.
 * @param string  $p_title     Title.
 * @param string  $p_desc      Description.
 * @param string  $p_user_id   User id.
 * @return mixed
 */
function mci_file_add($p_id, $p_name, $p_content, $p_file_type, $p_table, $p_title = '', $p_desc = '', $p_user_id = null)
{
    if (!file_type_check($p_name)) {
        return SoapObjectsFactory::newSoapFault('Client', 'File type not allowed.');
    }
    if (!file_is_name_unique($p_name, $p_id)) {
        return SoapObjectsFactory::newSoapFault('Client', 'Duplicate filename.');
    }
    $t_file_size = strlen($p_content);
    $t_max_file_size = (int) min(ini_get_number('upload_max_filesize'), ini_get_number('post_max_size'), config_get('max_file_size'));
    if ($t_file_size > $t_max_file_size) {
        return SoapObjectsFactory::newSoapFault('Client', 'File is too big.');
    }
    if ('bug' == $p_table) {
        $t_project_id = bug_get_field($p_id, 'project_id');
        $t_id = (int) $p_id;
        $t_issue_id = bug_format_id($p_id);
    } else {
        $t_project_id = $p_id;
        $t_id = $t_project_id;
        $t_issue_id = 0;
    }
    if ($p_user_id === null) {
        $p_user_id = auth_get_current_user_id();
    }
    if ($t_project_id == ALL_PROJECTS) {
        $t_file_path = config_get('absolute_path_default_upload_folder');
    } else {
        $t_file_path = project_get_field($t_project_id, 'file_path');
        if (is_blank($t_file_path)) {
            $t_file_path = config_get('absolute_path_default_upload_folder');
        }
    }
    $t_unique_name = file_generate_unique_name($t_file_path);
    $t_disk_file_name = $t_file_path . $t_unique_name;
    $t_method = config_get('file_upload_method');
    switch ($t_method) {
        case DISK:
            if (!file_exists($t_file_path) || !is_dir($t_file_path) || !is_writable($t_file_path) || !is_readable($t_file_path)) {
                return SoapObjectsFactory::newSoapFault('Server', 'Upload folder \'' . $t_file_path . '\' doesn\'t exist.');
            }
            file_ensure_valid_upload_path($t_file_path);
            if (!file_exists($t_disk_file_name)) {
                mci_file_write_local($t_disk_file_name, $p_content);
                chmod($t_disk_file_name, config_get('attachments_file_permissions'));
                $c_content = "''";
            }
            break;
        case DATABASE:
            $c_content = db_prepare_binary_string($p_content);
            $t_file_path = '';
            break;
    }
    $t_file_table = db_get_table($p_table . '_file');
    $t_id_col = $p_table . '_id';
    $t_param = array($t_id_col => $t_id, 'title' => $p_title, 'description' => $p_desc, 'diskfile' => $t_unique_name, 'filename' => $p_name, 'folder' => $t_file_path, 'filesize' => $t_file_size, 'file_type' => $p_file_type, 'date_added' => db_now(), 'user_id' => (int) $p_user_id);
    # Oracle has to update BLOBs separately
    if (!db_is_oracle()) {
        $t_param['content'] = $c_content;
    }
    $t_query_param = db_param();
    for ($i = 1; $i < count($t_param); $i++) {
        $t_query_param .= ', ' . db_param();
    }
    $t_query = 'INSERT INTO ' . $t_file_table . '
		( ' . implode(', ', array_keys($t_param)) . ' )
	VALUES
		( ' . $t_query_param . ' )';
    db_query($t_query, array_values($t_param));
    # get attachment id
    $t_attachment_id = db_insert_id($t_file_table);
    if (db_is_oracle()) {
        db_update_blob($t_file_table, 'content', $c_content, "diskfile='{$t_unique_name}'");
    }
    if ('bug' == $p_table) {
        # bump the last_updated date
        bug_update_date($t_issue_id);
        # add history entry
        history_log_event_special($t_issue_id, FILE_ADDED, $p_name);
    }
    return $t_attachment_id;
}
Пример #10
0
/**
 * Detach a tag from a bug.
 * @param integer Tag ID
 * @param integer Bug ID
 * @param boolean Add history entries to bug
 * @param integer User Id (or null for current logged in user)	 
 */
function tag_bug_detach($p_tag_id, $p_bug_id, $p_add_history = true, $p_user_id = null)
{
    if ($p_user_id === null) {
        $t_user_id = auth_get_current_user_id();
    } else {
        $t_user_id = $p_user_id;
    }
    if (!tag_bug_is_attached($p_tag_id, $p_bug_id)) {
        trigger_error(TAG_NOT_ATTACHED, ERROR);
    }
    $t_tag_row = tag_bug_get_row($p_tag_id, $p_bug_id);
    if ($t_user_id == tag_get_field($p_tag_id, 'user_id') || $t_user_id == $t_tag_row['user_id']) {
        $t_detach_level = config_get('tag_detach_own_threshold');
    } else {
        $t_detach_level = config_get('tag_detach_threshold');
    }
    access_ensure_bug_level($t_detach_level, $p_bug_id, $t_user_id);
    $c_tag_id = db_prepare_int($p_tag_id);
    $c_bug_id = db_prepare_int($p_bug_id);
    $t_bug_tag_table = config_get('mantis_bug_tag_table');
    $query = "DELETE FROM {$t_bug_tag_table} \r\n\t\t\t\t\tWHERE tag_id='{$c_tag_id}' AND bug_id='{$c_bug_id}'";
    db_query($query);
    if ($p_add_history) {
        $t_tag_name = tag_get_field($p_tag_id, 'name');
        history_log_event_special($p_bug_id, TAG_DETACHED, $t_tag_name);
    }
    return true;
}
Пример #11
0
function bugnote_set_view_state($p_bugnote_id, $p_private)
{
    $c_bugnote_id = db_prepare_int($p_bugnote_id);
    $t_bug_id = bugnote_get_field($p_bugnote_id, 'bug_id');
    if ($p_private) {
        $t_view_state = VS_PRIVATE;
    } else {
        $t_view_state = VS_PUBLIC;
    }
    $t_bugnote_table = config_get('mantis_bugnote_table');
    # update view_state
    $query = "UPDATE {$t_bugnote_table}\r\n\t\t          \tSET view_state='{$t_view_state}'\r\n\t\t          \tWHERE id='{$c_bugnote_id}'";
    db_query($query);
    history_log_event_special($t_bug_id, BUGNOTE_STATE_CHANGED, bugnote_format_id($t_view_state), $p_bugnote_id);
    return true;
}
Пример #12
0
function sponsorship_update_paid($p_sponsorship_id, $p_paid)
{
    $c_sponsorship_id = db_prepare_int($p_sponsorship_id);
    $t_sponsorship = sponsorship_get($c_sponsorship_id);
    $c_paid = db_prepare_int($p_paid);
    $t_sponsorship_table = config_get('mantis_sponsorship_table');
    $query = "UPDATE {$t_sponsorship_table}\r\n\t\t\t\t  SET last_updated= " . db_now() . ", paid={$c_paid}\r\n\t\t\t\t  WHERE id='{$c_sponsorship_id}'";
    db_query($query);
    history_log_event_special($t_sponsorship->bug_id, BUG_PAID_SPONSORSHIP, $t_sponsorship->user_id, $p_paid);
    sponsorship_clear_cache($p_sponsorship_id);
    return true;
}
Пример #13
0
/**
 * Delete the relationship with the specified target id.
 *
 * @param string $p_username  The name of the user trying to add a note to an issue.
 * @param string $p_password  The password of the user.
 * @param integer $p_issue_id  The id of the source issue for the relationship
 * @param integer $p_relationship_id  The id of relationship to delete.
 * @return true: success, false: failure
 */
function mc_issue_relationship_delete($p_username, $p_password, $p_issue_id, $p_relationship_id)
{
    $t_user_id = mci_check_login($p_username, $p_password);
    if ($t_user_id === false) {
        return new soap_fault('Client', '', 'Access Denied');
    }
    $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');
    }
    # user has access to update the bug...
    if (!access_has_bug_level(config_get('update_bug_threshold'), $p_issue_id, $t_user_id)) {
        return new soap_fault('Client', '', "Active user does not have access level required to remove a relationship from this issue.");
    }
    # bug is not read-only...
    if (bug_is_readonly($p_issue_id)) {
        return new soap_fault('Client', '', "Issue '{$p_issue_id}' is readonly.");
    }
    # retrieve the destination bug of the relationship
    $t_dest_issue_id = relationship_get_linked_bug_id($p_relationship_id, $p_issue_id);
    # user can access to the related bug at least as viewer, if it's exist...
    if (bug_exists($t_dest_issue_id)) {
        if (!access_has_bug_level(VIEWER, $t_dest_issue_id, $t_user_id)) {
            return new soap_fault('Client', '', "The issue '{$t_dest_issue_id}' requires higher access level.");
        }
    }
    $t_bug_relationship_data = relationship_get($p_relationship_id);
    $t_rel_type = $t_bug_relationship_data->type;
    # delete relationship from the DB
    relationship_delete($p_relationship_id);
    # update bug last updated (just for the src bug)
    bug_update_date($p_issue_id);
    # set the rel_type for both bug and dest_bug based on $t_rel_type and on who is the dest bug
    if ($p_issue_id == $t_bug_relationship_data->src_bug_id) {
        $t_bug_rel_type = $t_rel_type;
        $t_dest_bug_rel_type = relationship_get_complementary_type($t_rel_type);
    } else {
        $t_bug_rel_type = relationship_get_complementary_type($t_rel_type);
        $t_dest_bug_rel_type = $t_rel_type;
    }
    # send email and update the history for the src issue
    history_log_event_special($p_issue_id, BUG_DEL_RELATIONSHIP, $t_bug_rel_type, $t_dest_issue_id);
    email_relationship_deleted($p_issue_id, $t_dest_issue_id, $t_bug_rel_type);
    if (bug_exists($t_dest_issue_id)) {
        # send email and update the history for the dest issue
        history_log_event_special($t_dest_issue_id, BUG_DEL_RELATIONSHIP, $t_dest_bug_rel_type, $p_issue_id);
        email_relationship_deleted($t_dest_issue_id, $p_issue_id, $t_dest_bug_rel_type);
    }
    return true;
}
Пример #14
0
function bug_unmonitor($p_bug_id, $p_user_id)
{
    $c_bug_id = db_prepare_int($p_bug_id);
    $c_user_id = db_prepare_int($p_user_id);
    $t_bug_monitor_table = config_get('mantis_bug_monitor_table');
    # Delete monitoring record
    $query = "DELETE " . "FROM {$t_bug_monitor_table} " . "WHERE bug_id = '{$c_bug_id}'";
    if ($p_user_id !== null) {
        $query .= " AND user_id = '{$c_user_id}'";
    }
    db_query($query);
    # log new un-monitor action
    history_log_event_special($p_bug_id, BUG_UNMONITOR, $p_user_id);
    return true;
}
Пример #15
0
/**
 * updates the paid field
 * @param integer $p_sponsorship_id The sponsorship identifier to update.
 * @param integer $p_paid           The value to set to paid database field to.
 * @return boolean
 */
function sponsorship_update_paid($p_sponsorship_id, $p_paid)
{
    $t_sponsorship = sponsorship_get($p_sponsorship_id);
    $t_query = 'UPDATE {sponsorship} SET last_updated=' . db_param() . ', paid=' . db_param() . ' WHERE id=' . db_param();
    db_query($t_query, array(db_now(), (int) $p_paid, (int) $p_sponsorship_id));
    history_log_event_special($t_sponsorship->bug_id, BUG_PAID_SPONSORSHIP, $t_sponsorship->user_id, $p_paid);
    sponsorship_clear_cache($p_sponsorship_id);
    return true;
}
Пример #16
0
/**
 * Add a file to the system using the configured storage method
 *
 * @param integer $p_bug_id the bug id
 * @param array $p_file the uploaded file info, as retrieved from gpc_get_file()
 */
function file_add($p_bug_id, $p_file, $p_table = 'bug', $p_title = '', $p_desc = '', $p_user_id = null)
{
    file_ensure_uploaded($p_file);
    $t_file_name = $p_file['name'];
    $t_tmp_file = $p_file['tmp_name'];
    if (!file_type_check($t_file_name)) {
        trigger_error(ERROR_FILE_NOT_ALLOWED, ERROR);
    }
    if (!file_is_name_unique($t_file_name, $p_bug_id)) {
        trigger_error(ERROR_FILE_DUPLICATE, ERROR);
    }
    if ('bug' == $p_table) {
        $t_project_id = bug_get_field($p_bug_id, 'project_id');
        $t_bug_id = bug_format_id($p_bug_id);
    } else {
        $t_project_id = helper_get_current_project();
        $t_bug_id = 0;
    }
    if ($p_user_id === null) {
        $c_user_id = auth_get_current_user_id();
    } else {
        $c_user_id = (int) $p_user_id;
    }
    # prepare variables for insertion
    $c_bug_id = db_prepare_int($p_bug_id);
    $c_project_id = db_prepare_int($t_project_id);
    $c_file_type = db_prepare_string($p_file['type']);
    $c_title = db_prepare_string($p_title);
    $c_desc = db_prepare_string($p_desc);
    if ($t_project_id == ALL_PROJECTS) {
        $t_file_path = config_get('absolute_path_default_upload_folder');
    } else {
        $t_file_path = project_get_field($t_project_id, 'file_path');
        if (is_blank($t_file_path)) {
            $t_file_path = config_get('absolute_path_default_upload_folder');
        }
    }
    $c_file_path = db_prepare_string($t_file_path);
    $c_new_file_name = db_prepare_string($t_file_name);
    $t_file_hash = 'bug' == $p_table ? $t_bug_id : config_get('document_files_prefix') . '-' . $t_project_id;
    $t_unique_name = file_generate_unique_name($t_file_hash . '-' . $t_file_name, $t_file_path);
    $t_disk_file_name = $t_file_path . $t_unique_name;
    $c_unique_name = db_prepare_string($t_unique_name);
    $t_file_size = filesize($t_tmp_file);
    if (0 == $t_file_size) {
        trigger_error(ERROR_FILE_NO_UPLOAD_FAILURE, ERROR);
    }
    $t_max_file_size = (int) min(ini_get_number('upload_max_filesize'), ini_get_number('post_max_size'), config_get('max_file_size'));
    if ($t_file_size > $t_max_file_size) {
        trigger_error(ERROR_FILE_TOO_BIG, ERROR);
    }
    $c_file_size = db_prepare_int($t_file_size);
    $t_method = config_get('file_upload_method');
    switch ($t_method) {
        case FTP:
        case DISK:
            file_ensure_valid_upload_path($t_file_path);
            if (!file_exists($t_disk_file_name)) {
                if (FTP == $t_method) {
                    $conn_id = file_ftp_connect();
                    file_ftp_put($conn_id, $t_disk_file_name, $t_tmp_file);
                    file_ftp_disconnect($conn_id);
                }
                if (!move_uploaded_file($t_tmp_file, $t_disk_file_name)) {
                    trigger_error(ERROR_FILE_MOVE_FAILED, ERROR);
                }
                chmod($t_disk_file_name, config_get('attachments_file_permissions'));
                $c_content = "''";
            } else {
                trigger_error(ERROR_FILE_DUPLICATE, ERROR);
            }
            break;
        case DATABASE:
            $c_content = db_prepare_binary_string(fread(fopen($t_tmp_file, 'rb'), $t_file_size));
            break;
        default:
            trigger_error(ERROR_GENERIC, ERROR);
    }
    $t_file_table = db_get_table('mantis_' . $p_table . '_file_table');
    $c_id = 'bug' == $p_table ? $c_bug_id : $c_project_id;
    $query = "INSERT INTO {$t_file_table}\n\t\t\t\t\t\t(" . $p_table . "_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content, user_id)\n\t\t\t\t\t  VALUES\n\t\t\t\t\t\t({$c_id}, '{$c_title}', '{$c_desc}', '{$c_unique_name}', '{$c_new_file_name}', '{$c_file_path}', {$c_file_size}, '{$c_file_type}', '" . db_now() . "', {$c_content}, {$c_user_id})";
    db_query($query);
    if ('bug' == $p_table) {
        # updated the last_updated date
        $result = bug_update_date($p_bug_id);
        # log new bug
        history_log_event_special($p_bug_id, FILE_ADDED, $t_file_name);
    }
}
Пример #17
0
if (bug_exists($t_dest_bug_id)) {
    if (!access_has_bug_level(VIEWER, $t_dest_bug_id)) {
        error_parameters($t_dest_bug_id);
        trigger_error(ERROR_RELATIONSHIP_ACCESS_LEVEL_TO_DEST_BUG_TOO_LOW, ERROR);
    }
}
helper_ensure_confirmed(lang_get('delete_relationship_sure_msg'), lang_get('delete_relationship_button'));
$t_bug_relationship_data = relationship_get($f_rel_id);
$t_rel_type = $t_bug_relationship_data->type;
# delete relationship from the DB
relationship_delete($f_rel_id);
# update bug last updated (just for the src bug)
bug_update_date($f_bug_id);
# set the rel_type for both bug and dest_bug based on $t_rel_type and on who is the dest bug
if ($f_bug_id == $t_bug_relationship_data->src_bug_id) {
    $t_bug_rel_type = $t_rel_type;
    $t_dest_bug_rel_type = relationship_get_complementary_type($t_rel_type);
} else {
    $t_bug_rel_type = relationship_get_complementary_type($t_rel_type);
    $t_dest_bug_rel_type = $t_rel_type;
}
# send email and update the history for the src issue
history_log_event_special($f_bug_id, BUG_DEL_RELATIONSHIP, $t_bug_rel_type, $t_dest_bug_id);
email_relationship_deleted($f_bug_id, $t_dest_bug_id, $t_bug_rel_type);
if (bug_exists($t_dest_bug_id)) {
    # send email and update the history for the dest issue
    history_log_event_special($t_dest_bug_id, BUG_DEL_RELATIONSHIP, $t_dest_bug_rel_type, $f_bug_id);
    email_relationship_deleted($t_dest_bug_id, $f_bug_id, $t_dest_bug_rel_type);
}
form_security_purge('bug_relationship_delete');
print_header_redirect_view($f_bug_id);
Пример #18
0
/**
 * Set the view state of the bugnote
 * @param integer $p_bugnote_id A bugnote identifier.
 * @param boolean $p_private    Whether bugnote should be set to private status.
 * @return boolean
 * @access public
 */
function bugnote_set_view_state($p_bugnote_id, $p_private)
{
    $t_bug_id = bugnote_get_field($p_bugnote_id, 'bug_id');
    if ($p_private) {
        $t_view_state = VS_PRIVATE;
    } else {
        $t_view_state = VS_PUBLIC;
    }
    $t_query = 'UPDATE {bugnote} SET view_state=' . db_param() . ' WHERE id=' . db_param();
    db_query($t_query, array($t_view_state, $p_bugnote_id));
    history_log_event_special($t_bug_id, BUGNOTE_STATE_CHANGED, $t_view_state, bugnote_format_id($p_bugnote_id));
    return true;
}
Пример #19
0
/**
 * Delete the relationship with the specified target id.
 *
 * @param string  $p_username        The name of the user trying to add a note to an issue.
 * @param string  $p_password        The password of the user.
 * @param integer $p_issue_id        The id of the source issue for the relationship.
 * @param integer $p_relationship_id The id of relationship to delete.
 * @return boolean true: success, false: failure
 */
function mc_issue_relationship_delete($p_username, $p_password, $p_issue_id, $p_relationship_id)
{
    global $g_project_override;
    $t_user_id = mci_check_login($p_username, $p_password);
    if ($t_user_id === false) {
        return mci_soap_fault_login_failed();
    }
    $t_project_id = bug_get_field($p_issue_id, 'project_id');
    $g_project_override = $t_project_id;
    if (!mci_has_readwrite_access($t_user_id, $t_project_id)) {
        return mci_soap_fault_access_denied($t_user_id);
    }
    # user has access to update the bug...
    if (!access_has_bug_level(config_get('update_bug_threshold'), $p_issue_id, $t_user_id)) {
        return mci_soap_fault_access_denied($t_user_id, 'Active user does not have access level required to remove a relationship from this issue.');
    }
    # bug is not read-only...
    if (bug_is_readonly($p_issue_id)) {
        return mci_soap_fault_access_denied($t_user_id, 'Issue \'' . $p_issue_id . '\' is readonly.');
    }
    # retrieve the destination bug of the relationship
    $t_dest_issue_id = relationship_get_linked_bug_id($p_relationship_id, $p_issue_id);
    # user can access to the related bug at least as viewer, if it's exist...
    if (bug_exists($t_dest_issue_id)) {
        if (!access_has_bug_level(config_get('view_bug_threshold', null, null, $t_project_id), $t_dest_issue_id, $t_user_id)) {
            return mci_soap_fault_access_denied($t_user_id, 'The issue \'' . $t_dest_issue_id . '\' requires higher access level.');
        }
    }
    $t_bug_relationship_data = relationship_get($p_relationship_id);
    $t_rel_type = $t_bug_relationship_data->type;
    # delete relationship from the DB
    log_event(LOG_WEBSERVICE, 'deleting relationship id \'' . $p_relationship_id . '\'');
    relationship_delete($p_relationship_id);
    # update bug last updated
    bug_update_date($p_issue_id);
    bug_update_date($t_dest_issue_id);
    # set the rel_type for both bug and dest_bug based on $t_rel_type and on who is the dest bug
    if ($p_issue_id == $t_bug_relationship_data->src_bug_id) {
        $t_bug_rel_type = $t_rel_type;
        $t_dest_bug_rel_type = relationship_get_complementary_type($t_rel_type);
    } else {
        $t_bug_rel_type = relationship_get_complementary_type($t_rel_type);
        $t_dest_bug_rel_type = $t_rel_type;
    }
    # send email and update the history for the src issue
    history_log_event_special($p_issue_id, BUG_DEL_RELATIONSHIP, $t_bug_rel_type, $t_dest_issue_id);
    email_relationship_deleted($p_issue_id, $t_dest_issue_id, $t_bug_rel_type);
    if (bug_exists($t_dest_issue_id)) {
        # send email and update the history for the dest issue
        history_log_event_special($t_dest_issue_id, BUG_DEL_RELATIONSHIP, $t_dest_bug_rel_type, $p_issue_id);
        email_relationship_deleted($t_dest_issue_id, $p_issue_id, $t_dest_bug_rel_type);
    }
    return true;
}
Пример #20
0
 private function add_bug(&$p_email, $p_overwrite_project_id = FALSE)
 {
     $this->show_memory_usage('Start add bug');
     //Merge References and In-Reply-To headers into one array
     $t_references = $p_email['References'];
     $t_references[] = $p_email['In-Reply-To'];
     if ($this->_mail_add_bugnotes) {
         $t_bug_id = $this->mail_is_a_bugnote($p_email['Subject'], $t_references);
     } else {
         $t_bug_id = FALSE;
     }
     if ($t_bug_id !== FALSE && !bug_is_readonly($t_bug_id)) {
         // @TODO@ Disabled for now until we find a good solution on how to handle the reporters possible lack of access permissions
         //			access_ensure_bug_level( config_get( 'add_bugnote_threshold' ), $f_bug_id );
         $t_description = $p_email['X-Mantis-Body'];
         $t_description = $this->identify_replies($t_description);
         $t_description = $this->strip_signature($t_description);
         $t_description = $this->add_additional_info('note', $p_email, $t_description);
         $t_project_id = bug_get_field($t_bug_id, 'project_id');
         ERP_set_temporary_overwrite('project_override', $t_project_id);
         # Event integration
         # Core mantis event already exists within bugnote_add function
         $t_description = event_signal('EVENT_ERP_BUGNOTE_DATA', $t_description, $t_bug_id);
         if (bug_is_resolved($t_bug_id)) {
             # Reopen issue and add a bug note
             bug_reopen($t_bug_id, $t_description);
         } elseif (!is_blank($t_description)) {
             # Add a bug note
             bugnote_add($t_bug_id, $t_description);
         }
     } elseif ($this->_mail_add_bug_reports) {
         // @TODO@ Disabled for now until we find a good solution on how to handle the reporters possible lack of access permissions
         //			access_ensure_project_level( config_get('report_bug_threshold' ) );
         $f_master_bug_id = $t_bug_id !== FALSE && bug_is_readonly($t_bug_id) ? $t_bug_id : 0;
         $this->fix_empty_fields($p_email);
         $t_project_id = $p_overwrite_project_id === FALSE ? $this->_mailbox['project_id'] : $p_overwrite_project_id;
         ERP_set_temporary_overwrite('project_override', $t_project_id);
         $t_bug_data = new BugData();
         $t_bug_data->build = '';
         $t_bug_data->platform = '';
         $t_bug_data->os = '';
         $t_bug_data->os_build = '';
         $t_bug_data->version = '';
         $t_bug_data->profile_id = 0;
         $t_bug_data->handler_id = 0;
         $t_bug_data->view_state = (int) config_get('default_bug_view_status');
         $t_bug_data->category_id = (int) $this->_mailbox['global_category_id'];
         $t_bug_data->reproducibility = (int) config_get('default_bug_reproducibility');
         $t_bug_data->severity = (int) config_get('default_bug_severity');
         $t_bug_data->priority = (int) ($this->_mail_use_bug_priority ? $p_email['Priority'] : config_get('default_bug_priority'));
         $t_bug_data->projection = (int) config_get('default_bug_projection');
         $t_bug_data->eta = (int) config_get('default_bug_eta');
         $t_bug_data->resolution = config_get('default_bug_resolution');
         $t_bug_data->status = config_get('bug_submit_status');
         $t_bug_data->summary = $p_email['Subject'];
         $t_description = $p_email['X-Mantis-Body'];
         $t_description = $this->strip_signature($t_description);
         $t_description = $this->add_additional_info('issue', $p_email, $t_description);
         $t_bug_data->description = $t_description;
         $t_bug_data->steps_to_reproduce = config_get('default_bug_steps_to_reproduce');
         $t_bug_data->additional_information = config_get('default_bug_additional_info');
         $t_bug_data->due_date = date_get_null();
         $t_bug_data->project_id = $t_project_id;
         $t_bug_data->reporter_id = $p_email['Reporter_id'];
         // This function might do stuff that EmailReporting cannot handle. Disabled
         //helper_call_custom_function( 'issue_create_validate', array( $t_bug_data ) );
         // @TODO@ Disabled for now but possibly needed for other future features
         # 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 );
         
         				# Produce an error if the field is required but wasn't posted
         				if ( !gpc_isset_custom_field( $t_id, $t_def['type'] ) &&
         					( $t_def['require_report'] ||
         						$t_def['type'] == CUSTOM_FIELD_TYPE_ENUM ||
         						$t_def['type'] == CUSTOM_FIELD_TYPE_LIST ||
         						$t_def['type'] == CUSTOM_FIELD_TYPE_MULTILIST ||
         						$t_def['type'] == CUSTOM_FIELD_TYPE_RADIO ) ) {
         					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'], NULL ) ) )
         				{
         					error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
         					trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR );
         				}
         			}*/
         # Allow plugins to pre-process bug data
         $t_bug_data = event_signal('EVENT_REPORT_BUG_DATA', $t_bug_data);
         $t_bug_data = event_signal('EVENT_ERP_REPORT_BUG_DATA', $t_bug_data);
         # Create the bug
         $t_bug_id = $t_bug_data->create();
         // @TODO@ Disabled for now but possibly needed for other future features
         # 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'], '' ), false ) ) {
         				{
         					error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
         					trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR );
         				}
         			}*/
         // Lets link a readonly already existing bug to the newly created one
         if ($f_master_bug_id > 0) {
             $f_rel_type = BUG_RELATED;
             # update master bug last updated
             bug_update_date($f_master_bug_id);
             # Add the relationship
             relationship_add($t_bug_id, $f_master_bug_id, $f_rel_type);
             # Add log line to the history (both issues)
             history_log_event_special($f_master_bug_id, BUG_ADD_RELATIONSHIP, relationship_get_complementary_type($f_rel_type), $t_bug_id);
             history_log_event_special($t_bug_id, BUG_ADD_RELATIONSHIP, $f_rel_type, $f_master_bug_id);
             # Send the email notification
             email_relationship_added($f_master_bug_id, $t_bug_id, relationship_get_complementary_type($f_rel_type));
         }
         helper_call_custom_function('issue_create_notify', array($t_bug_id));
         # Allow plugins to post-process bug data with the new bug ID
         event_signal('EVENT_REPORT_BUG', array($t_bug_data, $t_bug_id));
         email_new_bug($t_bug_id);
     } else {
         // Not allowed to add issues and not allowed / able to add notes. Need to stop processing
         $this->custom_error('Not allowed to create a new issue. Email ignored');
         return;
     }
     $this->custom_error('Reporter: ' . $p_email['Reporter_id'] . ' - ' . $p_email['From_parsed']['email'] . ' --> Issue ID: #' . $t_bug_id, FALSE);
     $this->show_memory_usage('Finished add bug');
     $this->show_memory_usage('Start processing attachments');
     # Add files
     if ($this->_allow_file_upload) {
         if (count($p_email['X-Mantis-Parts']) > 0) {
             $t_rejected_files = NULL;
             while ($t_part = array_shift($p_email['X-Mantis-Parts'])) {
                 $t_file_rejected = $this->add_file($t_bug_id, $t_part);
                 if ($t_file_rejected !== TRUE) {
                     $t_rejected_files .= $t_file_rejected;
                 }
             }
             if ($t_rejected_files !== NULL) {
                 $t_part = array('name' => 'Rejected files.txt', 'ctype' => 'text/plain', 'body' => 'List of rejected files' . "\n\n" . $t_rejected_files);
                 $t_reject_rejected_files = $this->add_file($t_bug_id, $t_part);
                 if ($t_reject_rejected_files !== TRUE) {
                     $t_part['body'] .= $t_reject_rejected_files;
                     $this->custom_error('Failed to add "' . $t_part['name'] . '" to the issue. See below for all errors.' . "\n" . $t_part['body']);
                 }
             }
         }
     }
     //Add the users in Cc and To list in mail header
     $this->add_monitors($t_bug_id, $p_email);
     //Add the message-id to the database
     $this->add_msg_id($t_bug_id, $p_email['Message-ID']);
     ERP_set_temporary_overwrite('project_override', NULL);
     $this->show_memory_usage('Finished processing attachments');
 }
Пример #21
0
/**
 * Set the view state of the bugnote
 * @param int $p_bugnote_id bugnote id
 * @param bool $p_private
 * @return bool
 * @access public
 */
function bugnote_set_view_state($p_bugnote_id, $p_private)
{
    $c_bugnote_id = db_prepare_int($p_bugnote_id);
    $t_bug_id = bugnote_get_field($p_bugnote_id, 'bug_id');
    if ($p_private) {
        $t_view_state = VS_PRIVATE;
    } else {
        $t_view_state = VS_PUBLIC;
    }
    $t_bugnote_table = db_get_table('mantis_bugnote_table');
    $query = "UPDATE {$t_bugnote_table}\n\t\t          \tSET view_state=" . db_param() . "\n\t\t          \tWHERE id=" . db_param();
    db_query_bound($query, array($t_view_state, $c_bugnote_id));
    history_log_event_special($t_bug_id, BUGNOTE_STATE_CHANGED, $t_view_state, bugnote_format_id($p_bugnote_id));
    return true;
}
Пример #22
0
/**
 * updates the paid field
 * @param int $p_sponsorship_id
 * @param int $p_paid
 * @return true
 */
function sponsorship_update_paid($p_sponsorship_id, $p_paid)
{
    $c_sponsorship_id = db_prepare_int($p_sponsorship_id);
    $t_sponsorship = sponsorship_get($c_sponsorship_id);
    $c_paid = db_prepare_int($p_paid);
    $t_sponsorship_table = db_get_table('sponsorship');
    $query = "UPDATE {$t_sponsorship_table}\n\t\t\t\t  SET last_updated= " . db_param() . ", paid=" . db_param() . "\n\t\t\t\t  WHERE id=" . db_param();
    db_query_bound($query, array(db_now(), $c_paid, $c_sponsorship_id));
    history_log_event_special($t_sponsorship->bug_id, BUG_PAID_SPONSORSHIP, $t_sponsorship->user_id, $p_paid);
    sponsorship_clear_cache($p_sponsorship_id);
    return true;
}
Пример #23
0
}
$f_master_bug_id = gpc_get_int('m_id', 0);
$f_rel_type = gpc_get_int('rel_type', -1);
if ($f_master_bug_id > 0) {
    # it's a child generation... let's create the relationship and add some lines in the history
    # update master bug last updated
    bug_update_date($f_master_bug_id);
    # Add log line to record the cloning action
    history_log_event_special($t_bug_id, BUG_CREATED_FROM, '', $f_master_bug_id);
    history_log_event_special($f_master_bug_id, BUG_CLONED_TO, '', $t_bug_id);
    if ($f_rel_type >= 0) {
        # Add the relationship
        relationship_add($t_bug_id, $f_master_bug_id, $f_rel_type);
        # Add log line to the history (both issues)
        history_log_event_special($f_master_bug_id, BUG_ADD_RELATIONSHIP, relationship_get_complementary_type($f_rel_type), $t_bug_id);
        history_log_event_special($t_bug_id, BUG_ADD_RELATIONSHIP, $f_rel_type, $f_master_bug_id);
        # update relationship target bug last updated
        bug_update_date($t_bug_id);
        # Send the email notification
        email_relationship_added($f_master_bug_id, $t_bug_id, relationship_get_complementary_type($f_rel_type));
    }
    # copy notes from parent
    if ($f_copy_notes_from_parent) {
        $t_parent_bugnotes = bugnote_get_all_bugnotes($f_master_bug_id);
        foreach ($t_parent_bugnotes as $t_parent_bugnote) {
            $t_private = $t_parent_bugnote->view_state == VS_PRIVATE;
            bugnote_add($t_bug_id, $t_parent_bugnote->note, $t_parent_bugnote->time_tracking, $t_private, $t_parent_bugnote->note_type, $t_parent_bugnote->note_attr, $t_parent_bugnote->reporter_id, FALSE, FALSE);
        }
    }
    # copy attachments from parent
    if ($f_copy_attachments_from_parent) {
Пример #24
0
 /**
  * Update a bug from the given data structure
  *  If the third parameter is true, also update the longer strings table
  * @param bool p_update_extended
  * @param bool p_bypass_email Default false, set to true to avoid generating emails (if sending elsewhere)
  * @return bool (always true)
  * @access public
  */
 function update($p_update_extended = false, $p_bypass_mail = false)
 {
     self::validate($p_update_extended);
     $c_bug_id = $this->id;
     if (is_blank($this->due_date)) {
         $this->due_date = date_get_null();
     }
     $t_old_data = bug_get($this->id, true);
     $t_bug_table = db_get_table('mantis_bug_table');
     # Update all fields
     # Ignore date_submitted and last_updated since they are pulled out
     #  as unix timestamps which could confuse the history log and they
     #  shouldn't get updated like this anyway.  If you really need to change
     #  them use bug_set_field()
     $query = "UPDATE {$t_bug_table}\n\t\t\t\t\tSET project_id=" . db_param() . ', reporter_id=' . db_param() . ",\n\t\t\t\t\t\thandler_id=" . db_param() . ', duplicate_id=' . db_param() . ",\n\t\t\t\t\t\tpriority=" . db_param() . ', severity=' . db_param() . ",\n\t\t\t\t\t\treproducibility=" . db_param() . ', status=' . db_param() . ",\n\t\t\t\t\t\tresolution=" . db_param() . ', projection=' . db_param() . ",\n\t\t\t\t\t\tcategory_id=" . db_param() . ', eta=' . db_param() . ",\n\t\t\t\t\t\tos=" . db_param() . ', os_build=' . db_param() . ",\n\t\t\t\t\t\tplatform=" . db_param() . ', version=' . db_param() . ",\n\t\t\t\t\t\tbuild=" . db_param() . ', fixed_in_version=' . db_param() . ',';
     $t_fields = array($this->project_id, $this->reporter_id, $this->handler_id, $this->duplicate_id, $this->priority, $this->severity, $this->reproducibility, $this->status, $this->resolution, $this->projection, $this->category_id, $this->eta, $this->os, $this->os_build, $this->platform, $this->version, $this->build, $this->fixed_in_version);
     $t_roadmap_updated = false;
     if (access_has_project_level(config_get('roadmap_update_threshold'))) {
         $query .= "\n\t\t\t\t\t\ttarget_version=" . db_param() . ",";
         $t_fields[] = $this->target_version;
         $t_roadmap_updated = true;
     }
     $query .= "\n\t\t\t\t\t\tview_state=" . db_param() . ",\n\t\t\t\t\t\tsummary=" . db_param() . ",\n\t\t\t\t\t\tsponsorship_total=" . db_param() . ",\n\t\t\t\t\t\tsticky=" . db_param() . ",\n\t\t\t\t\t\tdue_date=" . db_param() . "\n\t\t\t\t\tWHERE id=" . db_param();
     $t_fields[] = $this->view_state;
     $t_fields[] = $this->summary;
     $t_fields[] = $this->sponsorship_total;
     $t_fields[] = (bool) $this->sticky;
     $t_fields[] = $this->due_date;
     $t_fields[] = $this->id;
     db_query_bound($query, $t_fields);
     bug_clear_cache($this->id);
     # log changes
     history_log_event_direct($c_bug_id, 'project_id', $t_old_data->project_id, $this->project_id);
     history_log_event_direct($c_bug_id, 'reporter_id', $t_old_data->reporter_id, $this->reporter_id);
     history_log_event_direct($c_bug_id, 'handler_id', $t_old_data->handler_id, $this->handler_id);
     history_log_event_direct($c_bug_id, 'priority', $t_old_data->priority, $this->priority);
     history_log_event_direct($c_bug_id, 'severity', $t_old_data->severity, $this->severity);
     history_log_event_direct($c_bug_id, 'reproducibility', $t_old_data->reproducibility, $this->reproducibility);
     history_log_event_direct($c_bug_id, 'status', $t_old_data->status, $this->status);
     history_log_event_direct($c_bug_id, 'resolution', $t_old_data->resolution, $this->resolution);
     history_log_event_direct($c_bug_id, 'projection', $t_old_data->projection, $this->projection);
     history_log_event_direct($c_bug_id, 'category', category_full_name($t_old_data->category_id, false), category_full_name($this->category_id, false));
     history_log_event_direct($c_bug_id, 'eta', $t_old_data->eta, $this->eta);
     history_log_event_direct($c_bug_id, 'os', $t_old_data->os, $this->os);
     history_log_event_direct($c_bug_id, 'os_build', $t_old_data->os_build, $this->os_build);
     history_log_event_direct($c_bug_id, 'platform', $t_old_data->platform, $this->platform);
     history_log_event_direct($c_bug_id, 'version', $t_old_data->version, $this->version);
     history_log_event_direct($c_bug_id, 'build', $t_old_data->build, $this->build);
     history_log_event_direct($c_bug_id, 'fixed_in_version', $t_old_data->fixed_in_version, $this->fixed_in_version);
     if ($t_roadmap_updated) {
         history_log_event_direct($c_bug_id, 'target_version', $t_old_data->target_version, $this->target_version);
     }
     history_log_event_direct($c_bug_id, 'view_state', $t_old_data->view_state, $this->view_state);
     history_log_event_direct($c_bug_id, 'summary', $t_old_data->summary, $this->summary);
     history_log_event_direct($c_bug_id, 'sponsorship_total', $t_old_data->sponsorship_total, $this->sponsorship_total);
     history_log_event_direct($c_bug_id, 'sticky', $t_old_data->sticky, $this->sticky);
     history_log_event_direct($c_bug_id, 'due_date', $t_old_data->due_date != date_get_null() ? $t_old_data->due_date : null, $this->due_date != date_get_null() ? $this->due_date : null);
     # Update extended info if requested
     if ($p_update_extended) {
         $t_bug_text_table = db_get_table('mantis_bug_text_table');
         $t_bug_text_id = bug_get_field($c_bug_id, 'bug_text_id');
         $query = "UPDATE {$t_bug_text_table}\n\t\t\t\t\t\t\tSET description=" . db_param() . ",\n\t\t\t\t\t\t\t\tsteps_to_reproduce=" . db_param() . ",\n\t\t\t\t\t\t\t\tadditional_information=" . db_param() . "\n\t\t\t\t\t\t\tWHERE id=" . db_param();
         db_query_bound($query, array($this->description, $this->steps_to_reproduce, $this->additional_information, $t_bug_text_id));
         bug_text_clear_cache($c_bug_id);
         $t_current_user = auth_get_current_user_id();
         if ($t_old_data->description != $this->description) {
             if (bug_revision_count($c_bug_id, REV_DESCRIPTION) < 1) {
                 $t_revision_id = bug_revision_add($c_bug_id, $t_old_data->reporter_id, REV_DESCRIPTION, $t_old_data->description, 0, $t_old_data->date_submitted);
             }
             $t_revision_id = bug_revision_add($c_bug_id, $t_current_user, REV_DESCRIPTION, $this->description);
             history_log_event_special($c_bug_id, DESCRIPTION_UPDATED, $t_revision_id);
         }
         if ($t_old_data->steps_to_reproduce != $this->steps_to_reproduce) {
             if (bug_revision_count($c_bug_id, REV_STEPS_TO_REPRODUCE) < 1) {
                 $t_revision_id = bug_revision_add($c_bug_id, $t_old_data->reporter_id, REV_STEPS_TO_REPRODUCE, $t_old_data->steps_to_reproduce, 0, $t_old_data->date_submitted);
             }
             $t_revision_id = bug_revision_add($c_bug_id, $t_current_user, REV_STEPS_TO_REPRODUCE, $this->steps_to_reproduce);
             history_log_event_special($c_bug_id, STEP_TO_REPRODUCE_UPDATED, $t_revision_id);
         }
         if ($t_old_data->additional_information != $this->additional_information) {
             if (bug_revision_count($c_bug_id, REV_ADDITIONAL_INFO) < 1) {
                 $t_revision_id = bug_revision_add($c_bug_id, $t_old_data->reporter_id, REV_ADDITIONAL_INFO, $t_old_data->additional_information, 0, $t_old_data->date_submitted);
             }
             $t_revision_id = bug_revision_add($c_bug_id, $t_current_user, REV_ADDITIONAL_INFO, $this->additional_information);
             history_log_event_special($c_bug_id, ADDITIONAL_INFO_UPDATED, $t_revision_id);
         }
     }
     # Update the last update date
     bug_update_date($c_bug_id);
     # allow bypass if user is sending mail separately
     if (false == $p_bypass_mail) {
         # bug assigned
         if ($t_old_data->handler_id != $this->handler_id) {
             email_generic($c_bug_id, 'owner', 'email_notification_title_for_action_bug_assigned');
             return true;
         }
         # status changed
         if ($t_old_data->status != $this->status) {
             $t_status = MantisEnum::getLabel(config_get('status_enum_string'), $this->status);
             $t_status = str_replace(' ', '_', $t_status);
             email_generic($c_bug_id, $t_status, 'email_notification_title_for_status_bug_' . $t_status);
             return true;
         }
         # @todo handle priority change if it requires special handling
         # generic update notification
         email_generic($c_bug_id, 'updated', 'email_notification_title_for_action_bug_updated');
     }
     return true;
 }
Пример #25
0
/**
 * Remove one or more bug revisions from the bug history.
 * @param int $p_revision_id Revision ID, or array of revision IDs
 * @return null
 */
function bug_revision_drop( $p_revision_id ) {
	$t_bug_rev_table = db_get_table( 'bug_revision' );

	if ( is_array( $p_revision_id ) ) {
		$t_revisions = array();
		$t_first = true;
		$t_query = "DELETE FROM $t_bug_rev_table WHERE id IN ( ";

		# TODO: Fetch bug revisions in one query (and cache them)
		foreach( $p_revision_id as $t_rev_id ) {
			$t_query .= ( $t_first ? db_param() : ', ' . db_param() );
			$t_revisions[$t_rev_id] = bug_revision_get( $t_rev_id );
		}

		$t_query .= ' )';
		db_query_bound( $t_query, $p_revision_id );
		foreach( $p_revision_id as $t_rev_id ) {
			if ( $t_revisions[$t_rev_id]['type'] == REV_BUGNOTE ) {
				history_log_event_special( $t_revisions[$t_rev_id]['bug_id'], BUGNOTE_REVISION_DROPPED, bugnote_format_id( $t_rev_id ), $t_revisions[$t_rev_id]['bugnote_id'] );
			} else {
				history_log_event_special( $t_revisions[$t_rev_id]['bug_id'], BUG_REVISION_DROPPED, bugnote_format_id( $t_rev_id ), $t_revisions[$t_rev_id]['type'] );
			}
		}
	} else {
		$t_revision = bug_revision_get( $p_revision_id );
		$t_query = "DELETE FROM $t_bug_rev_table WHERE id=" . db_param();
		db_query_bound( $t_query, array( $p_revision_id ) );
		if ( $t_revision['type'] == REV_BUGNOTE ) {
			history_log_event_special( $t_revision['bug_id'], BUGNOTE_REVISION_DROPPED, bugnote_format_id( $p_revision_id ), $t_revision['bugnote_id'] );
		} else {
			history_log_event_special( $t_revision['bug_id'], BUG_REVISION_DROPPED, bugnote_format_id( $p_revision_id ), $t_revision['type'] );
		}
	}
}
Пример #26
0
/**
 * Add a file to the system using the configured storage method
 *
 * @param integer $p_bug_id the bug id (should be 0 when adding project doc)
 * @param array $p_file the uploaded file info, as retrieved from gpc_get_file()
 * @param string $p_table 'bug' or 'project' depending on attachment type
 * @param string $p_title file title
 * @param string $p_desc file description
 * @param int $p_user_id user id (defaults to current user)
 * @param int $p_date_added date added
 * @param bool $p_skip_bug_update skip bug last modification update (useful when importing bug attachments)
 */
function file_add($p_bug_id, $p_file, $p_table = 'bug', $p_title = '', $p_desc = '', $p_user_id = null, $p_date_added = 0, $p_skip_bug_update = false)
{
    file_ensure_uploaded($p_file);
    $t_file_name = $p_file['name'];
    $t_tmp_file = $p_file['tmp_name'];
    if (!file_type_check($t_file_name)) {
        trigger_error(ERROR_FILE_NOT_ALLOWED, ERROR);
    }
    if (!file_is_name_unique($t_file_name, $p_bug_id)) {
        trigger_error(ERROR_FILE_DUPLICATE, ERROR);
    }
    $t_file_size = filesize($t_tmp_file);
    if (0 == $t_file_size) {
        trigger_error(ERROR_FILE_NO_UPLOAD_FAILURE, ERROR);
    }
    $t_max_file_size = (int) min(ini_get_number('upload_max_filesize'), ini_get_number('post_max_size'), config_get('max_file_size'));
    if ($t_file_size > $t_max_file_size) {
        trigger_error(ERROR_FILE_TOO_BIG, ERROR);
    }
    if ('bug' == $p_table) {
        $t_project_id = bug_get_field($p_bug_id, 'project_id');
        $t_id = (int) $p_bug_id;
        $t_bug_id = bug_format_id($p_bug_id);
    } else {
        $t_project_id = helper_get_current_project();
        $t_id = $t_project_id;
        $t_bug_id = 0;
    }
    if ($p_user_id === null) {
        $p_user_id = auth_get_current_user_id();
    }
    if ($p_date_added <= 0) {
        $p_date_added = db_now();
    }
    if ($t_project_id == ALL_PROJECTS) {
        $t_file_path = config_get('absolute_path_default_upload_folder');
    } else {
        $t_file_path = project_get_field($t_project_id, 'file_path');
        if (is_blank($t_file_path)) {
            $t_file_path = config_get('absolute_path_default_upload_folder');
        }
    }
    $t_file_hash = 'bug' == $p_table ? $t_bug_id : config_get('document_files_prefix') . '-' . $t_project_id;
    $t_unique_name = file_generate_unique_name($t_file_hash . '-' . $t_file_name, $t_file_path);
    $t_disk_file_name = $t_file_path . $t_unique_name;
    $t_method = config_get('file_upload_method');
    switch ($t_method) {
        case FTP:
        case DISK:
            file_ensure_valid_upload_path($t_file_path);
            if (!file_exists($t_disk_file_name)) {
                if (FTP == $t_method) {
                    $conn_id = file_ftp_connect();
                    file_ftp_put($conn_id, $t_disk_file_name, $t_tmp_file);
                    file_ftp_disconnect($conn_id);
                }
                if (!move_uploaded_file($t_tmp_file, $t_disk_file_name)) {
                    trigger_error(ERROR_FILE_MOVE_FAILED, ERROR);
                }
                chmod($t_disk_file_name, config_get('attachments_file_permissions'));
                $c_content = '';
            } else {
                trigger_error(ERROR_FILE_DUPLICATE, ERROR);
            }
            break;
        case DATABASE:
            $c_content = db_prepare_binary_string(fread(fopen($t_tmp_file, 'rb'), $t_file_size));
            break;
        default:
            trigger_error(ERROR_GENERIC, ERROR);
    }
    $t_file_table = db_get_table($p_table . '_file');
    $t_id_col = $p_table . "_id";
    $t_query_fields = "\n\t\t{$t_id_col}, title, description, diskfile, filename, folder,\n\t\tfilesize, file_type, date_added, user_id";
    $t_param = array($t_id, $p_title, $p_desc, $t_unique_name, $t_file_name, $t_file_path, $t_file_size, $p_file['type'], $p_date_added, (int) $p_user_id);
    # oci8 stores contents in a BLOB, which is updated separately
    if (!db_is_oracle()) {
        $t_query_fields .= ", content";
        $t_param[] = $c_content;
    }
    $t_query_param = db_param();
    for ($i = 1; $i < count($t_param); $i++) {
        $t_query_param .= ", " . db_param();
    }
    $t_query = "INSERT INTO {$t_file_table} ( {$t_query_fields} )\n\tVALUES\n\t\t( {$t_query_param} )";
    db_query_bound($t_query, $t_param);
    if (db_is_oracle()) {
        db_update_blob($t_file_table, 'content', $c_content, "diskfile='{$t_unique_name}'");
    }
    if ('bug' == $p_table) {
        # update the last_updated date
        if (!$p_skip_bug_update) {
            $result = bug_update_date($p_bug_id);
        }
        # log file added to bug history
        history_log_event_special($p_bug_id, FILE_ADDED, $t_file_name);
    }
}