mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
fix migration. Create dummy user if user doesn't exist, make sure all event_users records are valid
This commit is contained in:
parent
a620950383
commit
eef902291d
1 changed files with 22 additions and 3 deletions
|
|
@ -9,16 +9,35 @@ class AddUsersToEvents < ActiveRecord::Migration
|
|||
|
||||
class TempEventUser < ActiveRecord::Base
|
||||
self.table_name = 'event_users'
|
||||
belongs_to :temp_event
|
||||
belongs_to :temp_user
|
||||
attr_accessible :event_id, :user_id, :event_role
|
||||
end
|
||||
|
||||
def up
|
||||
TempEvent.all.each do |event|
|
||||
if TempEventUser.where(event_id: event).blank?
|
||||
# Assign sample user (created in seeds)
|
||||
user = User.find_by(email: 'deleted@localhost.osem')
|
||||
# Create dummy user, if user doesn't exist
|
||||
unless (user = User.find_by(email: 'deleted@localhost.osem'))
|
||||
user = User.new(email: 'deleted@localhost.osem', name: 'User deleted',
|
||||
biography: 'Data is no longer available for deleted user.',
|
||||
password: Devise.friendly_token[0, 20])
|
||||
user.skip_confirmation!
|
||||
user.save!
|
||||
end
|
||||
|
||||
event_users = TempEventUser.where(event_id: event)
|
||||
if event_users.blank?
|
||||
# Non existing users for event
|
||||
TempEventUser.create!(event_id: event.id, user_id: user.id, event_role: 'submitter')
|
||||
TempEventUser.create!(event_id: event.id, user_id: user.id, event_role: 'speaker')
|
||||
else
|
||||
# Wrong records in event_users
|
||||
event_users.each do |eu|
|
||||
unless eu.temp_user.present?
|
||||
eu.user_id = user.id
|
||||
eu.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue