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:
commit
988af5ae37
1 changed files with 10 additions and 5 deletions
|
@ -5,12 +5,17 @@ namespace :'2018_03_06_clean_html_textareas' do
|
|||
include ActionView::Helpers::TextHelper
|
||||
include HtmlToStringHelper
|
||||
|
||||
types_de_champ = TypeDeChamp.joins(:champ)
|
||||
.where(type_champ: "textarea")
|
||||
.where("champs.value LIKE '%<%'")
|
||||
champs = Champ.joins(:type_de_champ)
|
||||
.where(types_de_champ: { type_champ: "textarea" })
|
||||
.where("value LIKE '%<%'")
|
||||
|
||||
types_de_champ.find_each do |tdc|
|
||||
tdc.champ.each { |c| c.update_column(:value, html_to_string(c.value)) }
|
||||
total = champs.count
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue