2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-04-11 09:35:08 +01:00
|
|
|
class Product < ActiveRecord::Base
|
2012-12-07 11:11:12 +00:00
|
|
|
include Modules::Models::TimeLiving
|
|
|
|
|
2011-04-11 09:35:08 +01:00
|
|
|
belongs_to :platform
|
2012-11-06 14:13:16 +00:00
|
|
|
belongs_to :project
|
2011-11-11 17:13:09 +00:00
|
|
|
has_many :product_build_lists, :dependent => :destroy
|
2011-04-11 09:35:08 +01:00
|
|
|
|
2013-03-22 14:06:13 +00:00
|
|
|
ONCE_A_12_HOURS = 0
|
|
|
|
ONCE_A_DAY = 1
|
|
|
|
ONCE_A_WEEK = 2
|
|
|
|
|
|
|
|
AUTOSTART_STATUSES = [ONCE_A_12_HOURS, ONCE_A_DAY, ONCE_A_WEEK]
|
|
|
|
HUMAN_AUTOSTART_STATUSES = {
|
|
|
|
ONCE_A_12_HOURS => :once_a_12_hours,
|
|
|
|
ONCE_A_DAY => :once_a_day,
|
|
|
|
ONCE_A_WEEK => :once_a_week
|
|
|
|
}
|
|
|
|
|
2011-11-24 21:46:19 +00:00
|
|
|
validates :name, :presence => true, :uniqueness => {:scope => :platform_id}
|
2012-11-13 10:31:45 +00:00
|
|
|
validates :project_id, :presence => true
|
2013-02-15 16:20:06 +00:00
|
|
|
validates :main_script, :params, :length => { :maximum => 255 }
|
2013-03-22 16:15:37 +00:00
|
|
|
validates :autostart_status, :numericality => true,
|
|
|
|
:inclusion => {:in => AUTOSTART_STATUSES}, :allow_blank => true
|
2011-04-14 08:23:08 +01:00
|
|
|
|
2013-02-28 15:27:50 +00:00
|
|
|
scope :recent, order("#{table_name}.name ASC")
|
2011-04-14 08:23:08 +01:00
|
|
|
|
2012-11-13 10:31:45 +00:00
|
|
|
attr_accessible :name,
|
|
|
|
:description,
|
|
|
|
:project_id,
|
|
|
|
:main_script,
|
2013-02-01 19:24:56 +00:00
|
|
|
:params,
|
2013-03-22 14:06:13 +00:00
|
|
|
:platform_id,
|
2013-03-27 12:18:24 +00:00
|
|
|
:autostart_status,
|
|
|
|
:project_version
|
2012-04-03 13:21:39 +01:00
|
|
|
attr_readonly :platform_id
|
|
|
|
|
2012-02-21 21:27:11 +00:00
|
|
|
def full_clone(attrs = {})
|
2012-06-08 18:37:16 +01:00
|
|
|
dup.tap do |c|
|
2012-02-22 20:24:29 +00:00
|
|
|
attrs.each {|k,v| c.send("#{k}=", v)}
|
2013-02-27 21:55:30 +00:00
|
|
|
c.time_living = c.time_living.to_i / 60 # see: Modules::Models::TimeLiving#convert_time_living
|
|
|
|
c.platform_id = nil
|
|
|
|
c.product_build_lists = []
|
2012-06-08 18:37:16 +01:00
|
|
|
c.updated_at = nil; c.created_at = nil
|
2011-11-03 00:32:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-22 16:15:37 +00:00
|
|
|
def human_autostart_status
|
|
|
|
self.class.human_autostart_status(autostart_status)
|
2013-03-22 14:06:13 +00:00
|
|
|
end
|
|
|
|
|
2013-03-22 16:15:37 +00:00
|
|
|
def self.human_autostart_status(autostart_status)
|
|
|
|
I18n.t("layout.products.autostart_statuses.#{HUMAN_AUTOSTART_STATUSES[autostart_status]}")
|
2013-03-22 14:06:13 +00:00
|
|
|
end
|
|
|
|
|
2013-03-22 17:17:40 +00:00
|
|
|
class << self
|
|
|
|
HUMAN_AUTOSTART_STATUSES.each do |autostart_status, human_autostart_status|
|
|
|
|
define_method "autostart_iso_builds_#{human_autostart_status}" do
|
|
|
|
autostart_iso_builds autostart_status
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-22 16:58:53 +00:00
|
|
|
def self.autostart_iso_builds(autostart_status)
|
|
|
|
Product.where(:autostart_status => autostart_status).each do |product|
|
2013-03-22 19:14:06 +00:00
|
|
|
pbl = product.product_build_lists.new
|
2013-03-27 12:18:24 +00:00
|
|
|
[:params, :main_script, :project, :project_version].each do |k|
|
2013-03-22 16:58:53 +00:00
|
|
|
pbl.send "#{k}=", product.send(k)
|
|
|
|
end
|
|
|
|
owner = product.platform.owner
|
2013-03-22 19:11:47 +00:00
|
|
|
pbl.user = owner.is_a?(User) ? owner : owner.owner
|
|
|
|
pbl.autostarted = true
|
2013-03-22 19:14:06 +00:00
|
|
|
pbl.base_url = "http://#{product.platform.default_host}"
|
2013-03-22 19:11:47 +00:00
|
|
|
pbl.time_living = product.time_living / 60
|
2013-03-22 16:58:53 +00:00
|
|
|
pbl.save
|
|
|
|
end
|
|
|
|
end
|
2013-03-22 16:15:37 +00:00
|
|
|
|
2011-04-11 09:35:08 +01:00
|
|
|
end
|