From 40b03e717b92b504d7afa1756622d7fded6d625f Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Thu, 14 Mar 2019 12:38:16 +0800 Subject: [PATCH] FIX: `Upload#migrate_to_new_scheme` should not migrate system uploads. --- app/models/upload.rb | 5 ++++- spec/models/upload_spec.rb | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/upload.rb b/app/models/upload.rb index 262d0e2c600..4a53823df5a 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -224,7 +224,10 @@ class Upload < ActiveRecord::Base max_file_size_kb = [SiteSetting.max_image_size_kb, SiteSetting.max_attachment_size_kb].max.kilobytes local_store = FileStore::LocalStore.new - scope = Upload.where("url NOT LIKE '%/original/_X/%'").order(id: :desc) + scope = Upload.by_users + .where("url NOT LIKE '%/original/_X/%'") + .order(id: :desc) + scope = scope.limit(limit) if limit scope.each do |upload| diff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rb index 95ed94f7dc1..59fa7e40877 100644 --- a/spec/models/upload_spec.rb +++ b/spec/models/upload_spec.rb @@ -250,4 +250,13 @@ describe Upload do end end + describe '.migrate_to_new_scheme' do + it 'should not migrate system uploads' do + SiteSetting.migrate_to_new_scheme = true + + expect { Upload.migrate_to_new_scheme } + .to_not change { Upload.pluck(:url) } + end + end + end