/** * Get an array of the last visited bug ids. We intentionally don't check * if the ids still exists to avoid performance degradation. * * @param user_id The user id to get the last visited issues for, * or null for current logged in user. * @return An array of issue ids or an empty array if none found. * @access public */ function last_visited_get_array($p_user_id = null) { $t_value = token_get_value(TOKEN_LAST_VISITED, $p_user_id); if (is_null($t_value)) { return array(); } # we don't slice the array here to optimise for performance. If the user reduces the number of recently # visited to track, then he/she will get the extra entries until visiting an issue. $t_ids = explode(',', $t_value); bug_cache_array_rows($t_ids); return $t_ids; }
/** * Get list of affected issues between a given time period * @param integer $p_start_time Timestamp representing start time of the period. * @param integer $p_end_time Timestamp representing end time of the period. * @return array */ function timeline_get_affected_issues($p_start_time, $p_end_time) { $t_query = 'SELECT DISTINCT(bug_id) from {bug_history} WHERE date_modified >= ' . db_param() . ' AND date_modified < ' . db_param(); $t_result = db_query($t_query, array($p_start_time, $p_end_time)); $t_current_project = helper_get_current_project(); $t_all_issue_ids = array(); while (($t_row = db_fetch_array($t_result)) !== false) { $t_all_issue_ids[] = $t_row['bug_id']; } bug_cache_array_rows($t_all_issue_ids); $t_issue_ids = array(); foreach ($t_all_issue_ids as $t_issue_id) { if ($t_current_project != ALL_PROJECTS && $t_current_project != bug_get_field($t_issue_id, 'project_id')) { continue; } if (!access_has_bug_level(config_get('view_bug_threshold'), $t_issue_id)) { continue; } $t_issue_ids[] = $t_issue_id; } return $t_issue_ids; }
/** * get all relationships with the given bug as destination * @param integer $p_dest_bug_id Destination bug identifier. * @return array Array of BugRelationshipData objects */ function relationship_get_all_dest($p_dest_bug_id) { $t_query = 'SELECT {bug_relationship}.id, {bug_relationship}.relationship_type, {bug_relationship}.source_bug_id, {bug_relationship}.destination_bug_id, {bug}.project_id FROM {bug_relationship} INNER JOIN {bug} ON {bug_relationship}.source_bug_id = {bug}.id WHERE destination_bug_id=' . db_param() . ' ORDER BY relationship_type, {bug_relationship}.id'; $t_result = db_query($t_query, array((int) $p_dest_bug_id)); $t_dest_project_id = bug_get_field($p_dest_bug_id, 'project_id'); $t_bug_relationship_data = array(); $t_bug_array = array(); $i = 0; while ($t_row = db_fetch_array($t_result)) { $t_bug_relationship_data[$i] = new BugRelationshipData(); $t_bug_relationship_data[$i]->id = $t_row['id']; $t_bug_relationship_data[$i]->src_bug_id = $t_row['source_bug_id']; $t_bug_relationship_data[$i]->src_project_id = $t_row['project_id']; $t_bug_relationship_data[$i]->dest_bug_id = $t_row['destination_bug_id']; $t_bug_relationship_data[$i]->dest_project_id = $t_dest_project_id; $t_bug_relationship_data[$i]->type = $t_row['relationship_type']; $t_bug_array[] = $t_row['source_bug_id']; $i++; } if (!empty($t_bug_array)) { bug_cache_array_rows($t_bug_array); } return $t_bug_relationship_data; }
/** * Given a set of changeset objects, parse the bug links * and save the changes. * @param array Changeset objects * @param object Repository object */ function Source_Process_Changesets($p_changesets, $p_repo = null) { global $g_cache_current_user_id; if (!is_array($p_changesets)) { return; } if (is_null($p_repo)) { $t_repos = SourceRepo::load_by_changesets($p_changesets); } else { $t_repos = array($p_repo->id => $p_repo); } $t_resolved_threshold = config_get('bug_resolved_status_threshold'); $t_fixed_threshold = config_get('bug_resolution_fixed_threshold'); $t_notfixed_threshold = config_get('bug_resolution_not_fixed_threshold'); # Link author and committer name/email to user accounts foreach ($p_changesets as $t_key => $t_changeset) { $p_changesets[$t_key] = Source_Parse_Users($t_changeset); } # Parse normal bug links foreach ($p_changesets as $t_changeset) { $t_changeset->bugs = Source_Parse_Buglinks($t_changeset->message); } # Parse fixed bug links $t_fixed_bugs = array(); # Find and associate resolve links with the changeset foreach ($p_changesets as $t_changeset) { $t_bugs = Source_Parse_Bugfixes($t_changeset->message); foreach ($t_bugs as $t_bug_id) { $t_fixed_bugs[$t_bug_id] = $t_changeset; } # Add the link to the normal set of buglinks $t_changeset->bugs = array_unique(array_merge($t_changeset->bugs, $t_bugs)); } # Save changeset data before processing their consequences foreach ($p_changesets as $t_changeset) { $t_changeset->repo = $p_repo; $t_changeset->save(); } # Precache information for resolved bugs bug_cache_array_rows(array_keys($t_fixed_bugs)); $t_current_user_id = $g_cache_current_user_id; $t_enable_resolving = config_get('plugin_Source_enable_resolving'); $t_enable_message = config_get('plugin_Source_enable_message'); $t_enable_mapping = config_get('plugin_Source_enable_mapping'); $t_bugfix_status = config_get('plugin_Source_bugfix_status'); $t_bugfix_status_pvm = config_get('plugin_Source_bugfix_status_pvm'); $t_resolution = config_get('plugin_Source_bugfix_resolution'); $t_handler = config_get('plugin_Source_bugfix_handler'); $t_message_template = str_replace(array('$1', '$2', '$3', '$4', '$5', '$6'), array('%1$s', '%2$s', '%3$s', '%4$s', '%5$s', '%6$s'), config_get('plugin_Source_bugfix_message')); $t_mappings = array(); # Start fixing and/or resolving issues foreach ($t_fixed_bugs as $t_bug_id => $t_changeset) { # make sure the bug exists before processing if (!bug_exists($t_bug_id)) { continue; } # fake the history entries as the committer/author user ID $t_user_id = null; if ($t_changeset->committer_id > 0) { $t_user_id = $t_changeset->committer_id; } else { if ($t_changeset->user_id > 0) { $t_user_id = $t_changeset->user_id; } } if (!is_null($t_user_id)) { $g_cache_current_user_id = $t_user_id; } else { if (!is_null($t_current_user_id)) { $g_cache_current_user_id = $t_current_user_id; } else { $g_cache_current_user_id = 0; } } # generate the branch mappings $t_version = ''; $t_pvm_version_id = 0; if ($t_enable_mapping) { $t_repo_id = $t_changeset->repo_id; if (!isset($t_mappings[$t_repo_id])) { $t_mappings[$t_repo_id] = SourceMapping::load_by_repo($t_repo_id); } if (isset($t_mappings[$t_repo_id][$t_changeset->branch])) { $t_mapping = $t_mappings[$t_repo_id][$t_changeset->branch]; if (Source_PVM()) { $t_pvm_version_id = $t_mapping->apply_pvm($t_bug_id); } else { $t_version = $t_mapping->apply($t_bug_id); } } } # generate a note message if ($t_enable_message) { $t_message = sprintf($t_message_template, $t_changeset->branch, $t_changeset->revision, $t_changeset->timestamp, $t_changeset->message, $t_repos[$t_changeset->repo_id]->name, $t_changeset->id); } else { $t_message = ''; } $t_bug = bug_get($t_bug_id); # Update the resolution, fixed-in version, and/or add a bugnote $t_update = false; if (Source_PVM()) { if ($t_bugfix_status_pvm > 0 && $t_pvm_version_id > 0) { $t_matrix = new ProductMatrix($t_bug_id); if (isset($t_matrix->status[$t_pvm_version_id])) { $t_matrix->status[$t_pvm_version_id] = $t_bugfix_status_pvm; $t_matrix->save(); } } } else { if ($t_bugfix_status > 0 && $t_bug->status != $t_bugfix_status) { $t_bug->status = $t_bugfix_status; $t_update = true; } else { if ($t_enable_resolving && $t_bugfix_status == -1 && $t_bug->status < $t_resolved_threshold) { $t_bug->status = $t_resolved_threshold; $t_update = true; } } if ($t_bug->resolution < $t_fixed_threshold || $t_bug->resolution >= $t_notfixed_threshold) { $t_bug->resolution = $t_resolution; $t_update = true; } if (is_blank($t_bug->fixed_in_version)) { $t_bug->fixed_in_version = $t_version; $t_update = true; } } if ($t_handler && !is_null($t_user_id)) { $t_bug->handler_id = $t_user_id; } $t_private = plugin_config_get('bugfix_message_view_status') == VS_PRIVATE; if ($t_update) { if ($t_message) { bugnote_add($t_bug_id, $t_message, '0:00', $t_private, 0, '', null, false); } $t_bug->update(); } else { if ($t_message) { bugnote_add($t_bug_id, $t_message, '0:00', $t_private); } } } # reset the user ID $g_cache_current_user_id = $t_current_user_id; # Allow other plugins to post-process commit data event_signal('EVENT_SOURCE_COMMITS', array($p_changesets)); event_signal('EVENT_SOURCE_FIXED', array($t_fixed_bugs)); }
/** * Print list of open bugs with the highest activity score the score is calculated assigning * one "point" for each history event associated with the bug * @return void */ function summary_print_by_activity() { $t_project_id = helper_get_current_project(); $t_resolved = config_get('bug_resolved_status_threshold'); $t_specific_where = helper_project_specific_where($t_project_id); if (' 1<>1' == $t_specific_where) { return; } $t_query = 'SELECT COUNT(h.id) as count, b.id, b.summary, b.view_state FROM {bug} b, {bug_history} h WHERE h.bug_id = b.id AND b.status < ' . db_param() . ' AND ' . $t_specific_where . ' GROUP BY h.bug_id, b.id, b.summary, b.last_updated, b.view_state ORDER BY count DESC, b.last_updated DESC'; $t_result = db_query($t_query, array($t_resolved)); $t_count = 0; $t_private_bug_threshold = config_get('private_bug_threshold'); $t_summarydata = array(); $t_summarybugs = array(); while ($t_row = db_fetch_array($t_result)) { # Skip private bugs unless user has proper permissions if (VS_PRIVATE == $t_row['view_state'] && false == access_has_bug_level($t_private_bug_threshold, $t_row['id'])) { continue; } if ($t_count++ == 10) { break; } $t_summarydata[] = array('id' => $t_row['id'], 'summary' => $t_row['summary'], 'count' => $t_row['count']); $t_summarybugs[] = $t_row['id']; } bug_cache_array_rows($t_summarybugs); foreach ($t_summarydata as $t_row) { $t_bugid = string_get_bug_view_link($t_row['id']); $t_summary = string_display_line($t_row['summary']); $t_notescount = $t_row['count']; echo '<tr>' . "\n"; echo '<td class="small">' . $t_bugid . ' - ' . $t_summary . '</td><td class="right">' . $t_notescount . '</td>' . "\n"; echo '</tr>' . "\n"; } }
function summary_print_by_activity() { $t_mantis_bug_table = db_get_table('mantis_bug_table'); $t_mantis_history_table = db_get_table('mantis_bug_history_table'); $t_project_id = helper_get_current_project(); $t_user_id = auth_get_current_user_id(); $t_resolved = config_get('bug_resolved_status_threshold'); $specific_where = helper_project_specific_where($t_project_id); if (' 1<>1' == $specific_where) { return; } $query = "SELECT COUNT(h.id) as count, b.id, b.summary, b.view_state\n\t\t\t\tFROM {$t_mantis_bug_table} AS b, {$t_mantis_history_table} AS h\n\t\t\t\tWHERE h.bug_id = b.id\n\t\t\t\tAND b.status < " . db_param() . "\n\t\t\t\tAND {$specific_where}\n\t\t\t\tGROUP BY h.bug_id, b.id, b.summary, b.last_updated, b.view_state\n\t\t\t\tORDER BY count DESC, b.last_updated DESC"; $result = db_query_bound($query, array($t_resolved)); $t_count = 0; $t_private_bug_threshold = config_get('private_bug_threshold'); $t_summarydata = array(); $t_summarybugs = array(); while ($row = db_fetch_array($result)) { // Skip private bugs unless user has proper permissions if (VS_PRIVATE == $row['view_state'] && false == access_has_bug_level($t_private_bug_threshold, $row['id'])) { continue; } if ($t_count++ == 10) { break; } $t_summarydata[] = array('id' => $row['id'], 'summary' => $row['summary'], 'count' => $row['count']); $t_summarybugs[] = $row['id']; } bug_cache_array_rows($t_summarybugs); foreach ($t_summarydata as $row) { $t_bugid = string_get_bug_view_link($row['id']); $t_summary = string_display_line($row['summary']); $t_notescount = $row['count']; print "<tr " . helper_alternate_class() . ">\n"; print "<td class=\"small\">{$t_bugid} - {$t_summary}</td><td class=\"right\">{$t_notescount}</td>\n"; print "</tr>\n"; } }
/** * get all relationships with the given bug as destination * @param int $p_dest_bug_id Destination Bug id * @return array Array of BugRelationshipData objects */ function relationship_get_all_dest($p_dest_bug_id) { $c_dest_bug_id = db_prepare_int($p_dest_bug_id); $t_mantis_bug_relationship_table = db_get_table('bug_relationship'); $t_mantis_bug_table = db_get_table('bug'); $query = "SELECT {$t_mantis_bug_relationship_table}.id, {$t_mantis_bug_relationship_table}.relationship_type,\n\t\t\t\t{$t_mantis_bug_relationship_table}.source_bug_id, {$t_mantis_bug_relationship_table}.destination_bug_id,\n\t\t\t\t{$t_mantis_bug_table}.project_id\n\t\t\t\tFROM {$t_mantis_bug_relationship_table}\n\t\t\t\tINNER JOIN {$t_mantis_bug_table} ON {$t_mantis_bug_relationship_table}.source_bug_id = {$t_mantis_bug_table}.id\n\t\t\t\tWHERE destination_bug_id=" . db_param() . "\n\t\t\t\tORDER BY relationship_type, {$t_mantis_bug_relationship_table}.id"; $result = db_query_bound($query, array($c_dest_bug_id)); $t_dest_project_id = bug_get_field($p_dest_bug_id, 'project_id'); $t_bug_relationship_data = array(); $t_relationship_count = db_num_rows($result); $t_bug_array = array(); for ($i = 0; $i < $t_relationship_count; $i++) { $row = db_fetch_array($result); $t_bug_relationship_data[$i] = new BugRelationshipData(); $t_bug_relationship_data[$i]->id = $row['id']; $t_bug_relationship_data[$i]->src_bug_id = $row['source_bug_id']; $t_bug_relationship_data[$i]->src_project_id = $row['project_id']; $t_bug_relationship_data[$i]->dest_bug_id = $row['destination_bug_id']; $t_bug_relationship_data[$i]->dest_project_id = $t_dest_project_id; $t_bug_relationship_data[$i]->type = $row['relationship_type']; $t_bug_array[] = $row['source_bug_id']; } unset($t_bug_relationship_data[$t_relationship_count]); if (!empty($t_bug_array)) { bug_cache_array_rows($t_bug_array); } return $t_bug_relationship_data; }
require_api('print_api.php'); require_api('string_api.php'); require_api('utility_api.php'); require_api('version_api.php'); auth_ensure_user_authenticated(); $f_action = gpc_get_string('action', ''); $f_bug_arr = gpc_get_int_array('bug_arr', array()); # redirects to all_bug_page if nothing is selected if (is_blank($f_action) || 0 == count($f_bug_arr)) { print_header_redirect('view_all_bug_page.php'); } # run through the issues to see if they are all from one project $t_project_id = ALL_PROJECTS; $t_multiple_projects = false; $t_projects = array(); bug_cache_array_rows($f_bug_arr); foreach ($f_bug_arr as $t_bug_id) { $t_bug = bug_get($t_bug_id); if ($t_project_id != $t_bug->project_id) { if ($t_project_id != ALL_PROJECTS && !$t_multiple_projects) { $t_multiple_projects = true; } else { $t_project_id = $t_bug->project_id; $t_projects[$t_project_id] = $t_project_id; } } } if ($t_multiple_projects) { $t_project_id = ALL_PROJECTS; $t_projects[ALL_PROJECTS] = ALL_PROJECTS; }
<?php # Copyright (c) 2012 John Reese # Licensed under the MIT license access_ensure_global_level(plugin_config_get('view_threshold')); $t_can_update = access_has_project_level(plugin_config_get('update_threshold')); require_once config_get('plugin_path') . 'Source/Source.ViewAPI.php'; $f_changeset_id = gpc_get_int('id'); $f_offset = gpc_get_int('offset', 0); $t_changeset = SourceChangeset::load($f_changeset_id); $t_changeset->load_files(); $t_changeset->load_bugs(); bug_cache_array_rows($t_changeset->bugs); $t_bug_rows = array(); foreach ($t_changeset->bugs as $t_bug_id) { $t_bug_row = bug_cache_row($t_bug_id, false); if (false === $t_bug_row) { continue; } $t_bug_rows[$t_bug_id] = $t_bug_row; } $t_affected_rowspan = count($t_bug_rows) + ($t_can_update ? 1 : 0); $t_repos = SourceRepo::load_by_changesets($t_changeset); if (count($t_repos) < 1) { trigger_error(ERROR_GENERIC, ERROR); } $t_repo = array_shift($t_repos); $t_repo->load_branches(); if ($t_changeset->parent) { $t_changeset_parent = SourceChangeset::load_by_revision($t_repo, $t_changeset->parent); } else {
} if ($category_name) { $query .= " AND category_id IN (" . join(", ", $category_ids) . ")"; } $query .= " ORDER BY status ASC, priority DESC, id DESC"; $result = db_query_bound($query, $params); $bug_ids = array(); while ($row = db_fetch_array($result)) { $bug_ids[] = $row["id"]; } bug_cache_array_rows($bug_ids); $bugs = array(); $status = array(); $columns = plugin_config_get("board_columns"); $sevcolors = plugin_config_get("board_severity_colors"); $rescolors = plugin_config_get("board_resolution_colors"); $sprint_length = plugin_config_get("sprint_length"); $use_source = plugin_is_loaded("Source"); $resolved_count = 0; foreach ($bug_ids as $bug_id) { $bug = bug_get($bug_id); $bugs[$bug->status][] = $bug;