mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-03-30 16:50:10 -04:00
FIX: ensure consistency of user options
Edge case during upgrade can cause accounts registered after migration prior to restart to have missing user option records
This commit is contained in:
parent
e947c3b9ec
commit
433fa74d87
3 changed files with 21 additions and 0 deletions
|
@ -14,6 +14,7 @@ module Jobs
|
|||
Topic.ensure_consistency!
|
||||
Badge.ensure_consistency!
|
||||
CategoryUser.ensure_consistency!
|
||||
UserOption.ensure_consistency!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,6 +5,14 @@ class UserOption < ActiveRecord::Base
|
|||
|
||||
after_save :update_tracked_topics
|
||||
|
||||
def self.ensure_consistency!
|
||||
exec_sql("SELECT u.id FROM users u
|
||||
LEFT JOIN user_options o ON o.user_id = u.id
|
||||
WHERE o.user_id IS NULL").values.each do |id,_|
|
||||
UserOption.create(user_id: id.to_i)
|
||||
end
|
||||
end
|
||||
|
||||
def self.previous_replies_type
|
||||
@previous_replies_type ||= Enum.new(always: 0, unless_emailed: 1, never: 2)
|
||||
end
|
||||
|
|
|
@ -3,6 +3,18 @@ require_dependency 'user_option'
|
|||
|
||||
describe UserOption do
|
||||
|
||||
describe "#ensure_consistency!" do
|
||||
it "recreates missing user option records" do
|
||||
user = Fabricate(:user)
|
||||
user.user_option.destroy
|
||||
UserOption.ensure_consistency!
|
||||
|
||||
user.reload
|
||||
|
||||
expect(user.user_option.email_always).to eq(SiteSetting.default_email_always)
|
||||
end
|
||||
end
|
||||
|
||||
describe "should_be_redirected_to_top" do
|
||||
let!(:user) { Fabricate(:user) }
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue