Skip to content

Commit

Permalink
Added rollback for required_report last_published_date on deletion
Browse files Browse the repository at this point in the history
Added submission_id to required_report_due_dates table
  • Loading branch information
zgary committed Jan 7, 2020
1 parent d77e195 commit 4bb16b9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
30 changes: 29 additions & 1 deletion app/controllers/concerns/hyrax/works_controller_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def create
report_due_date_id = params[hash_key_for_curation_concern]['report_due_date_id']
if report_due_date_id.present?
required_report_due_date = RequiredReportDueDate.where(id: params[hash_key_for_curation_concern]['report_due_date_id']).first
required_report_due_date.update_attributes(date_submitted: Time.current)
required_report_due_date.update_attributes(submission_id: curation_concern.id, date_submitted: Time.current)
end

after_create_response
Expand Down Expand Up @@ -117,9 +117,37 @@ def update

def destroy
title = curation_concern.to_s
agency = curation_concern.agency
required_report_name = curation_concern.required_report_name
submission_id = curation_concern.id

env = Actors::Environment.new(curation_concern, current_ability, {})
return unless actor.destroy(env)
Hyrax.config.callback.run(:after_destroy, curation_concern.id, current_user)

# Query for publications with required_report
publications = NycGovernmentPublication.where(required_report_name: required_report_name,
agency: agency)
.order('date_published_ssi desc')
required_report = RequiredReport.where(agency_name: agency, name: required_report_name).first
required_report_due_date = RequiredReportDueDate.where(submission_id: submission_id).first

# If there are no previous publications, set date_published to nil
if publications.present?
publications.each do |p|
if !(p.suppressed?)
# Set required_report.date_published to the publication with the next chronological published date
required_report.update_attributes(last_published_date: p.date_published)
break
end
end
else
required_report.update_attributes(last_published_date: nil)
end

# Set submission_id and date_submitted to nil in required_report_due_dates
required_report_due_date.update_attributes(submission_id: nil, date_submitted: nil)

after_destroy_response(title)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def change
t.date :due_date, null: false
t.datetime :date_submitted
t.datetime :delinquency_report_published_date
t.string :submission_id

t.timestamps
end
Expand Down
1 change: 1 addition & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@
t.date "due_date", null: false
t.datetime "date_submitted"
t.datetime "delinquency_report_published_date"
t.string "submission_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["required_report_id"], name: "index_required_report_due_dates_on_required_report_id"
Expand Down

0 comments on commit 4bb16b9

Please sign in to comment.