2014-02-28 06:38:01 +08:00
|
|
|
unless Rails.env.test?
|
2014-05-06 21:41:59 +08:00
|
|
|
staff = Category.find_by(id: SiteSetting.staff_category_id)
|
2017-07-28 09:20:09 +08:00
|
|
|
if staff && !staff.group_ids.include?(Group[:staff].id)
|
2014-02-28 06:38:01 +08:00
|
|
|
|
|
|
|
# Add permissions and a description to the Staff category.
|
|
|
|
|
2014-03-19 23:59:53 +08:00
|
|
|
Category.transaction do
|
|
|
|
staff.group_names = ['staff']
|
2014-03-14 22:26:17 +08:00
|
|
|
unless staff.save
|
|
|
|
puts staff.errors.full_messages
|
2014-03-19 23:59:53 +08:00
|
|
|
raise "Failed to set permissions on the Staff category!"
|
2014-03-14 22:26:17 +08:00
|
|
|
end
|
2014-02-28 06:38:01 +08:00
|
|
|
|
2014-03-19 23:59:53 +08:00
|
|
|
if staff.topic_id.nil?
|
|
|
|
creator = PostCreator.new(Discourse.system_user,
|
|
|
|
raw: I18n.t('staff_category_description'),
|
|
|
|
title: I18n.t('category.topic_prefix', category: staff.name),
|
|
|
|
category: staff.name,
|
|
|
|
archetype: Archetype.default
|
|
|
|
)
|
|
|
|
post = creator.create
|
|
|
|
|
|
|
|
unless post && post.id
|
|
|
|
puts post.errors.full_messages if post
|
|
|
|
puts creator.errors.inspect
|
|
|
|
raise "Failed to create description for Staff category!"
|
|
|
|
end
|
|
|
|
|
|
|
|
staff.topic_id = post.topic.id
|
|
|
|
unless staff.save
|
|
|
|
puts staff.errors.full_messages
|
|
|
|
puts "Failed to set the Staff category description topic!"
|
|
|
|
end
|
|
|
|
|
|
|
|
# Reset topic count because we don't count the description topic
|
2018-06-19 14:13:14 +08:00
|
|
|
DB.exec "UPDATE categories SET topic_count = 0 WHERE id = #{staff.id}"
|
2014-03-19 23:59:53 +08:00
|
|
|
end
|
2014-03-14 22:26:17 +08:00
|
|
|
end
|
2014-02-28 06:38:01 +08:00
|
|
|
end
|
|
|
|
end
|