mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 07:38:45 -05:00
Merge pull request #4441 from tgxworld/fix_restore_not_respecting_folder_on_multisite
FIX: Uploads being restored into the wrong directory for multisite.
This commit is contained in:
commit
770c5ea378
1 changed files with 23 additions and 1 deletions
|
@ -1,3 +1,5 @@
|
|||
require_dependency "db_helper"
|
||||
|
||||
module BackupRestore
|
||||
|
||||
class RestoreDisabledError < RuntimeError; end
|
||||
|
@ -360,12 +362,32 @@ module BackupRestore
|
|||
def extract_uploads
|
||||
if system('tar', '--exclude=*/*', '--list', '--file', @tar_filename, 'uploads')
|
||||
log "Extracting uploads..."
|
||||
FileUtils.cd(File.join(Rails.root, "public")) do
|
||||
|
||||
FileUtils.cd(@tmp_directory) do
|
||||
execute_command(
|
||||
'tar', '--extract', '--keep-newer-files', '--file', @tar_filename, 'uploads/',
|
||||
failure_message: "Failed to extract uploadsd."
|
||||
)
|
||||
end
|
||||
|
||||
public_uploads_path = File.join(Rails.root, "public")
|
||||
|
||||
FileUtils.cd(public_uploads_path) do
|
||||
FileUtils.mkdir_p("uploads")
|
||||
|
||||
tmp_uploads_path = Dir.glob(File.join(@tmp_directory, "uploads", "*")).first
|
||||
previous_db_name = File.basename(tmp_uploads_path)
|
||||
current_db_name = RailsMultisite::ConnectionManagement.current_db
|
||||
|
||||
execute_command(
|
||||
'rsync', '-avp', "#{tmp_uploads_path}/", "uploads/#{current_db_name}/",
|
||||
failure_message: "Failed to restore uploads."
|
||||
)
|
||||
|
||||
if previous_db_name != current_db_name
|
||||
DbHelper.remap("uploads/#{previous_db_name}", "uploads/#{current_db_name}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue