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



30
31
32
33
34
35
36
37
38
39
40
# File 'app/jobs/bulk_action_revert_document_job.rb', line 30

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

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

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

  document.save
end

#revert_publication_status(doc) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# 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.current_version].reify
  document&.skip_callbacks = true

  document.save
end