Base importer: Calculate category colors depending on parent category

This commit is contained in:
Gerhard Schlager 2018-06-27 20:27:11 +02:00
parent 23acddc9fa
commit fb022098f6
1 changed files with 5 additions and 4 deletions

View File

@ -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