2014-01-22 00:05:46 -05:00
|
|
|
unless Rails.env.test?
|
2014-05-06 09:41:59 -04:00
|
|
|
meta = Category.find_by(id: SiteSetting.meta_category_id)
|
2014-01-22 00:05:46 -05:00
|
|
|
if meta && !meta.topic_id
|
|
|
|
|
2014-03-19 11:59:53 -04:00
|
|
|
Category.transaction do
|
|
|
|
creator = PostCreator.new(Discourse.system_user,
|
|
|
|
raw: I18n.t('meta_category_description'),
|
|
|
|
title: I18n.t('category.topic_prefix', category: meta.name),
|
|
|
|
category: meta.name,
|
|
|
|
archetype: Archetype.default
|
|
|
|
)
|
|
|
|
post = creator.create
|
2014-01-22 00:05:46 -05:00
|
|
|
|
2014-03-19 11:59:53 -04:00
|
|
|
unless post && post.id
|
|
|
|
puts post.errors.full_messages if post
|
|
|
|
puts creator.errors.inspect
|
|
|
|
raise "Failed meta topic"
|
|
|
|
end
|
2014-01-22 00:05:46 -05:00
|
|
|
|
2017-07-27 21:20:09 -04:00
|
|
|
meta.set_permissions(everyone: :full)
|
2014-03-19 11:59:53 -04:00
|
|
|
meta.topic_id = post.topic.id
|
|
|
|
unless meta.save
|
|
|
|
puts meta.errors.full_messages
|
|
|
|
puts "Failed to set the meta description and permission!"
|
|
|
|
end
|
2014-01-22 00:05:46 -05:00
|
|
|
|
2014-03-19 11:59:53 -04:00
|
|
|
# Reset topic count because we don't count the description topic
|
2018-06-19 02:13:14 -04:00
|
|
|
DB.exec "UPDATE categories SET topic_count = 0 WHERE id = #{meta.id}"
|
2014-03-19 11:59:53 -04:00
|
|
|
end
|
2014-01-22 00:05:46 -05:00
|
|
|
end
|
|
|
|
end
|