Added additional checks to avoid issue tracker related 500 server errors

See https://github.com/gitlabhq/gitlabhq/issues/5236.
Issue might come from obsolete or dirty project settings e.g. for trackers that have been attached some time ago but does not exist any more.