Commit 68869469 authored by Valery Sizov's avatar Valery Sizov

Move update project logic into separate method after_rename_repository

MR - https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/19747
parent 6983184c
...@@ -1583,46 +1583,33 @@ class Project < ActiveRecord::Base ...@@ -1583,46 +1583,33 @@ class Project < ActiveRecord::Base
end end
def rename_repo def rename_repo
path_before_change = previous_changes['path'].first path_before = previous_changes['path'].first
full_path_before_change = full_path_was full_path_before = full_path_was
full_path_after_change = build_full_path full_path_after = build_full_path
Rails.logger.error "Attempting to rename #{full_path_was} -> #{full_path_after_change}" Gitlab::AppLogger.info("Attempting to rename #{full_path_was} -> #{full_path_after}")
if has_container_registry_tags? if has_container_registry_tags?
Rails.logger.error "Project #{full_path_was} cannot be renamed because container registry tags are present!" Gitlab::AppLogger.info("Project #{full_path_was} cannot be renamed because container registry tags are present!")
# we currently don't support renaming repository if it contains images in container registry # we currently don't support renaming repository if it contains images in container registry
raise StandardError.new('Project cannot be renamed, because images are present in its container registry') raise StandardError.new('Project cannot be renamed, because images are present in its container registry')
end end
expire_caches_before_rename(full_path_was) expire_caches_before_rename(full_path_before)
if rename_or_migrate_repository! if rename_or_migrate_repository!
Gitlab::AppLogger.info "Project was renamed: #{full_path_before_change} -> #{full_path_after_change}" Gitlab::AppLogger.info("Project was renamed: #{full_path_before} -> #{full_path_after}")
rename_repo_notify!(full_path_before_change) after_rename_repository(full_path_before, path_before)
after_rename_repo(path_before_change)
else else
Rails.logger.error "Repository could not be renamed: #{full_path_before_change} -> #{full_path_after_change}" Gitlab::AppLogger.info("Repository could not be renamed: #{full_path_before} -> #{full_path_after}")
# if we cannot move namespace directory we should rollback # if we cannot move namespace directory we should rollback
# db changes in order to prevent out of sync between db and fs # db changes in order to prevent out of sync between db and fs
raise StandardError.new('repository cannot be renamed') raise StandardError.new('Repository cannot be renamed')
end end
end end
def after_rename_repo(path_before_change)
write_repository_config
# We need to check if project had been rolled out to move resource to hashed storage or not and decide
# if we need execute any take action or no-op.
unless hashed_storage?(:attachments)
Gitlab::UploadsTransfer.new.rename_project(path_before_change, self.path, namespace.full_path)
end
Gitlab::PagesTransfer.new.rename_project(path_before_change, self.path, namespace.full_path)
end
def write_repository_config(gl_full_path: full_path) def write_repository_config(gl_full_path: full_path)
# We'd need to keep track of project full path otherwise directory tree # We'd need to keep track of project full path otherwise directory tree
# created with hashed storage enabled cannot be usefully imported using # created with hashed storage enabled cannot be usefully imported using
...@@ -1633,17 +1620,6 @@ class Project < ActiveRecord::Base ...@@ -1633,17 +1620,6 @@ class Project < ActiveRecord::Base
nil nil
end end
def rename_repo_notify!(full_path_before_change)
# When we import a project overwriting the original project, there
# is a move operation. In that case we don't want to send the instructions.
send_move_instructions(full_path_before_change) unless import_started?
self.old_path_with_namespace = full_path_before_change
SystemHooksService.new.execute_hooks_for(self, :rename)
reload_repository!
end
def after_import def after_import
repository.after_import repository.after_import
wiki.repository.after_import wiki.repository.after_import
...@@ -2072,6 +2048,31 @@ class Project < ActiveRecord::Base ...@@ -2072,6 +2048,31 @@ class Project < ActiveRecord::Base
end end
end end
def after_rename_repository(full_path_before, path_before)
execute_rename_repository_hooks!(full_path_before)
write_repository_config
# We need to check if project had been rolled out to move resource to hashed storage or not and decide
# if we need execute any take action or no-op.
unless hashed_storage?(:attachments)
Gitlab::UploadsTransfer.new.rename_project(path_before, self.path, namespace.full_path)
end
Gitlab::PagesTransfer.new.rename_project(path_before, self.path, namespace.full_path)
end
def execute_rename_repository_hooks!(full_path_before)
# When we import a project overwriting the original project, there
# is a move operation. In that case we don't want to send the instructions.
send_move_instructions(full_path_before) unless import_started?
self.old_path_with_namespace = full_path_before
SystemHooksService.new.execute_hooks_for(self, :rename)
reload_repository!
end
def storage def storage
@storage ||= @storage ||=
if hashed_storage?(:repository) if hashed_storage?(:repository)
......
...@@ -456,20 +456,6 @@ module EE ...@@ -456,20 +456,6 @@ module EE
end end
alias_method :merge_requests_ff_only_enabled?, :merge_requests_ff_only_enabled alias_method :merge_requests_ff_only_enabled?, :merge_requests_ff_only_enabled
override :rename_repo
def rename_repo
super
path_was = previous_changes['path'].first
old_path_with_namespace = File.join(namespace.full_path, path_was)
::Geo::RepositoryRenamedEventStore.new(
self,
old_path: path_was,
old_path_with_namespace: old_path_with_namespace
).create
end
override :disabled_services override :disabled_services
def disabled_services def disabled_services
strong_memoize(:disabled_services) do strong_memoize(:disabled_services) do
...@@ -561,5 +547,16 @@ module EE ...@@ -561,5 +547,16 @@ module EE
::Geo::RepositoryUpdatedService.new(self, source: ::Geo::RepositoryUpdatedEvent::REPOSITORY).execute ::Geo::RepositoryUpdatedService.new(self, source: ::Geo::RepositoryUpdatedEvent::REPOSITORY).execute
::Geo::RepositoryUpdatedService.new(self, source: ::Geo::RepositoryUpdatedEvent::WIKI).execute ::Geo::RepositoryUpdatedService.new(self, source: ::Geo::RepositoryUpdatedEvent::WIKI).execute
end end
override :after_rename_repository
def after_rename_repository(full_path_before, path_before)
super(full_path_before, path_before)
::Geo::RepositoryRenamedEventStore.new(
self,
old_path: path_before,
old_path_with_namespace: full_path_before
).create
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment