From afea0325444cc476f73ee34fcf81ca14c6bf6ed9 Mon Sep 17 00:00:00 2001 From: CL Fisher Date: Wed, 4 Dec 2024 07:06:46 -0500 Subject: [PATCH 1/2] clean up social media, request types and pick up emails --- ...111437_cleanup_invalid_partner_profiles.rb | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 db/migrate/20241204111437_cleanup_invalid_partner_profiles.rb diff --git a/db/migrate/20241204111437_cleanup_invalid_partner_profiles.rb b/db/migrate/20241204111437_cleanup_invalid_partner_profiles.rb new file mode 100644 index 0000000000..d0f7f3012f --- /dev/null +++ b/db/migrate/20241204111437_cleanup_invalid_partner_profiles.rb @@ -0,0 +1,61 @@ +class CleanupInvalidPartnerProfiles < ActiveRecord::Migration[7.1] + def up + # ActiveRecord::Base.logger = Logger.new(STDOUT) + invalid_profiles = Partners::Profile.all.reject(&:valid?) + + return if !invalid_profiles + + invalid_profiles.each do |profile| + # address invalid social media section + + unless (profile.website.present? || + profile.twitter.present? || + profile.facebook.present? || + profile.instagram.present? || + profile.no_social_media_presence || + profile.partner.partials_to_show.exclude?("media_information")) + profile.no_social_media_presence = true + end + + # address no request types set + + unless(profile.enable_quantity_based_requests || profile.enable_individual_requests || profile.enable_child_based_requests) + profile.enable_quantity_based_requests = profile.partner.organization.enable_quantity_based_requests + profile.enable_individual_requests = profile.partner.organization.enable_individual_requests + profile.enable_child_based_requests = profile.partner.organization.enable_child_based_requests + end + + + + # address bad pickup email + + unless profile.valid? + # if profile is not valid at this point, it is a bad pickup email + + pick_up = profile.pick_up_email + pick_up.downcase! + pick_up.strip! + if pick_up == "none" or pick_up == "na" or pick_up == "n/a" or pick_up == "see above" + profile.pick_up_email = "" + else + profile.pick_up_email.sub!("/",",") + profile.pick_up_email.sub!(";",",") + profile.pick_up_email.sub!(" or ", ", ") + profile.pick_up_email.sub!(" and ", ", ") + profile.pick_up_email.sub!(" & ", ", ") + end + + if(!profile.valid?) ## If we can't fix the email, append it to the name so we don't lose the information aspect + profile.pick_up_name += ", email: " + profile.pick_up_email + profile.pick_up_email = "" + end + end + + profile.save! + + end + end + def down + # irreversible + end +end From 37d32a97c2df17e4b68fd47d058321f6ca336dbe Mon Sep 17 00:00:00 2001 From: CL Fisher Date: Thu, 5 Dec 2024 15:49:37 -0500 Subject: [PATCH 2/2] suggested changes --- ...0241204111437_cleanup_invalid_partner_profiles.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/db/migrate/20241204111437_cleanup_invalid_partner_profiles.rb b/db/migrate/20241204111437_cleanup_invalid_partner_profiles.rb index d0f7f3012f..1b21236aeb 100644 --- a/db/migrate/20241204111437_cleanup_invalid_partner_profiles.rb +++ b/db/migrate/20241204111437_cleanup_invalid_partner_profiles.rb @@ -3,7 +3,7 @@ def up # ActiveRecord::Base.logger = Logger.new(STDOUT) invalid_profiles = Partners::Profile.all.reject(&:valid?) - return if !invalid_profiles + return if !invalid_profiles.present? invalid_profiles.each do |profile| # address invalid social media section @@ -38,11 +38,11 @@ def up if pick_up == "none" or pick_up == "na" or pick_up == "n/a" or pick_up == "see above" profile.pick_up_email = "" else - profile.pick_up_email.sub!("/",",") - profile.pick_up_email.sub!(";",",") - profile.pick_up_email.sub!(" or ", ", ") - profile.pick_up_email.sub!(" and ", ", ") - profile.pick_up_email.sub!(" & ", ", ") + profile.pick_up_email.gsub!("/",",") + profile.pick_up_email.gsub!(";",",") + profile.pick_up_email.gsub!(" or ", ", ") + profile.pick_up_email.gsub!(" and ", ", ") + profile.pick_up_email.gsub!(" & ", ", ") end if(!profile.valid?) ## If we can't fix the email, append it to the name so we don't lose the information aspect