diff options
author | Michael Kozono <mkozono@gmail.com> | 2018-01-04 14:16:13 -0800 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-01-18 10:28:55 -0800 |
commit | 5d57030e46bffcf21f1ea763d031f38330506061 (patch) | |
tree | 3c987338302fc49e4cef12f194e2ca3850853541 /app/models/route.rb | |
parent | 792e9ed7fa46d236c01fb14c8ad7f9b4ea4dee59 (diff) | |
download | gitlab-ce-5d57030e46bffcf21f1ea763d031f38330506061.tar.gz |
Delete conflicting orphaned routes
Diffstat (limited to 'app/models/route.rb')
-rw-r--r-- | app/models/route.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/app/models/route.rb b/app/models/route.rb index 412f5fb45a5..3d4b5a8b5ee 100644 --- a/app/models/route.rb +++ b/app/models/route.rb @@ -1,4 +1,6 @@ class Route < ActiveRecord::Base + include CaseSensitivity + belongs_to :source, polymorphic: true # rubocop:disable Cop/PolymorphicAssociations validates :source, presence: true @@ -10,6 +12,7 @@ class Route < ActiveRecord::Base validate :ensure_permanent_paths, if: :path_changed? + before_validation :delete_conflicting_orphaned_routes after_create :delete_conflicting_redirects after_update :delete_conflicting_redirects, if: :path_changed? after_update :create_redirect_for_old_path @@ -78,4 +81,13 @@ class Route < ActiveRecord::Base def conflicting_redirect_exists? RedirectRoute.permanent.matching_path_and_descendants(path).exists? end + + def delete_conflicting_orphaned_routes + conflicting = self.class.iwhere(path: path) + conflicting_orphaned_routes = conflicting.select do |route| + route.source.nil? + end + + conflicting_orphaned_routes.each(&:destroy) + end end |