Add trigger post jobs when post is created
Dieser Commit ist enthalten in:
Ursprung
dd3875840b
Commit
9383695c5b
3 geänderte Dateien mit 42 neuen und 9 gelöschten Zeilen
|
@ -10,6 +10,7 @@ class CustomWizard::Action
|
|||
@user = params[:user]
|
||||
@data = params[:data]
|
||||
@log = []
|
||||
@result = CustomWizard::ActionResult.new
|
||||
end
|
||||
|
||||
def perform
|
||||
|
@ -17,15 +18,11 @@ class CustomWizard::Action
|
|||
self.send(action['type'].to_sym)
|
||||
end
|
||||
|
||||
log = "wizard: #{@wizard.id}; action: #{action['type']}; user: #{user.username}"
|
||||
|
||||
if @log.any?
|
||||
@log.each do |item|
|
||||
log << "; #{item.to_s}"
|
||||
end
|
||||
if creates_post? && @result.success?
|
||||
@result.handler.enqueue_jobs
|
||||
end
|
||||
|
||||
CustomWizard::Log.create(log)
|
||||
save_log
|
||||
end
|
||||
|
||||
def mapper
|
||||
|
@ -51,6 +48,7 @@ class CustomWizard::Action
|
|||
|
||||
if creator.errors.blank?
|
||||
log_success("created topic", "id: #{post.topic.id}")
|
||||
result.handler = creator
|
||||
end
|
||||
else
|
||||
log_error("invalid topic params", "title: #{params[:title]}; post: #{params[:raw]}")
|
||||
|
@ -88,6 +86,7 @@ class CustomWizard::Action
|
|||
|
||||
if creator.errors.blank?
|
||||
log_success("created message", "id: #{post.topic.id}")
|
||||
result.handler = creator
|
||||
end
|
||||
else
|
||||
log_error(
|
||||
|
@ -320,6 +319,10 @@ class CustomWizard::Action
|
|||
add_custom_fields(params)
|
||||
end
|
||||
|
||||
def creates_post?
|
||||
[:create_topic, :send_message].include?(action['type'].to_sym)
|
||||
end
|
||||
|
||||
def profile_url_fields
|
||||
['profile_background', 'card_background']
|
||||
end
|
||||
|
@ -371,13 +374,27 @@ class CustomWizard::Action
|
|||
|
||||
def log_success(message, detail = nil)
|
||||
@log.push("success: #{message} - #{detail}")
|
||||
@result.success = true
|
||||
end
|
||||
|
||||
def log_error(message, detail = nil)
|
||||
@log.push("error: #{message} - #{detail}")
|
||||
@result.success = false
|
||||
end
|
||||
|
||||
def log_info(message, detail = nil)
|
||||
@log.push("info: #{message} - #{detail}")
|
||||
end
|
||||
|
||||
def save_log
|
||||
log = "wizard: #{@wizard.id}; action: #{action['type']}; user: #{user.username}"
|
||||
|
||||
if @log.any?
|
||||
@log.each do |item|
|
||||
log << "; #{item.to_s}"
|
||||
end
|
||||
end
|
||||
|
||||
CustomWizard::Log.create(log)
|
||||
end
|
||||
end
|
15
lib/custom_wizard/action_result.rb
Normale Datei
15
lib/custom_wizard/action_result.rb
Normale Datei
|
@ -0,0 +1,15 @@
|
|||
class CustomWizard::ActionResult
|
||||
attr_accessor :success, :handler
|
||||
|
||||
def initialize
|
||||
@success = false
|
||||
end
|
||||
|
||||
def success?
|
||||
@success
|
||||
end
|
||||
|
||||
def failed?
|
||||
!success
|
||||
end
|
||||
end
|
|
@ -55,6 +55,7 @@ after_initialize do
|
|||
../jobs/clear_after_time_wizard.rb
|
||||
../jobs/refresh_api_access_token.rb
|
||||
../jobs/set_after_time_wizard.rb
|
||||
../lib/custom_wizard/action_result.rb
|
||||
../lib/custom_wizard/action.rb
|
||||
../lib/custom_wizard/builder.rb
|
||||
../lib/custom_wizard/field.rb
|
||||
|
|
Laden …
In neuem Issue referenzieren