class TrustyCms::TaskSupport

def config_import(path = "#{Rails.root}/config/trusty_config.yml", clear = nil)

def config_import(path = "#{Rails.root}/config/trusty_config.yml", clear = nil)
  establish_connection
  if File.exist?(path)
    begin
      TrustyCms::Config.transaction do
        TrustyCms::Config.delete_all if clear
        configs = YAML.load(YAML.load_file(path))
        configs.each do |key, value|
          c = TrustyCms::Config.find_or_initialize_by_key(key)
          c.value = value
          c.save
        end
      end
      puts "TrustyCms::Config updated from #{path}"
    rescue ActiveRecord::RecordInvalid => e
      puts "IMPORT FAILED and rolled back. #{e}"
    end
  else
    puts "No file exists at #{path}"
  end
end