diff --git a/app/models/locale.rb b/app/models/locale.rb index 6e88d549d..802700505 100644 --- a/app/models/locale.rb +++ b/app/models/locale.rb @@ -15,14 +15,16 @@ class Locale < ApplicationModel raise "Can't load locales from #{url}: #{result.error}" if !result.success? - result.data.each {|locale| - exists = Locale.where(locale: locale['locale']).first - if exists - exists.update(locale.symbolize_keys!) - else - Locale.create(locale.symbolize_keys!) - end - } + ActiveRecord::Base.transaction do + result.data.each {|locale| + exists = Locale.where(locale: locale['locale']).first + if exists + exists.update(locale.symbolize_keys!) + else + Locale.create(locale.symbolize_keys!) + end + } + end true end diff --git a/app/models/translation.rb b/app/models/translation.rb index eab31a644..0949a0e93 100644 --- a/app/models/translation.rb +++ b/app/models/translation.rb @@ -27,26 +27,29 @@ load translations from online } ) raise "Can't load translations from #{url}: #{result.error}" if !result.success? - result.data.each {|translation| - #puts translation.inspect - # handle case insensitive sql - exists = Translation.where(locale: translation['locale'], format: translation['format'], source: translation['source']) - translaten = nil - exists.each {|item| - if item.source == translation['source'] - translaten = item + ActiveRecord::Base.transaction do + result.data.each {|translation| + #puts translation.inspect + + # handle case insensitive sql + exists = Translation.where(locale: translation['locale'], format: translation['format'], source: translation['source']) + translaten = nil + exists.each {|item| + if item.source == translation['source'] + translaten = item + end + } + if translaten + + # verify if update is needed + translaten.update_attributes(translation.symbolize_keys!) + translaten.save + else + Translation.create(translation.symbolize_keys!) end } - if translaten - - # verify if update is needed - translaten.update_attributes(translation.symbolize_keys!) - translaten.save - else - Translation.create(translation.symbolize_keys!) - end - } + end true end