2018-11-17 00:37:17 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-15 14:03:31 +00:00
|
|
|
module Gitlab
|
|
|
|
module ImportExport
|
|
|
|
class AvatarRestorer
|
|
|
|
def initialize(project:, shared:)
|
|
|
|
@project = project
|
|
|
|
@shared = shared
|
|
|
|
end
|
|
|
|
|
|
|
|
def restore
|
|
|
|
return true unless avatar_export_file
|
|
|
|
|
|
|
|
@project.avatar = File.open(avatar_export_file)
|
|
|
|
@project.save!
|
|
|
|
rescue => e
|
|
|
|
@shared.error(e)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def avatar_export_file
|
2018-09-11 08:22:34 +00:00
|
|
|
@avatar_export_file ||= Dir["#{avatar_export_path}/**/*"].find { |f| File.file?(f) }
|
2016-07-15 14:03:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def avatar_export_path
|
|
|
|
File.join(@shared.export_path, 'avatar')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|