2018-03-06 14:37:20 +01:00
|
|
|
require Rails.root.join("app", "helpers", "html_to_string_helper")
|
|
|
|
|
|
|
|
namespace :'2018_03_06_clean_html_textareas' do
|
|
|
|
task clean: :environment do
|
|
|
|
include ActionView::Helpers::TextHelper
|
|
|
|
include HtmlToStringHelper
|
|
|
|
|
2018-03-09 15:46:02 +01:00
|
|
|
champs = Champ.joins(:type_de_champ)
|
|
|
|
.where(types_de_champ: { type_champ: "textarea" })
|
|
|
|
.where("value LIKE '%<%'")
|
2018-03-06 14:37:20 +01:00
|
|
|
|
2018-03-09 15:46:02 +01:00
|
|
|
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))
|
2018-03-06 14:37:20 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|