Skip to content

Commit

Permalink
Allow unaltered shelters to be updated during import
Browse files Browse the repository at this point in the history
  • Loading branch information
omnilord committed Sep 3, 2019
1 parent 5523032 commit 8fc07d5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/importers/fema_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def self.shelters

# If not closed, the sheter will likely have staff available to answer Questions
# if shelter-seekers do show up even if they are not accepting at this time.
active: status != 'CLOSED',
archived: !(status != 'CLOSED'), # Yes, double negative
accepting: accepting
}

Expand Down
9 changes: 6 additions & 3 deletions app/jobs/import_fema_shelters_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def deduplicated_import!(data)
Shelter.create!(data)
1
else
unarchive!(shelter)
update!(shelter, data)
0
end
end
Expand Down Expand Up @@ -66,10 +66,13 @@ def find_by_source(data)
Shelter.unscope(:where).where('LOWER(TRIM(source)) = ?', data[:source].strip.downcase)
end

def unarchive!(shelter)
def update!(shelter, data)
_data = shelter.updated_by.blank? ? data : {}
if shelter.archived
logger.info "Unarchiving pre-existing shelter with ID #{shelter.id}"
shelter.update_columns(archived: false, updated_at: Time.now)
_data[:archived] = false
end
shelter.assign_attributes(_data)
shelter.save if shelter.changed?
end
end

0 comments on commit 8fc07d5

Please sign in to comment.