mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-30 21:27:17 +00:00
use sql query to update weight calculator prefs
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
class UpdateWeightCalculators < ActiveRecord::Migration
|
||||
def change
|
||||
Spree::Calculator.connection.execute(
|
||||
"UPDATE spree_preferences SET key = replace( key, 'per_kg', 'per_unit') WHERE key like '/calculator/weight/per_kg/%'"
|
||||
)
|
||||
|
||||
Calculator::Weight.all.each { |calculator|
|
||||
calculator.preferred_unit_from_list = 'kg'
|
||||
calculator.preferred_per_unit = calculator.preferred_per_kg
|
||||
calculator.preferences.delete(:preferred_per_kg)
|
||||
Rails.cache.delete(calculator.preference_cache_key("preferred_per_kg"))
|
||||
Rails.cache.delete("/calculator/weight/preferred_per_kg/" + calculator.id)
|
||||
calculator.save
|
||||
}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user