class SystemSetting < ActiveRecord::Base TIMEOUT = 20 def self.singleton system_setting = self.find(:first) if system_setting system_setting else self.new end end def exec "rake" # .bat on Windows end def speedtest cl = "sync:priority RAILS_ENV=#{ENV['RAILS_ENV']}" # + cl cl += " BASE_PATH=\'#{SixUpdaterWeb::BASE_PATH}\'" if defined?(SixUpdaterWeb::OLDLOCATION) SixUpdaterWeb.run_program(exec, RAILS_ROOT, cl) end def update_gamespy(setting = Appsetting.new, internal = false) self.gamespied_at = Time.now self.save ENV['NOGEO'] = nil if internal SixUpdaterWeb.update_gamespy else cl = "sync:gamespy RAILS_ENV=#{ENV['RAILS_ENV']} GAMESPY_TYPES=#{setting.edition::GAMESPY_TYPES.join(",")}" # + cl cl += " BASE_PATH=\'#{SixUpdaterWeb::BASE_PATH}\'" if defined?(SixUpdaterWeb::OLDLOCATION) SixUpdaterWeb.run_program(exec, RAILS_ROOT, cl) end end def update_gamespy_nogeo(setting = Appsetting.new, internal = false) self.gamespied_at = Time.now self.save ENV['NOGEO'] = "1" if internal SixUpdaterWeb.update_gamespy else cl = "sync:gamespy RAILS_ENV=#{ENV['RAILS_ENV']} NOGEO=1 GAMESPY_TYPES=#{setting.edition::GAMESPY_TYPES.join(",")}" # + cl cl += " BASE_PATH=\'#{SixUpdaterWeb::BASE_PATH}\'" if defined?(SixUpdaterWeb::OLDLOCATION) SixUpdaterWeb.run_program(exec, RAILS_ROOT, cl) end end def synchronize l = [] begin Six::Network::Panel.setlogger(logger) status = Timeout::timeout(TIMEOUT) do Six::Network::Panel.login(self.server_username, self.server_password, true) end # Temporary until migration done begin l += Category.imp rescue => e logger.error "ERROR: #{e.class} #{e.message} #{e.backtrace.join("\n")}" end [Mod, Network, Server, Repository, Action, Appsetting, Sixconfig].each do |t| r = t.imp # Mod dependencies workaround begin r.each do |mod| if mod.dependencies && !mod.dependencies.empty? mod.mods = mod.dependencies.map{|m| Mod.find(:first, :conditions => ["name LIKE ?", m]) }.reject{|m| m.nil?} mod.save end end rescue => e logger.error "ERROR: #{e.class} #{e.message} #{e.backtrace.join("\n")}" end if t == Mod l += r end rescue Timeout::Error logger.info "TIMEOUT while trying to synchronize!" rescue => e logger.info "ERROR: #{e.class} #{e.message} #{e.backtrace.join("\n")}" end l end def update_sitecontrollers if ENV["RAILS_ENV"] == "production" && (RUBY_VERSION > "1.9.1" || RUBY_VERSION < "1.9.1") begin # TODO: This should be in after_initialize yet there it fails.. SixUpdaterWeb.update_site_controllers # Update the list of controllers - give default adminstrator permission to rescue => e logger.debug "ERROR: #{e.class} #{e.message} #{e.backtrace.join("\n")}" end end end def sync self.synchronized_at = Time.now self.save #Mod.delete_all("type IS NULL or name IS NULL") #Appsetting.delete_all("type IS NULL or name IS NULL") l = self.synchronize self.update_sitecontrollers content = l.size > 0 ? "Synchronized #{l.size} records with server-site!" : "WARNING: No objects received, possibly issue with connection (timeout?), or server site" #Mod.delete_all("type IS NULL or name IS NULL") #Appsetting.delete_all("type IS NULL or name IS NULL") content end end