FIX: don't try to create category description topic if it already exists

This commit is contained in:
Neil Lalonde 2014-03-14 10:26:17 -04:00
parent a07062644c
commit 99285f73e7
2 changed files with 44 additions and 40 deletions

View File

@ -11,27 +11,29 @@ unless Rails.env.test?
raise "Failed to set permissions on trust level 3 lounge category!" raise "Failed to set permissions on trust level 3 lounge category!"
end end
creator = PostCreator.new(Discourse.system_user, if lounge.topic_id.nil?
raw: I18n.t('vip_category_description'), creator = PostCreator.new(Discourse.system_user,
title: I18n.t('category.topic_prefix', category: lounge.name), raw: I18n.t('vip_category_description'),
category: lounge.name, title: I18n.t('category.topic_prefix', category: lounge.name),
archetype: Archetype.default category: lounge.name,
) archetype: Archetype.default
post = creator.create )
post = creator.create
unless post && post.id unless post && post.id
puts post.errors.full_messages if post puts post.errors.full_messages if post
puts creator.errors.inspect puts creator.errors.inspect
raise "Failed to create description for trust level 3 lounge!" raise "Failed to create description for trust level 3 lounge!"
end
lounge.topic_id = post.topic.id
unless lounge.save
puts lounge.errors.full_messages
puts "Failed to set the lounge description topic!"
end
# Reset topic count because we don't count the description topic
Category.exec_sql "UPDATE categories SET topic_count = 0 WHERE id = #{lounge.id}"
end end
lounge.topic_id = post.topic.id
unless lounge.save
puts lounge.errors.full_messages
puts "Failed to set the lounge description topic!"
end
# Reset topic count because we don't count the description topic
Category.exec_sql "UPDATE categories SET topic_count = 0 WHERE id = #{lounge.id}"
end end
end end

View File

@ -10,27 +10,29 @@ unless Rails.env.test?
raise "Failed to set permissions on the Staff category!" raise "Failed to set permissions on the Staff category!"
end end
creator = PostCreator.new(Discourse.system_user, if staff.topic_id.nil?
raw: I18n.t('staff_category_description'), creator = PostCreator.new(Discourse.system_user,
title: I18n.t('category.topic_prefix', category: staff.name), raw: I18n.t('staff_category_description'),
category: staff.name, title: I18n.t('category.topic_prefix', category: staff.name),
archetype: Archetype.default category: staff.name,
) archetype: Archetype.default
post = creator.create )
post = creator.create
unless post && post.id unless post && post.id
puts post.errors.full_messages if post puts post.errors.full_messages if post
puts creator.errors.inspect puts creator.errors.inspect
raise "Failed to create description for Staff category!" 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
Category.exec_sql "UPDATE categories SET topic_count = 0 WHERE id = #{staff.id}"
end 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
Category.exec_sql "UPDATE categories SET topic_count = 0 WHERE id = #{staff.id}"
end end
end end