diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index ce46a7a98..c0ea1d751 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -191,6 +191,9 @@ en: vip_category_name: "Lounge" vip_category_description: "A category exclusive to members with trust level 3 and higher." + meta_category_name: "Meta" + meta_category_description: "A category to discuss issues related to this forum" + category: topic_prefix: "Category definition for %{category}" replace_paragraph: "[Replace this first paragraph with a short description of your new category. This guidance will appear in the category selection area, so try to keep it below 200 characters. Until you edit this text or create topics, this category won't appear on the categories page.]" diff --git a/config/site_settings.yml b/config/site_settings.yml index fe3f0078f..e91c24f55 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -426,5 +426,7 @@ uncategorized: lounge_category_id: default: -1 hidden: true - + meta_category_id: + default: -1 + hidden: true diff --git a/db/fixtures/501_meta_category.rb b/db/fixtures/501_meta_category.rb new file mode 100644 index 000000000..d8b0b9724 --- /dev/null +++ b/db/fixtures/501_meta_category.rb @@ -0,0 +1,29 @@ +unless Rails.env.test? + meta = Category.where(id: SiteSetting.meta_category_id).first + if meta && !meta.topic_id + + 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 + + unless post && post.id + puts post.errors.full_messages if post + puts creator.errors.inspect + raise "Failed meta topic" + end + + meta.set_permissions(:everyone => :full) + meta.topic_id = post.topic.id + unless meta.save + puts meta.errors.full_messages + puts "Failed to set the meta description and permission!" + end + + # Reset topic count because we don't count the description topic + Category.exec_sql "UPDATE categories SET topic_count = 0 WHERE id = #{meta.id}" + end +end diff --git a/db/migrate/20140122043508_add_meta_category.rb b/db/migrate/20140122043508_add_meta_category.rb new file mode 100644 index 000000000..959754f27 --- /dev/null +++ b/db/migrate/20140122043508_add_meta_category.rb @@ -0,0 +1,28 @@ +class AddMetaCategory < ActiveRecord::Migration + def up + unless Rails.env.test? + result = Category.exec_sql "SELECT 1 FROM site_settings where name = 'meta_category_id'" + if result.count == 0 + description = I18n.t('meta_category_description') + + name = I18n.t('meta_category_name') + if Category.exec_sql("SELECT 1 FROM categories where name ilike '#{name}'").count == 0 + result = execute "INSERT INTO categories + (name, color, text_color, created_at, updated_at, user_id, slug, description, read_restricted) + VALUES ('#{name}', 'EEEEEE', '652D90', now(), now(), -1, '#{Slug.for(name)}', '#{description}', true) + RETURNING id" + category_id = result[0]["id"].to_i + + execute "INSERT INTO site_settings(name, data_type, value, created_at, updated_at) + VALUES ('meta_category_id', 3, #{category_id}, now(), now())" + end + + end + end + end + + def down + # Don't reverse this change. There is so much logic around deleting a category that it's messy + # to try to do in sql. The up method will just make sure never to create the category twice. + end +end