View Issue Details

IDProjectCategoryView StatusLast Update
0024681mantisbtfeaturepublic2018-08-22 08:20
ReporterBozzAssigned To 
PrioritynormalSeveritymajorReproducibilityalways
Status newResolutionopen 
Product Version2.16.0 
Target VersionFixed in Version 
Summary0024681: Add the possibility to configure multiple bug link tags
Description

Hi,

We have been using Mantis for a while now, integrated at the beginning with SVN, and we migrated a while ago some of our projects to GitLab.
We implemented integration between GitLab commits and Mantis.

The issue we have now is the cross referencing of issues.
In our GitLab we also use the internal Issue tracker, as well as the (official) Mantis issue tracker. In GitLab internal issues are referenced using the # characters, but it is possible to define an external issue tracker, such as Mantis, and reference external issues using something like MANTIS-xxxx to differentiate them from the GitLab internal issues

I tried to configure the Mantis configuration <b>$g_bug_link_tag</b> like so
<pre>$g_bug_link_tag = '#|MANTIS-';</pre>
but it seems like the parameters does not accept these characters '|' and '-' even though it seems to be parsed as a regular expression:
<pre>
string_api.php

function string_process_bugnote_link(...) {
$t_tag = config_get( 'bugnote_link_tag' );
...
$p_string = preg_replace_callback(
'/(^|[^\w])' . preg_quote( $t_tag, '/' ) . '(\d+)\b/',
$s_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn],
$p_string
);
}
</pre>

<b>feature request</b>: Will it be possible to configure a list of possible bug link tags please ?
The motivation is not to replace but to be able to use both former and new references.

Thank you.

TagsNo tags attached.

Activities

Bozz

Bozz

2018-08-20 06:44

reporter   ~0060458

Last edited: 2018-08-20 06:45

View 2 revisions

Hi,

here is a proposal for a fix:

// config_defaults_inc.php

/**
 * Bug Linking
 * if a number follows this tag it will create a link to a bug.
 * for a list of tags, use the pipe character '|' as delimiter
 * eg. for # a link would be #45
 * eg. for bug: a link would be bug:98
 * eg. for #|MANTIS- a link would be #45 and/or MANTIS-125
 * @global string $g_bug_link_tag
 */
$g_bug_link_tag = '#';
// string_api.php

function string_process_bug_link( $p_string, ... ) {
    ...
    $t_tag = config_get( 'bug_link_tag' );
    $t_tags = array_map('trim', explode('|', $t_tag)); // **NEW**
    ...
    foreach($t_tags as $tag) { // **NEW**
        $p_string = preg_replace_callback(
            '/(^|[^\w&])' . preg_quote( $tag, '/' ) . '(\d+)\b/', // **MODIFIED**
            $s_bug_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn],
            $p_string
        );
    } // **NEW**
}
// config_inc.php

$g_bug_link_tag = '#|MANTIS-';
dregad

dregad

2018-08-21 03:26

developer   ~0060465

Last edited: 2018-08-21 03:29

View 2 revisions

it seems like the parameters does not accept these characters '|' and '-' even though it seems to be parsed as a regular expression

This is because we use preg_quote() to ensure that whatever character(s) are used in $g_bug_link_tag are taken literally and not as part of the regex.

To achieve the desired feature, I think it would be better to define the config for multiple tags as an array, instead of splitting a string by | (what if someone wants to use that as a delimiter ?). Then you can avoid the explode statement, and build the regexp with something along the lines of $t_bug_pattern = implode( '|', array_map( 'preg_quote', $t_tag ) ); and use the same code as before instead of introducing a foreach loop.

EDIT: probably a callback function is needed for array_map, so preg_quote can be called with '/' as second parameter.

That being said, I'm a bit concerned about performance. PCRE and callback functions are slow, so pages with many bug links could have degraded response times (but I did not actually benchmark this).

Finally, for consistency I think the same change should be applied to bugnote tags.

Let me know your thoughts.

Bozz

Bozz

2018-08-21 12:37

reporter   ~0060470

Damien your solution seems reasonably good to me, though I don’t have anything to say about perf issues (But the current implementation already uses pcre and callbacks as it seems).

I thought about proposing a change of that prop into an array as well, but that would mean a breaking change! Or introducing a new config prop but it would then mean deal with @deprecated config otherwise.

In any case, I don’t really mind the final solution to choose :-)
For now I modified manually the core files of Mantis in my installation as there is no custom function neither available to change that behaviour.

dregad

dregad

2018-08-22 08:20

developer   ~0060476

About performance: on second thoughts, the preprocessing overhead necessary to handle multiple tags based on an array (whether it's based on a foreach loop or a more complex regex) will most likely be negligible compared to the cost of having preg_replace_callback() execute the closure for each pattern match. I'll try to run some benchmark as time allows, but

I thought about proposing a change of that prop into an array as well, but that would mean a breaking change! Or introducing a new config prop but it would then mean deal with @deprecated config otherwise.

I don't think deprecating the config is necessary - backwards-compatibility can easily be achieved with if( is_array( $t_tag ) { ... }

Issue History

Date Modified Username Field Change
2018-08-20 05:38 Bozz New Issue
2018-08-20 06:44 Bozz Note Added: 0060458
2018-08-20 06:45 Bozz Note Edited: 0060458 View Revisions
2018-08-21 03:26 dregad Note Added: 0060465
2018-08-21 03:29 dregad Note Edited: 0060465 View Revisions
2018-08-21 12:37 Bozz Note Added: 0060470
2018-08-22 08:20 dregad Note Added: 0060476