Merge pull request #1588 from betagouv/frederic/1543-strip_html_textarea_improve_for_production

[Fix #1543] simplify request and provide progress feedback
This commit is contained in:
Frederic Merizen 2018-03-09 15:52:53 +01:00 committed by GitHub
commit 988af5ae37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,12 +5,17 @@ namespace :'2018_03_06_clean_html_textareas' do
include ActionView::Helpers::TextHelper include ActionView::Helpers::TextHelper
include HtmlToStringHelper include HtmlToStringHelper
types_de_champ = TypeDeChamp.joins(:champ) champs = Champ.joins(:type_de_champ)
.where(type_champ: "textarea") .where(types_de_champ: { type_champ: "textarea" })
.where("champs.value LIKE '%<%'") .where("value LIKE '%<%'")
types_de_champ.find_each do |tdc| total = champs.count
tdc.champ.each { |c| c.update_column(:value, html_to_string(c.value)) }
champs.find_each(batch_size: 100).with_index do |c, i|
if (i % 100) == 0
print "Champ #{i}/#{total}\n"
end
c.update_column(:value, html_to_string(c.value))
end end
end end
end end