Fixes #5923: System rule are modified when trying to delete a directive

Basically switch the deletion order so that if the directive can't be deleted, it is not removed from rules (because it's less a problem to have rules with unknown directives, we can still go delete them by hand)
ok, i read the ticket and understood