Class: BulkActionRevertDocumentJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/bulk_action_revert_document_job.rb

Overview

BulkActionRevertDocumentJob

Instance Method Summary collapse

Instance Method Details

#perform(action, doc) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'app/jobs/bulk_action_revert_document_job.rb', line 7

def perform(action, doc)
  case action
  when :revert_publication_status
    revert_publication_status(doc)
  when :revert_delete
    revert_delete(doc)
  else
    logger.debug("@TODO - #{field_name} => #{field_value}")
  end
end

#revert_delete(doc) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/jobs/bulk_action_revert_document_job.rb', line 34

def revert_delete(doc)
  document = Document.new(id: doc.document_id)

  logger.debug("Revert Delete - #{document.id}")

  versions = document.versions
  document = versions.last.reify
  document.skip_callbacks = true

  if document.save
    doc.state_machine.transition_to!(:success)
  else
    doc.state_machine.transition_to!(:failed)
  end
end

#revert_publication_status(doc) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/jobs/bulk_action_revert_document_job.rb', line 18

def revert_publication_status(doc)
  document = Document.find_by!(friendlier_id: doc.friendlier_id)

  logger.debug("Revert PubStatus - #{document.friendlier_id}")

  versions = document.versions
  document = versions[doc.version].reify
  document.skip_callbacks = true

  if document.save
    doc.state_machine.transition_to!(:success)
  else
    doc.state_machine.transition_to!(:failed)
  end
end