function display_strategies($p_type = null) { if (is_null($p_type)) { echo '<option value="0">', plugin_lang_get('select_one'), '</option>'; } echo '<option value="', SOURCE_EXPLICIT, '"', $p_type == SOURCE_EXPLICIT ? ' selected="selected"' : '', '>', plugin_lang_get('mapping_explicit'), '</option>'; if (!Source_PVM()) { echo '<option value="', SOURCE_NEAR, '"', $p_type == SOURCE_NEAR ? ' selected="selected"' : '', '>', plugin_lang_get('mapping_near'), '</option>', '<option value="', SOURCE_FAR, '"', $p_type == SOURCE_FAR ? ' selected="selected"' : '', '>', plugin_lang_get('mapping_far'), '</option>'; echo '<option value="', SOURCE_FIRST, '"', $p_type == SOURCE_FIRST ? ' selected="selected"' : '', '>', plugin_lang_get('mapping_first'), '</option>', '<option value="', SOURCE_LAST, '"', $p_type == SOURCE_LAST ? ' selected="selected"' : '', '>', plugin_lang_get('mapping_last'), '</option>'; } }
/** * 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)); }
if (Source_PVM()) { $f_mapping_pvm_version_id = gpc_get_int('_pvm_version_id', 0); $f_mapping_version = ''; } else { $f_mapping_pvm_version_id = 0; $f_mapping_version = gpc_get_string('_version', ''); } $f_mapping_regex = gpc_get_string('_regex', ''); if (!is_blank($f_mapping_branch)) { if (isset($t_mappings[$f_mapping_branch])) { die('error branch'); } if ($f_mapping_type < SOURCE_EXPLICIT) { die('error type'); } if ($f_mapping_type == SOURCE_EXPLICIT) { if (Source_PVM()) { if ($f_mapping_pvm_version_id < 1) { die('error product version'); } } else { if (is_blank($f_mapping_version)) { die('error version'); } } } $t_mapping = new SourceMapping($t_repo->id, $f_mapping_branch, $f_mapping_type, $f_mapping_version, $f_mapping_regex, $f_mapping_pvm_version_id); $t_mapping->save(); } form_security_purge('plugin_Source_repo_update_mappings'); print_successful_redirect(plugin_page('repo_manage_page', true) . '&id=' . $t_repo->id);