[Mantis] Bulk Detach Tags

Recently, I had to remove a lot of tags from a release on Mantis, but this highlighted that although Mantis has for a long time supported attaching tags in bulk to a lot of reports via one button click, it has no ability to bulk detach them later on. So, I select 100 reports in View Issues, click the action groups command to Attach tags, add my tag, click go. Done. Later on, if I want to remove those tags, I have to find and open report 1, click the red X next to the tag, find and open report 2... And so on.

Now, this is a known issue on Mantis's own bug tracker (you can read the report from 2013 here), but the length of time this issue has been open didn't give me much hope for them fixing it soon. Nor did the fact that this issue isn't listed as one they're committed to fixing ahead of releasing 1.3 in the near-ish future. Also, I didn't notice that a code file had been attched to the report already, which (although an incomplete fix) would have saved me 10 minutes or so ;)

After a couple of our product releases where I had to clean up a stack of tags, I reached my limit and investigated how to add this bulk detach functionality myself. And I'm pleased to say I got it all working the other day. It took me (a very reluctant and rubbish web developer) about a day-and-a-half to figure out the code, implement the new functionality, and test it locally and then live, but I'll save you the effort and provide all the details below.

Note that the code here is for Mantis v1.2.19. I have not tested on any other version and make no claims/guarantees that it will work on any other version of Mantis.

Although if you're reading this you're probably already a Mantis user, the link to download Mantis and get more info about this excellent free bug tracker is this one right here.

So, on with the code....


config_defaults_inc.php

Find the example section for defining an array of custom group actions, then modify the empty declaration to actually contain the array data we now need:

config_defaults_inc.php

Before anyone comments, yes, I am aware that I should have added this into config_inc.php and not the defaults file, but the defaults file told me to... Also, why we need this at all when attach tags doesn't / how and where Mantis declares the original attach tags functions, I never worked out.


bug_group_action_api.php

Find the section for attaching tags by searching for EXT_ATTACH_TAGS and then in the lines below add the following to create a "Detach Tags" entry in your group actions list:

bug_group_action_api.php


core\print_api.php

Find the function print_tag_attach_form and then in the lines below add the matching detach tags form:

print_api.php


lang\string_english.txt

In this file we need to add two new variables to hold the text for our button and our acton group command name (if you need localisation in different languages you will need to add the equivalents for these two lines into each language you support):

string_english.txt 1

string_english.txt 2


bug_actiongroup_detach_tags_inc.php

And, finally, we drop into place the actual new function to detach tags form reports. This is a modification to the bug_actiongroup_attach_tags_inc.php which is part of Mantis already, but with the variables renamed, cleaned of bits we don't need, and the actual function swapped to be detach rather than attach. Note that the version on the Mantis bug report I mentioned earlier has different arguments for an older version of Mantis, so if you arent using 1.2.19 you might need to edit this file a bit.

You can download the new file here (not going to make you type it all out...)



And that should be you good to go. Of course, test well to confirm your Mantis isn't setup differently from mine (but then you were going to anyway, right?).

Happy detaching!