-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upload migration files from profile settings and start processing
- Loading branch information
Showing
9 changed files
with
177 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
.modal.fade{id: "importAccountModal", | ||
tabindex: "-1", | ||
role: "dialog", | ||
aria: {labelledby: "importAccountModalLabel", hidden: "true"}} | ||
.modal-dialog | ||
.modal-content | ||
.modal-header | ||
%button.close{type: "button", data: {dismiss: "modal"}, aria: {hidden: "true"}} | ||
× | ||
%h3.modal-title{id: "importAccountModalLabel"} | ||
Import another account | ||
.modal-body | ||
%p | ||
You are about to import and merge another account into | ||
= current_user.diaspora_handle | ||
/. | ||
Here is what's going to happen: | ||
%ol | ||
%li | ||
Your profile (name, bio, birthday, gender...) will be updated with the content from the imported account | ||
%li | ||
Your settings (theme, visibility...) will be updated with those from the imported account | ||
%li | ||
All your aspects and contacts will be added to this account. This will be transparent for them, they | ||
will be linked to that account as they were linked with the account you are importing | ||
%li | ||
All posts and comments you made with the imported account will be imported in that account and seen | ||
as posted by this accounts by the other users | ||
%li | ||
%strong | ||
The imported account and all its linked data will be deleted from the previous pod. | ||
%p | ||
If the pod of the account you are importing is offline, your contacts and posts will still be imported, | ||
but your contacts will receive a notification as if you started sharing with them. | ||
= form_for current_user, url: edit_user_path, html: {method: :put, multipart: true, class: "form-horizontal"} do |f| | ||
.row | ||
.col-md-6 | ||
%label Select the data archive: | ||
= f.file_field :export, accept: "application/json, application/zip, application/gzip" | ||
.col-md-6 | ||
%label Select the photos archive: | ||
= f.file_field :exported_photos_file, accept: "application/zip" | ||
%h4 | ||
The original account will be imported | ||
%strong | ||
and deleted. This cannot be undone! | ||
%p | ||
.clearfix | ||
.btn.btn-default{data: {dismiss: "modal"}} | ||
Cancel | ||
= f.submit 'Import and merge', class: "btn btn-primary.pull-right", id: "change_email_preferences" | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
module Workers | ||
class ImportProfile < Base | ||
sidekiq_options queue: :medium | ||
|
||
include Diaspora::Logging | ||
|
||
def perform(user_id) | ||
user = User.find_by(username: user_id) | ||
if user.nil? | ||
logger.error "A user with name #{user_id} not a local user" | ||
else | ||
logger.info "Import for profile #{user_id} at path #{user.export.current_path} requested" | ||
import_user_profile(user.export.current_path, user_id) | ||
|
||
logger.info("Moving photos from impport file") | ||
import_user_photos(user) | ||
end | ||
end | ||
|
||
private | ||
def import_user_profile(path_to_profile, username) | ||
service = MigrationService.new(path_to_profile, username) | ||
logger.info "Start validating user profile #{username}" | ||
service.validate | ||
logger.info "Start importing user profile for #{username}" | ||
service.perform! | ||
logger.info "Successfully imported profile: #{username}" | ||
rescue MigrationService::ArchiveValidationFailed => e | ||
logger.error "Errors in the archive found: #{e.message}" | ||
rescue MigrationService::MigrationAlreadyExists | ||
logger.error "Migration record already exists for the user, can't continue" | ||
rescue MigrationService::SelfMigrationNotAllowed | ||
logger.error "You can't migrate onto your own account" | ||
ensure | ||
service.remove_intermediate_file | ||
end | ||
|
||
def import_user_photos(user) | ||
unzip_photos_file(photo_file_path) | ||
user.posts.find_in_batches do |photo| | ||
photo_filename = photo.remote_photo_name | ||
copy sorce photo.unprocessed_image.store_dir | ||
photo.remote_photo_name = nil # migration sets this attribute, but file needs to be procesed | ||
photo.unprocessed_image = photo_filename | ||
photo.save(touch: false) | ||
|
||
end | ||
end | ||
|
||
def unzip_photos_file(photo_file_path) | ||
system("unzip", photo_file_path) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters