2016-08-25 13:14:56 -04:00
|
|
|
class Wizard
|
|
|
|
class StepUpdater
|
2016-08-31 13:35:49 -04:00
|
|
|
include ActiveModel::Model
|
2016-08-25 13:14:56 -04:00
|
|
|
|
|
|
|
def initialize(current_user, id)
|
|
|
|
@current_user = current_user
|
|
|
|
@id = id
|
|
|
|
end
|
|
|
|
|
|
|
|
def update(fields)
|
|
|
|
updater_method = "update_#{@id.underscore}".to_sym
|
2016-08-31 13:35:49 -04:00
|
|
|
send(updater_method, fields.symbolize_keys) if respond_to?(updater_method)
|
2016-08-25 13:14:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def update_forum_title(fields)
|
|
|
|
update_setting(:title, fields, :title)
|
|
|
|
update_setting(:site_description, fields, :site_description)
|
|
|
|
end
|
|
|
|
|
2016-08-31 13:35:49 -04:00
|
|
|
def update_contact(fields)
|
|
|
|
update_setting(:contact_email, fields, :contact_email)
|
|
|
|
update_setting(:contact_url, fields, :contact_url)
|
|
|
|
update_setting(:site_contact_username, fields, :site_contact_username)
|
|
|
|
end
|
|
|
|
|
2016-09-02 11:42:14 -04:00
|
|
|
def update_colors(fields)
|
|
|
|
scheme_name = fields[:color_scheme]
|
|
|
|
|
|
|
|
theme = ColorScheme.themes.find {|s| s[:id] == scheme_name }
|
|
|
|
|
|
|
|
colors = []
|
|
|
|
theme[:colors].each do |name, hex|
|
|
|
|
colors << {name: name, hex: hex[1..-1] }
|
|
|
|
end
|
|
|
|
|
|
|
|
attrs = {
|
|
|
|
enabled: true,
|
|
|
|
name: I18n.t("wizard.step.colors.fields.color_scheme.options.#{scheme_name}"),
|
|
|
|
colors: colors
|
|
|
|
}
|
|
|
|
|
|
|
|
scheme = ColorScheme.where(via_wizard: true).first
|
|
|
|
if scheme.present?
|
|
|
|
attrs[:colors] = colors
|
|
|
|
revisor = ColorSchemeRevisor.new(scheme, attrs)
|
|
|
|
revisor.revise
|
|
|
|
else
|
|
|
|
attrs[:via_wizard] = true
|
|
|
|
scheme = ColorScheme.new(attrs)
|
|
|
|
scheme.save!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-25 13:14:56 -04:00
|
|
|
def success?
|
|
|
|
@errors.blank?
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def update_setting(id, fields, field_id)
|
|
|
|
value = fields[field_id]
|
|
|
|
value.strip! if value.is_a?(String)
|
2016-08-31 13:35:49 -04:00
|
|
|
|
|
|
|
SiteSetting.set_and_log(id, value, @current_user) if SiteSetting.send(id) != value
|
2016-08-25 13:14:56 -04:00
|
|
|
rescue Discourse::InvalidParameters => e
|
2016-08-31 13:35:49 -04:00
|
|
|
errors.add(field_id, e.message)
|
2016-08-25 13:14:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|