Sha256: ecfae772de3807bc0aeaa67166935c4d3e9c3b38c2161e3d35dafce81794c93c

Contents?: true

Size: 1.65 KB

Versions: 12

Compression:

Stored size: 1.65 KB

Contents

class UpgradePaperclipPaths < ActiveRecord::Migration
  include 
  def self.up
    sites = Site.all
      sites.each do |site|
        # Old paperclip directories
        old_assets_dir = "#{Rails.root}/public/assets"
        old_photos_dir = "#{Rails.root}/public/photos"
        old_themes_dir = "#{Rails.root}/public/themes"
        old_photos_dir_multisite = "#{Rails.root}/public/sites/site-#{site.perma_host}/photos"
        old_themes_dir_multisite = "#{Rails.root}/public/themes/site-#{site.id}"
        
        # New paperclip directory
        site_upload_dir = "#{Rails.root}/public/sites/site-#{site.id}"
        FileUtils.mkdir_p(site_upload_dir) unless File.exists?(site_upload_dir)
        
        # Copy old files to new location
        p "Starting file copy ..."
        FileUtils.cp_r("#{old_assets_dir}/.", site_upload_dir + '/assets', :verbose => true) if File.exists?(old_assets_dir)
        FileUtils.cp_r("#{old_photos_dir}/.", site_upload_dir + '/photos', :verbose => true) if File.exists?(old_photos_dir)
        FileUtils.cp_r("#{old_themes_dir}/.", site_upload_dir + '/themes', :verbose => true) if File.exists?(old_themes_dir)
        FileUtils.cp_r("#{old_photos_dir_multisite}/.", site_upload_dir + '/photos', :verbose => true) if File.exists?(old_photos_dir_multisite)
        FileUtils.cp_r("#{old_themes_dir_multisite}/.", site_upload_dir + '/themes', :verbose => true) if File.exists?(old_themes_dir_multisite)
        p "Cleanup the new themes directory..."
        FileUtils.rm_rf(site_upload_dir + "/themes/site-#{site.id}", :verbose => true) if File.exists?(site_upload_dir + "/themes/site-#{site.id}")
    end
  end
  
  def self.down
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
adva-0.2.4 db/migrate/20090707171100_upgrade_paperclip_paths.rb
adva-0.2.3 db/migrate/20090707171100_upgrade_paperclip_paths.rb
adva-0.2.2 db/migrate/20090707171100_upgrade_paperclip_paths.rb
adva-0.2.1 db/migrate/20090707171100_upgrade_paperclip_paths.rb
adva-0.2.0 db/migrate/20090707171100_upgrade_paperclip_paths.rb
adva-0.1.4 db/migrate/20090707171100_upgrade_paperclip_paths.rb
adva-0.1.3 db/migrate/20090707171100_upgrade_paperclip_paths.rb
adva-0.1.2 db/migrate/20090707171100_upgrade_paperclip_paths.rb
adva-0.1.1 db/migrate/20090707171100_upgrade_paperclip_paths.rb
adva-0.1.0 db/migrate/20090707171100_upgrade_paperclip_paths.rb
adva_cms-0.0.1 db/migrate/20090707171100_upgrade_paperclip_paths.rb
adva-0.0.1 adva_cms/db/migrate/20090707171100_upgrade_paperclip_paths.rb