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:
parent
31aa701518
commit
76fe3a16a9
|
@ -18,18 +18,20 @@ module DiscourseDev
|
||||||
end
|
end
|
||||||
|
|
||||||
@model = model
|
@model = model
|
||||||
@type = model.to_s
|
@type = model.to_s.downcase.to_sym
|
||||||
@count = count
|
@count = count
|
||||||
end
|
end
|
||||||
|
|
||||||
def create!
|
def create!
|
||||||
record = model.create!(data)
|
record = model.create!(data)
|
||||||
yield(record) if block_given?
|
yield(record) if block_given?
|
||||||
|
DiscourseEvent.trigger(:after_create_dev_record, record, type)
|
||||||
|
record
|
||||||
end
|
end
|
||||||
|
|
||||||
def populate!
|
def populate!
|
||||||
if current_count >= @count
|
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.application.top_level_tasks.each do |task_name|
|
||||||
Rake::Task[task_name].reenable
|
Rake::Task[task_name].reenable
|
||||||
|
@ -39,17 +41,20 @@ module DiscourseDev
|
||||||
return
|
return
|
||||||
elsif current_count > 0
|
elsif current_count > 0
|
||||||
@count -= current_count
|
@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
|
else
|
||||||
puts "Creating #{@count} sample #{type.downcase} records"
|
puts "Creating #{@count} sample #{type} records"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
records = []
|
||||||
@count.times do
|
@count.times do
|
||||||
create!
|
records << create!
|
||||||
putc "."
|
putc "."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
DiscourseEvent.trigger(:after_populate_dev_records, records, type)
|
||||||
puts
|
puts
|
||||||
|
records
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_count
|
def current_count
|
||||||
|
|
Loading…
Reference in New Issue