mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 15:52:11 +08:00
Base importer: Calculate category colors depending on parent category
This commit is contained in:
parent
23acddc9fa
commit
fb022098f6
|
@ -32,6 +32,7 @@ class ImportScripts::Base
|
|||
@old_site_settings = {}
|
||||
@start_times = { import: Time.now }
|
||||
@skip_updates = false
|
||||
@next_category_color_index = {}
|
||||
end
|
||||
|
||||
def preload_i18n
|
||||
|
@ -445,7 +446,7 @@ class ImportScripts::Base
|
|||
user_id: opts[:user_id] || opts[:user].try(:id) || Discourse::SYSTEM_USER_ID,
|
||||
position: opts[:position],
|
||||
parent_category_id: opts[:parent_category_id],
|
||||
color: opts[:color] || category_color,
|
||||
color: opts[:color] || category_color(opts[:parent_category_id]),
|
||||
text_color: opts[:text_color] || "FFF",
|
||||
read_restricted: opts[:read_restricted] || false,
|
||||
)
|
||||
|
@ -466,11 +467,11 @@ class ImportScripts::Base
|
|||
new_category
|
||||
end
|
||||
|
||||
def category_color
|
||||
def category_color(parent_category_id)
|
||||
@category_colors ||= SiteSetting.category_colors.split('|')
|
||||
|
||||
index = @next_category_color_index.presence || 0
|
||||
@next_category_color_index = index + 1 >= @category_colors.count ? 0 : index + 1
|
||||
index = @next_category_color_index[parent_category_id].presence || 0
|
||||
@next_category_color_index[parent_category_id] = index + 1 >= @category_colors.count ? 0 : index + 1
|
||||
|
||||
@category_colors[index]
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user