public
Description: Tog Platform Picture Management Component
Homepage: http://www.toghq.com
Clone URL: git://github.com/tog/tog_picto.git
aitor (author)
Wed Jul 01 13:25:27 -0700 2009
commit  8676f9b746ca24f6a2dce68fc8609e1d14076021
tree    19bfda57adcd0c5fb04368144df679a7f2d9a05a
parent  701e22d24817a114bad2e093d536b260a02e0ecc
tog_picto / db / migrate / 007_add_attachments_image_to_photo.rb
100644 51 lines (40 sloc) 1.622 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class AddAttachmentsImageToPhoto < ActiveRecord::Migration
  def self.up
    add_column :photos, :image_file_name, :string
    add_column :photos, :image_content_type, :string
    add_column :photos, :image_file_size, :integer
    add_column :photos, :image_updated_at, :datetime
 
    rename_column :photos, :image, :old_file_name
 
    add_crop("plugins.tog_picto.photo.versions.tiny")
 
    Picto::Photo.all.each do |p|
      unless p.old_file_name.blank?
        p.image = File.new("public/system/photos/picto/photo/image/#{p.id}/#{p.old_file_name}") if File.exists?("public/system/photos/picto/photo/image/#{p.id}/#{p.old_file_name}")
        p.save!
      end
    end
    FileUtils.rm_rf "public/system/photos/picto/"
 
    remove_column :photos, :old_file_name
  end
 
  def self.down
    add_column :photos, :image, :string
 
    remove_crop("plugins.tog_picto.photo.versions.tiny")
 
    Picto::Photo.all.each do |p|
      unless p.image_file_name.blank?
        p.image = File.new("public/system/picto/photos/images/#{p.id}/#{p.image_file_name}") if File.exists?("public/system/picto/photos/images/#{p.id}/#{p.image_file_name}")
        p.save!
      end
    end
    FileUtils.rm_rf "public/system/picto/photos"
 
    remove_column :photos, :image_file_name
    remove_column :photos, :image_content_type
    remove_column :photos, :image_file_size
    remove_column :photos, :image_updated_at
  end
 
  private
  def self.add_crop(key)
    Tog::Config[key]="#{Tog::Config[key]}#" unless Tog::Config[key] =~ /#|%|@|!|<|>|\^/
  end
 
  def self.remove_crop(key)
    Tog::Config[key]=Tog::Config[key].gsub("#",'')
  end
end