mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Add fixed_category_positions site setting to handle whether categories are ordered by specified positions or by activity.
This commit is contained in:
@@ -9,7 +9,7 @@ class AddUncategorizedCategory < ActiveRecord::Migration
|
||||
|
||||
result = execute "INSERT INTO categories
|
||||
(name,color,slug,description,text_color, user_id, created_at, updated_at, position)
|
||||
VALUES ('#{name}', 'AB9364', 'uncategorized', '', 'FFFFFF', -1, now(), now(), 1 )
|
||||
VALUES ('#{name}', 'AB9364', 'uncategorized', '', 'FFFFFF', -1, now(), now(), 0 )
|
||||
RETURNING id
|
||||
"
|
||||
category_id = result[0]["id"].to_i
|
||||
|
||||
@@ -13,8 +13,8 @@ class AddLoungeCategory < ActiveRecord::Migration
|
||||
end
|
||||
|
||||
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)
|
||||
(name, color, text_color, created_at, updated_at, user_id, slug, description, read_restricted, position)
|
||||
VALUES ('#{name}', 'EEEEEE', '652D90', now(), now(), -1, '#{Slug.for(name)}', '#{description}', true, 3)
|
||||
RETURNING id"
|
||||
category_id = result[0]["id"].to_i
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ class AddMetaCategory < ActiveRecord::Migration
|
||||
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}', '808281', 'FFFFFF', now(), now(), -1, '#{Slug.for(name)}', '#{description}', true)
|
||||
(name, color, text_color, created_at, updated_at, user_id, slug, description, read_restricted, position)
|
||||
VALUES ('#{name}', '808281', 'FFFFFF', now(), now(), -1, '#{Slug.for(name)}', '#{description}', true, 1)
|
||||
RETURNING id"
|
||||
category_id = result[0]["id"].to_i
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ class AddStaffCategory < ActiveRecord::Migration
|
||||
name = I18n.t('staff_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}', '283890', 'FFFFFF', now(), now(), -1, '#{Slug.for(name)}', '#{description}', true)
|
||||
(name, color, text_color, created_at, updated_at, user_id, slug, description, read_restricted, position)
|
||||
VALUES ('#{name}', '283890', 'FFFFFF', now(), now(), -1, '#{Slug.for(name)}', '#{description}', true, 2)
|
||||
RETURNING id"
|
||||
category_id = result[0]["id"].to_i
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
class InitFixedCategoryPositionsValue < ActiveRecord::Migration
|
||||
def up
|
||||
# Look at existing categories to determine if positions have been specified
|
||||
result = Category.exec_sql("SELECT count(*) FROM categories WHERE position IS NOT NULL")
|
||||
|
||||
# Greater than 4 because uncategorized, meta, staff, lounge all have positions by default
|
||||
if result[0]['count'].to_i > 4
|
||||
execute "INSERT INTO site_settings (name, data_type, value, created_at, updated_at) VALUES ('fixed_category_positions', 5, 't', now(), now())"
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
execute "DELETE FROM site_settings WHERE name = 'fixed_category_positions'"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user