If the barbarians are at the gates, you have only one problem: you need to keep the barbarians outside the gates.
If the barbarians are inside the gates, you have two problems: you need to push the barbarians back outside the gates, and... you need new gates.
But if the barbarians are in the gates because a faction in the City opened the gates and let them in, you have three problems: getting rid of the barbarians, getting new gates, and how the City can function when its citizens betray it.