app/models/bulk_action.rb in geoblacklight_admin-0.3.2 vs app/models/bulk_action.rb in geoblacklight_admin-0.4.0
- old
+ new
@@ -4,11 +4,13 @@
require "cgi"
# BulkAction
class BulkAction < ApplicationRecord
# Callbacks
- after_create_commit :collect_documents
+ after_create do
+ BulkActionCollectDocuments.perform_later(id)
+ end
# Associations
has_many :documents, class_name: "BulkActionDocument", autosave: false, dependent: :destroy
has_many :bulk_action_transitions, autosave: false, dependent: :destroy
@@ -36,30 +38,31 @@
# state_machine.transition_to!(:imported)
# save
end
def check_run_state
- return if state_machine.current_state == "complete"
+ nil if state_machine.current_state == "complete"
- state_machine.transition_to!(:complete) if documents.in_state(:queued).blank?
+ # @TODO / background job for collecting documents
+ # state_machine.transition_to!(:complete) if documents.in_state(:queued).blank?
end
def revert!
# Queue Revert Job
BulkActionRevertJob.perform_later(self)
end
- private
-
def collect_documents
cgi = CGI.unescape(scope)
uri = URI.parse(cgi)
if uri.path.include?("fetch")
fetch_documents(uri)
else
api_documents(uri)
end
end
+
+ private
def fetch_documents(uri)
qargs = Rack::Utils.parse_nested_query(uri.query)
fetch_documents = Document.where(friendlier_id: qargs["ids"])
create_documents(fetch_documents)