mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 09:58:18 +08:00
FEATURE: Attach backup log as upload (#13849)
Discourse automatically sends a private message after backup or restore finished. The private message used to contain the log inline even when it was very long. A very long log can create issues because the length of the post will be over the maximum allowed length of a post. When that happens, Discourse will try to create an upload with the logs. If that fails, it will trim the log and inline it.
This commit is contained in:
@ -16,4 +16,59 @@ describe BackupRestore::Backuper do
|
||||
|
||||
expect(backuper.send(:get_parameterized_title)).to eq("coding-horror")
|
||||
end
|
||||
|
||||
describe '#notify_user' do
|
||||
before do
|
||||
freeze_time Time.zone.parse('2010-01-01 12:00')
|
||||
end
|
||||
|
||||
it 'includes logs if short' do
|
||||
SiteSetting.max_export_file_size_kb = 1
|
||||
SiteSetting.export_authorized_extensions = "tar.gz"
|
||||
|
||||
silence_stdout do
|
||||
backuper = BackupRestore::Backuper.new(Discourse.system_user.id)
|
||||
|
||||
expect { backuper.send(:notify_user) }
|
||||
.to change { Topic.private_messages.count }.by(1)
|
||||
.and change { Upload.count }.by(0)
|
||||
end
|
||||
|
||||
expect(Topic.last.first_post.raw).to include("```text\n[2010-01-01 12:00:00] Notifying 'system' of the end of the backup...\n```")
|
||||
end
|
||||
|
||||
it 'include upload if log is long' do
|
||||
SiteSetting.max_post_length = 250
|
||||
|
||||
silence_stdout do
|
||||
backuper = silence_stdout { BackupRestore::Backuper.new(Discourse.system_user.id) }
|
||||
|
||||
expect { backuper.send(:notify_user) }
|
||||
.to change { Topic.private_messages.count }.by(1)
|
||||
.and change { Upload.where(original_filename: "log.txt.zip").count }.by(1)
|
||||
end
|
||||
|
||||
expect(Topic.last.first_post.raw).to include("[log.txt.zip|attachment]")
|
||||
end
|
||||
|
||||
it 'includes trimmed logs if log is long and upload cannot be saved' do
|
||||
SiteSetting.max_post_length = 348
|
||||
SiteSetting.max_export_file_size_kb = 1
|
||||
SiteSetting.export_authorized_extensions = "tar.gz"
|
||||
|
||||
silence_stdout do
|
||||
backuper = BackupRestore::Backuper.new(Discourse.system_user.id)
|
||||
|
||||
1.upto(10).each do |i|
|
||||
backuper.send(:log, "Line #{i}")
|
||||
end
|
||||
|
||||
expect { backuper.send(:notify_user) }
|
||||
.to change { Topic.private_messages.count }.by(1)
|
||||
.and change { Upload.count }.by(0)
|
||||
end
|
||||
|
||||
expect(Topic.last.first_post.raw).to include("```text\n...\n[2010-01-01 12:00:00] Line 10\n[2010-01-01 12:00:00] Notifying 'system' of the end of the backup...\n```")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user