OSDN Git Service

merge v04
[pettanr/pettanr.git] / app / models / original_picture.rb
index 96740f9..19c993d 100644 (file)
@@ -1,6 +1,5 @@
 class OriginalPicture < ActiveRecord::Base
   belongs_to :artist
-  belongs_to :license
   has_one :resource_picture
   
   validates :ext, :presence => true, :length => {:maximum => 4}, :inclusion => {:in => ['png', 'jpeg', 'gif']}\r
@@ -8,12 +7,10 @@ class OriginalPicture < ActiveRecord::Base
   validates :height, :presence => true, :numericality => true, :natural_number => true
   validates :filesize, :presence => true, :numericality => {:greater_than => 0, :less_than_or_equal_to => 2000000}, :natural_number => true
   validates :artist_id, :presence => true, :numericality => true, :existence => true
-  validates :license_id, :presence => true, :numericality => true, :existence => true
   
   before_destroy :destroy_with_file
   
   def supply_default art
-    self.license_id = art.default_license_id if self.license_id.blank?
   end
   
   def self.default_page_size
@@ -46,11 +43,11 @@ class OriginalPicture < ActiveRecord::Base
   end
   
   def self.list_opt
-    {:include => [:license, :resource_picture]}
+    {:include => {:resource_picture => {}}}
   end
   
   def self.list_json_opt
-    {:include => [:license, :resource_picture]}
+    {:include => {:resource_picture => {}}}
   end
   
   def self.show cid, artist, opt = {}
@@ -66,13 +63,13 @@ class OriginalPicture < ActiveRecord::Base
   end
   
   def self.show_include_opt opt = {}
-    res = [:license, :resource_picture]
-    res.push(opt[:include]) if opt[:include]
+    res = {:resource_picture => {}}
+    res.merge!(opt[:include]) if opt[:include]
     res
   end
   
   def self.show_json_include_opt
-    {:include => [:license, :resource_picture]}
+    {:include => {:resource_picture => {}}}
   end
   
   def destroy_with_file
@@ -106,24 +103,16 @@ class OriginalPicture < ActiveRecord::Base
     mgk
   end
   
-  def store(picture_data, art, lid = nil)
+  def store(picture_data, art)
     mgk = data_to_mgk picture_data
     return false unless mgk
     res = false
     self.attributes = {:ext => mgk.format.downcase, :width => mgk.columns, :height => mgk.rows, 
-      :filesize => mgk.filesize, :artist_id => art.id, 
-      :license_id => lid.blank? ? art.default_license_id : lid.to_i
+      :filesize => mgk.filesize, :artist_id => art.id
     }
     OriginalPicture.transaction do
       if res = self.save
         if res = PictureIO.original_picture_io.put(picture_data, self.filename)
-          rp = ResourcePicture.update_picture(self)
-          unless rp.store(mgk)
-            res = false
-            PictureIO.original_picture_io.delete(self.filename)
-            self.errors.add :base, 'resource picture copying error'
-            raise ActiveRecord::Rollback
-          end
           res = true
         else
           self.errors.add :base, 'original picture io does not work'