debian-mirror-gitlab/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects.rb

76 lines
2.6 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Gitlab
module Database
module RenameReservedPathsMigration
module V1
class RenameProjects < RenameBase
include Gitlab::ShellAdapter
def rename_projects
projects_for_paths.each do |project|
rename_project(project)
end
remove_cached_html_for_projects(projects_for_paths.map(&:id))
end
def rename_project(project)
old_full_path, new_full_path = rename_path_for_routable(project)
2017-09-10 17:25:29 +05:30
track_rename('project', old_full_path, new_full_path)
move_project_folders(project, old_full_path, new_full_path)
end
def move_project_folders(project, old_full_path, new_full_path)
2018-03-17 18:26:18 +05:30
unless project.hashed_storage?(:repository)
move_repository(project, old_full_path, new_full_path)
move_repository(project, "#{old_full_path}.wiki", "#{new_full_path}.wiki")
end
move_uploads(old_full_path, new_full_path) unless project.hashed_storage?(:attachments)
2017-08-17 22:00:37 +05:30
move_pages(old_full_path, new_full_path)
end
2017-09-10 17:25:29 +05:30
def revert_renames
reverts_for_type('project') do |path_before_rename, current_path|
matches_path = MigrationClasses::Route.arel_table[:path].matches(current_path)
project = MigrationClasses::Project.joins(:route)
2020-04-22 19:07:51 +05:30
.find_by(matches_path)
2017-09-10 17:25:29 +05:30
if project
perform_rename(project, current_path, path_before_rename)
move_project_folders(project, current_path, path_before_rename)
else
say "Couldn't rename project from #{current_path} back to "\
"#{path_before_rename}, project was renamed or no longer "\
"exists at the expected path."
end
end
end
2017-08-17 22:00:37 +05:30
def move_repository(project, old_path, new_path)
2018-10-15 14:42:47 +05:30
unless gitlab_shell.mv_repository(project.repository_storage,
2017-08-17 22:00:37 +05:30
old_path,
new_path)
2020-11-24 15:15:51 +05:30
Gitlab::AppLogger.error "Error moving #{old_path} to #{new_path}"
2017-08-17 22:00:37 +05:30
end
end
def projects_for_paths
return @projects_for_paths if @projects_for_paths
with_paths = MigrationClasses::Route.arel_table[:path]
.matches_any(path_patterns)
@projects_for_paths = MigrationClasses::Project.joins(:route).where(with_paths)
end
end
end
end
end
end