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 = {}
|
@old_site_settings = {}
|
||||||
@start_times = { import: Time.now }
|
@start_times = { import: Time.now }
|
||||||
@skip_updates = false
|
@skip_updates = false
|
||||||
|
@next_category_color_index = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def preload_i18n
|
def preload_i18n
|
||||||
|
@ -445,7 +446,7 @@ class ImportScripts::Base
|
||||||
user_id: opts[:user_id] || opts[:user].try(:id) || Discourse::SYSTEM_USER_ID,
|
user_id: opts[:user_id] || opts[:user].try(:id) || Discourse::SYSTEM_USER_ID,
|
||||||
position: opts[:position],
|
position: opts[:position],
|
||||||
parent_category_id: opts[:parent_category_id],
|
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",
|
text_color: opts[:text_color] || "FFF",
|
||||||
read_restricted: opts[:read_restricted] || false,
|
read_restricted: opts[:read_restricted] || false,
|
||||||
)
|
)
|
||||||
|
@ -466,11 +467,11 @@ class ImportScripts::Base
|
||||||
new_category
|
new_category
|
||||||
end
|
end
|
||||||
|
|
||||||
def category_color
|
def category_color(parent_category_id)
|
||||||
@category_colors ||= SiteSetting.category_colors.split('|')
|
@category_colors ||= SiteSetting.category_colors.split('|')
|
||||||
|
|
||||||
index = @next_category_color_index.presence || 0
|
index = @next_category_color_index[parent_category_id].presence || 0
|
||||||
@next_category_color_index = index + 1 >= @category_colors.count ? 0 : index + 1
|
@next_category_color_index[parent_category_id] = index + 1 >= @category_colors.count ? 0 : index + 1
|
||||||
|
|
||||||
@category_colors[index]
|
@category_colors[index]
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue