Upgrade step for cleaning refences + detect and fix duplicates
Created by: cproensa
Adding the clean up step for config upgrade.
Also: Regarding avoiding duplicated references, this is my approach after discussion in https://www.mantisbt.org/bugs/view.php?id=21850 Note that the duplicated references scenario can also happen when bugs are deleted externally, bypassing the delete event. The approach here: first cleans up the duplicates, and then insert the correct one for the current bug.