mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:42:02 +08:00
DEV: Populate first and last seen at timestamps. (#17643)
discourse-chat's auto-join users rely on these values, so it's handy for the populate task to set them.
This commit is contained in:
parent
424a274c12
commit
6df36247c1
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'discourse_dev/record'
|
||||
require 'faker'
|
||||
require "discourse_dev/record"
|
||||
require "faker"
|
||||
|
||||
module DiscourseDev
|
||||
class User < Record
|
||||
|
@ -19,6 +19,8 @@ module DiscourseDev
|
|||
username = Faker::Internet.unique.username(specifier: ::User.username_length)
|
||||
username = UserNameSuggester.suggest(username)
|
||||
username_lower = ::User.normalize_username(username)
|
||||
created_at = Faker::Time.between(from: DiscourseDev.config.start_date, to: DateTime.now)
|
||||
seen_at = Faker::Time.between(from: created_at, to: DateTime.now)
|
||||
|
||||
{
|
||||
name: name,
|
||||
|
@ -27,7 +29,9 @@ module DiscourseDev
|
|||
username_lower: username_lower,
|
||||
moderator: Faker::Boolean.boolean(true_ratio: 0.1),
|
||||
trust_level: Faker::Number.between(from: 1, to: 4),
|
||||
created_at: Faker::Time.between(from: DiscourseDev.config.start_date, to: DateTime.now),
|
||||
created_at: created_at,
|
||||
first_seen_at: seen_at,
|
||||
last_seen_at: seen_at,
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -35,7 +39,9 @@ module DiscourseDev
|
|||
super do |user|
|
||||
user.activate
|
||||
set_random_avatar(user)
|
||||
Faker::Number.between(from: 0, to: 2).times do
|
||||
Faker::Number
|
||||
.between(from: 0, to: 2)
|
||||
.times do
|
||||
group = Group.random
|
||||
|
||||
group.add(user)
|
||||
|
@ -70,7 +76,7 @@ module DiscourseDev
|
|||
STDERR.puts "Failed to upload avatar for user #{user.username}: #{avatar_path}"
|
||||
STDERR.puts upload.errors.inspect if upload
|
||||
end
|
||||
rescue
|
||||
rescue StandardError
|
||||
STDERR.puts "Failed to create avatar for user #{user.username}: #{avatar_path}"
|
||||
ensure
|
||||
tempfile.close! if tempfile
|
||||
|
@ -80,11 +86,9 @@ module DiscourseDev
|
|||
|
||||
def copy_to_tempfile(source_path)
|
||||
extension = File.extname(source_path)
|
||||
tmp = Tempfile.new(['discourse-upload', extension])
|
||||
tmp = Tempfile.new(["discourse-upload", extension])
|
||||
|
||||
File.open(source_path) do |source_stream|
|
||||
IO.copy_stream(source_stream, tmp)
|
||||
end
|
||||
File.open(source_path) { |source_stream| IO.copy_stream(source_stream, tmp) }
|
||||
|
||||
tmp.rewind
|
||||
tmp
|
||||
|
|
Loading…
Reference in New Issue
Block a user