Class: SystemSetting

Inherits:
ActiveRecord::Base show all
Defined in:
lib/six-updater-web/app/models/system_setting.rb

Constant Summary collapse

TIMEOUT =
20

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ActiveRecord::Base

#associated_valid?, #no_errors_in_associated?, #save_associated, #save_associated!, #save_with_unsaved_flag, #to_label, #unsaved=, #unsaved?

Class Method Details

.singletonObject



4
5
6
7
8
9
10
11
# File 'lib/six-updater-web/app/models/system_setting.rb', line 4

def self.singleton
  system_setting = self.find(:first)
  if system_setting
    system_setting
  else
    self.new
  end
end

Instance Method Details

#execObject



13
14
15
# File 'lib/six-updater-web/app/models/system_setting.rb', line 13

def exec
  "rake" # .bat on Windows
end

#speedtestObject



17
18
19
20
21
# File 'lib/six-updater-web/app/models/system_setting.rb', line 17

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

#syncObject



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/six-updater-web/app/models/system_setting.rb', line 97

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

#synchronizeObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/six-updater-web/app/models/system_setting.rb', line 49

def synchronize
  l = []
  begin
    Six::Network::Panel.setlogger(logger)
    status = Timeout::timeout(TIMEOUT) do
      Six::Network::Panel.(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

#update_gamespy(setting = Appsetting.new, internal = false) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/six-updater-web/app/models/system_setting.rb', line 23

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

#update_gamespy_nogeo(setting = Appsetting.new, internal = false) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/six-updater-web/app/models/system_setting.rb', line 36

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

#update_sitecontrollersObject



86
87
88
89
90
91
92
93
94
95
# File 'lib/six-updater-web/app/models/system_setting.rb', line 86

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