Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBenjamin Neff <benjamin@coding4coffee.ch>2021-11-09 06:04:27 +0300
committerBenjamin Neff <benjamin@coding4coffee.ch>2021-11-23 03:48:33 +0300
commit34528521f27607eb1729e3e9dd53409d9e68a6f7 (patch)
tree358205d54930f7e5ee5fde48d058b209db6045f0 /lib
parent96493b4a5c19072763ce8cb58f3a18ae0fa89d4c (diff)
Allow to choose to overwrite settings and profile data
Diffstat (limited to 'lib')
-rw-r--r--lib/archive_importer.rb30
-rw-r--r--lib/tasks/accounts.rake36
2 files changed, 48 insertions, 18 deletions
diff --git a/lib/archive_importer.rb b/lib/archive_importer.rb
index 1b0bab6cb..8776edca8 100644
--- a/lib/archive_importer.rb
+++ b/lib/archive_importer.rb
@@ -10,7 +10,7 @@ class ArchiveImporter
@archive_hash = archive_hash
end
- def import
+ def import(opts={})
import_tag_followings
import_aspects
import_contacts
@@ -19,12 +19,12 @@ class ArchiveImporter
import_subscriptions
import_others_relayables
import_blocks
+ import_settings if opts.fetch(:import_settings, true)
+ import_profile if opts.fetch(:import_profile, true)
end
- def create_user(attr)
- allowed_keys = %w[
- email strip_exif show_community_spotlight_in_stream language disable_mail auto_follow_back
- ]
+ def find_or_create_user(attr)
+ allowed_keys = %w[email language]
data = convert_keys(archive_hash["user"], allowed_keys)
# setting getting_started to false as the user doesn't need to see the getting started wizard
data.merge!(
@@ -36,8 +36,6 @@ class ArchiveImporter
}
)
self.user = User.find_or_build(data)
- user.show_community_spotlight_in_stream = data.fetch(:show_community_spotlight_in_stream, true)
- user.strip_exif = data.fetch(:strip_exif, true)
user.getting_started = false
user.save!
end
@@ -63,7 +61,7 @@ class ArchiveImporter
return if name.nil?
aspect = user.aspects.find_by(name: name)
- user.update(auto_follow_back_aspect: aspect) if aspect
+ user.update(auto_follow_back: true, auto_follow_back_aspect: aspect) if aspect
end
def import_aspects
@@ -74,7 +72,6 @@ class ArchiveImporter
logger.warn "#{self}: #{e}"
end
end
- set_auto_follow_back_aspect
end
def import_posts
@@ -125,6 +122,21 @@ class ArchiveImporter
end
end
+ def import_settings
+ allowed_keys = %w[language show_community_spotlight_in_stream strip_exif]
+ convert_keys(archive_hash["user"], allowed_keys).each do |key, value|
+ user.update(key => value) unless value.nil?
+ end
+
+ set_auto_follow_back_aspect if archive_hash.fetch("user").fetch("auto_follow_back", false)
+ end
+
+ def import_profile
+ profile_attributes.each do |key, value|
+ user.person.profile.update(key => value) unless value.nil?
+ end
+ end
+
def convert_keys(hash, allowed_keys)
hash
.slice(*allowed_keys)
diff --git a/lib/tasks/accounts.rake b/lib/tasks/accounts.rake
index 24077ec3e..f6075de3d 100644
--- a/lib/tasks/accounts.rake
+++ b/lib/tasks/accounts.rake
@@ -2,13 +2,16 @@
namespace :accounts do
desc "Perform migration"
- task :migration, %i[archive_path photos_path new_user_name] => :environment do |_t, args|
- puts "Account migration is requested. You can import a profile or a photos archive or booth."
- args = %i[archive_path photos_path new_user_name].map {|name| [name, args[name]] }.to_h
+ task :migration,
+ %i[archive_path photos_path new_user_name import_settings import_profile] => :environment do |_t, args|
+ puts "Account migration is requested. You can import a profile or a photos archive or both."
+ args = %i[archive_path photos_path new_user_name import_settings import_profile]
+ .map {|name| [name, args[name]] }.to_h
process_arguments(args)
start_time = Time.now.getlocal
if args[:new_user_name].present? && (args[:archive_path].present? || args[:photos_path].present?)
- ImportService.new.import_by_files(args[:archive_path], args[:photos_path], args[:new_user_name])
+ ImportService.new.import_by_files(args[:archive_path], args[:photos_path], args[:new_user_name],
+ args.slice(:import_settings, :import_profile))
puts "\n Migration completed in #{Time.now.getlocal - start_time} seconds. (Photos might still be processed in)"
else
puts "Must set a user name and a archive file path or photos file path"
@@ -19,16 +22,31 @@ namespace :accounts do
args[:archive_path] = request_parameter(args[:archive_path], "Enter the archive (.json, .gz, .zip) path: ")
args[:photos_path] = request_parameter(args[:photos_path], "Enter the photos (.zip) path: ")
args[:new_user_name] = request_parameter(args[:new_user_name], "Enter the new user name: ")
+ args[:import_settings] = request_boolean_parameter(args[:import_settings], "Import and overwrite settings [Y/n]: ")
+ args[:import_profile] = request_boolean_parameter(args[:import_profile], "Import and overwrite profile [Y/n]: ")
puts "Archive path: #{args[:archive_path]}"
puts "Photos path: #{args[:photos_path]}"
puts "New username: #{args[:new_user_name]}"
+ puts "Import settings: #{args[:import_settings]}"
+ puts "Import profile: #{args[:import_profile]}"
+ end
+
+ def request_parameter(arg, text)
+ return arg unless arg.nil?
+
+ print text
+ $stdin.gets.strip
end
-end
-def request_parameter(arg, text)
- return arg unless arg.nil?
+ def request_boolean_parameter(arg, text, default: true)
+ return arg == "true" unless arg.nil?
- print text
- $stdin.gets.strip
+ print text
+ response = $stdin.gets.strip.downcase
+
+ return default if response == ""
+
+ response[0] == "y"
+ end
end