A platform for community discussion. Free, open, simple.
DEV: fix chat:*:populate rake tasks (#29740)
Régis Hanolfea82d04ec5f
diff --git a/plugins/chat/lib/discourse_dev/category_channel.rb b/plugins/chat/lib/discourse_dev/category_channel.rbindex b1c4cd68592..277c9c69d38 100644--- a/plugins/chat/lib/discourse_dev/category_channel.rb+++ b/plugins/chat/lib/discourse_dev/category_channel.rb@@ -5,20 +5,17 @@ require "faker"module DiscourseDevclass CategoryChannel < Record- def initialize- super(::Chat::CategoryChannel, 5)+ def initialize(ignore_current_count: true, count: 5, channel_id: nil)+ super(::Chat::CategoryChannel, count)enddef datachatable = Category.random+ description = Faker::Lorem.sentence+ name = Faker::Company.name+ created_at = Faker::Time.between(from: DiscourseDev.config.start_date, to: DateTime.now)- {- chatable: chatable,- description: Faker::Lorem.paragraph,- user_count: 1,- name: Faker::Company.name,- created_at: Faker::Time.between(from: DiscourseDev.config.start_date, to: DateTime.now),- }+ { chatable:, description:, user_count: 1, name:, created_at: }enddef create!@@ -30,14 +27,19 @@ module DiscourseDevif Faker::Boolean.boolean(true_ratio: 0.5)admin_username =begin- DiscourseDev::Config.new.config[:admin][:username]+ DiscourseDev.config.admin[:username]rescue StandardErrornilend- admin_user = ::User.find_by(username: admin_username) if admin_username+ admin_user = ::User.find_by_username(admin_username) if admin_usernameend- user = admin_user || User.new(username: Faker::Internet.username(specifier: 10)).create!+ user =+ admin_user ||+ ::User.create!(+ email: Faker::Internet.email,+ username: Faker::Internet.username(specifier: 10),+ )Chat::ChannelMembershipManager.new(channel).follow(user)users << userend@@ -47,8 +49,10 @@ module DiscourseDev.times doChat::CreateMessage.call(guardian: users.sample.guardian,- chat_channel_id: channel.id,- message: Faker::Lorem.paragraph,+ params: {+ chat_channel_id: channel.id,+ message: Faker::Lorem.sentence,+ },)endenddiff --git a/plugins/chat/lib/tasks/chat.rake b/plugins/chat/lib/tasks/chat.rakeindex 2e91673c900..03dc08a4a56 100644--- a/plugins/chat/lib/tasks/chat.rake+++ b/plugins/chat/lib/tasks/chat.rake@@ -3,24 +3,16 @@if Discourse.allow_dev_populate?desc "Generates sample messages in channels"task "chat:message:populate", %i[channel_id count] => ["db:load_config"] do |_, args|- DiscourseDev::Message.populate!(- ignore_current_count: true,- channel_id: args[:channel_id],- count: args[:count],- )+ DiscourseDev::Message.populate!(channel_id: args[:channel_id], count: args[:count])enddesc "Generates random channels from categories"task "chat:category_channel:populate" => ["db:load_config"] do |_, args|- DiscourseDev::CategoryChannel.populate!(ignore_current_count: true)+ DiscourseDev::CategoryChannel.populate!enddesc "Creates a thread with sample messages in a channel"- task "chat:thread:populate", %i[channel_id message_count] => ["db:load_config"] do |_, args|- DiscourseDev::Thread.populate!(- ignore_current_count: true,- channel_id: args[:channel_id],- message_count: args[:message_count],- )+ task "chat:thread:populate", %i[channel_id count] => ["db:load_config"] do |_, args|+ DiscourseDev::Thread.populate!(channel_id: args[:channel_id], count: args[:count])endend