Created
May 7, 2019 20:04
-
-
Save jcreed/5eae4035403ed16e1e71d5945ab49ea0 to your computer and use it in GitHub Desktop.
export header field update task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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