2019-04-29 20:25:53 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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
|
|
|
|
2016-09-12 14:43:00 -04:00
|
|
|
attr_accessor :refresh_required, :fields
|
2016-09-09 16:51:07 -04:00
|
|
|
|
2016-09-12 14:43:00 -04:00
|
|
|
def initialize(current_user, step, fields)
|
2016-08-25 13:14:56 -04:00
|
|
|
@current_user = current_user
|
2016-09-09 16:51:07 -04:00
|
|
|
@step = step
|
2016-09-07 18:04:01 -04:00
|
|
|
@refresh_required = false
|
2016-09-12 14:43:00 -04:00
|
|
|
@fields = fields
|
2016-08-25 13:14:56 -04:00
|
|
|
end
|
|
|
|
|
2016-09-12 14:43:00 -04:00
|
|
|
def update
|
2016-09-14 16:36:08 -04:00
|
|
|
@step.updater.call(self) if @step.present? && @step.updater.present?
|
|
|
|
|
|
|
|
if success?
|
|
|
|
logger = StaffActionLogger.new(@current_user)
|
|
|
|
logger.log_wizard_step(@step)
|
|
|
|
end
|
2016-09-08 16:58:07 -04:00
|
|
|
end
|
|
|
|
|
2016-08-25 13:14:56 -04:00
|
|
|
def success?
|
|
|
|
@errors.blank?
|
|
|
|
end
|
|
|
|
|
2016-09-07 18:04:01 -04:00
|
|
|
def refresh_required?
|
|
|
|
@refresh_required
|
|
|
|
end
|
|
|
|
|
2016-09-09 16:51:07 -04:00
|
|
|
def update_setting(id, value)
|
2019-04-29 20:25:53 -04:00
|
|
|
value = value.strip if value.is_a?(String)
|
2018-11-14 02:03:02 -05:00
|
|
|
|
|
|
|
if !value.is_a?(Upload) && SiteSetting.type_supervisor.get_type(id) == :upload
|
|
|
|
value = Upload.get_from_url(value) || ""
|
|
|
|
end
|
|
|
|
|
2019-05-06 21:00:09 -04:00
|
|
|
SiteSetting.set_and_log(id, value, @current_user) if SiteSetting.get(id) != value
|
2016-09-09 16:51:07 -04:00
|
|
|
end
|
2016-09-09 15:57:44 -04:00
|
|
|
|
2016-09-12 14:43:00 -04:00
|
|
|
def apply_setting(id)
|
|
|
|
update_setting(id, @fields[id])
|
2016-09-09 16:51:07 -04:00
|
|
|
rescue Discourse::InvalidParameters => e
|
2016-09-12 14:43:00 -04:00
|
|
|
errors.add(id, e.message)
|
|
|
|
end
|
|
|
|
|
2016-09-15 16:01:44 -04:00
|
|
|
def ensure_changed(id)
|
|
|
|
errors.add(id, "") if @fields[id] == SiteSetting.defaults[id]
|
|
|
|
end
|
|
|
|
|
2016-09-12 14:43:00 -04:00
|
|
|
def apply_settings(*ids)
|
|
|
|
ids.each { |id| apply_setting(id) }
|
2016-09-09 16:51:07 -04:00
|
|
|
end
|
2016-08-25 13:14:56 -04:00
|
|
|
end
|
|
|
|
end
|