DEV: trigger new discourse events after_create_dev_record & after_populate_dev_records. (#13733)

After every new random record created using the `dev:populate` rake task a new Discourse event will be triggered. So the plugins can modify the records if needed.
This commit is contained in:
Vinoth Kannan 2021-07-15 11:11:41 +05:30 committed by GitHub
parent 31aa701518
commit 76fe3a16a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,18 +18,20 @@ module DiscourseDev
end
@model = model
@type = model.to_s
@type = model.to_s.downcase.to_sym
@count = count
end
def create!
record = model.create!(data)
yield(record) if block_given?
DiscourseEvent.trigger(:after_create_dev_record, record, type)
record
end
def populate!
if current_count >= @count
puts "Already have #{current_count} #{type.downcase} records"
puts "Already have #{current_count} #{type} records"
Rake.application.top_level_tasks.each do |task_name|
Rake::Task[task_name].reenable
@ -39,17 +41,20 @@ module DiscourseDev
return
elsif current_count > 0
@count -= current_count
puts "There are #{current_count} #{type.downcase} records. Creating #{@count} more."
puts "There are #{current_count} #{type} records. Creating #{@count} more."
else
puts "Creating #{@count} sample #{type.downcase} records"
puts "Creating #{@count} sample #{type} records"
end
records = []
@count.times do
create!
records << create!
putc "."
end
DiscourseEvent.trigger(:after_populate_dev_records, records, type)
puts
records
end
def current_count