Skip to content

Instantly share code, notes, and snippets.

@jcreed
Created May 7, 2019 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcreed/5eae4035403ed16e1e71d5945ab49ea0 to your computer and use it in GitHub Desktop.
Save jcreed/5eae4035403ed16e1e71d5945ab49ea0 to your computer and use it in GitHub Desktop.
export header field update task
namespace :transfer_exports do
desc "Update The Common Application exports custom headers for custom questions"
task :update, [:cycle] => [:environment] do |task, args|
extend ReleaseTaskHelpers
cycle = args[:cycle]
if Cycle.where(identifier: cycle)
display :notice, task.full_comment
with_association('The Common Application', cycle) do |cas|
cas.user_identities.each do |user_identity|
user_identity.exports.each do |export|
export.exports_fields.each do |export_field|
print "export field start "
field = export_field.field
debugger
if (/^custom_questions_/ === field.identifier && export_field.header.blank?)
prev_field = Field.find_by_previous_field_identifier(user_identity, field.identifier)
next unless prev_field
ef.header = prev_field.identifier
puts "export field updated: #{ef.id}"
ef.save
end
end
end
end
end
else
display :error, "Cycle #{cycle} does not exist."
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment