OSDN Git Service

Merge branch 'v05' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v05
[pettanr/pettanr.git] / app / models / provider_status.rb
index 3902804..ae0cc11 100644 (file)
@@ -1,12 +1,16 @@
 class ProviderStatus < ActiveRecord::Base
   has_one :provider
   
-#  validates :token
+  validates :token, :format => {:with => /^[a-zA-Z0-9]+$/, :allow_blank => true}
   validates :receive_hour1, :numericality => {:allow_blank => true}
   validates :receive_hour2, :numericality => {:allow_blank => true}
 #  validates :received_at
 #  validates :stopped_at
   
+  before_save do |r|
+    r.token = r.token.gsub(/\s/, '') if r.token
+  end
+  
   def supply_default
   end
   
@@ -109,4 +113,17 @@ class ProviderStatus < ActiveRecord::Base
     self.save
   end
   
+  def self.import pid, exports
+    res = {}
+    ProviderStatus.transaction do
+      res[:licenses] = ProviderLicense.import @provider_status.provider.id, exports['licenses']
+      raise ActiveRecord::Rollback if res[:licenses].any?
+      res[:artists] = ProviderArtist.import @provider_status.provider.id, exports['artists']
+      raise ActiveRecord::Rollback if res[:artists].any?
+      res[:original_pictures] = ProviderOriginalPicture.import @provider_status.provider.id, exports['original_pictures']
+      raise ActiveRecord::Rollback if res[:original_pictures].any?
+    end
+    res
+  end
+  
 end