Class: GalleriesTasks

Inherits:
Object
  • Object
show all
Defined in:
lib/galleries_tasks.rb

Class Method Summary collapse

Class Method Details

.clean_name_seoObject



7
8
9
10
11
12
# File 'lib/galleries_tasks.rb', line 7

def self.clean_name_seo
  galleries = Gallery.find :all
  galleries.each do |g|
    Util.clean_name_seo g
  end
end

.to_mongoidObject



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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/galleries_tasks.rb', line 14

def self.to_mongoid
  logfile = 'log/galleries_tasks.log'
  
  File.open(logfile, 'a') do|f|
    
    f.puts DateTime.new
    
    user = User.where( :email => '[email protected]' ).first
  
    # take all photos
    old_photos = SqlPhoto.find :all,
      :conditions => { :is_trash => 0 }
    f.puts "old photos: #{old_photos.count}"
  
    old_photos.each do |old_photo|
      if 0 == Photo.where( :old_id => old_photo.id ).length
        # create new photo
        new_photo = Photo.new
        begin
          new_photo.photo = open(old_photo.photo.url(:original))
        rescue; end
        new_photo.user = user
    
        # gallery?
        unless old_photo.gallery_id.blank?
      
          old_gallery = SqlGallery.find old_photo.gallery_id
          new_gallery = Gallery.where( :galleryname => old_gallery.name_seo ).first
          if new_gallery.blank?
            # create new gallery
            new_gallery = Gallery.new
            new_gallery.name = old_gallery.name
            new_gallery.galleryname = old_gallery.name_seo
            new_gallery.descr = old_gallery.descr
            new_gallery.x = old_gallery.x
            new_gallery.y = old_gallery.y
            new_gallery.created_at = old_gallery.created_at
            new_gallery.updated_at = old_gallery.updated_at
            new_gallery.is_public = old_gallery.is_public
            new_gallery.is_feature = old_gallery.is_feature
            begin
              new_gallery.city = City.where( :cityname => old_gallery.city.name_seo ).first
            rescue; end
            new_gallery.user = user
            new_gallery.save
          
          end
        end
    
        new_photo.gallery = new_gallery
        new_photo.old_id = old_photo.id
        new_photo.created_at = old_photo.created_at
        new_photo.updated_at = old_photo.updated_at
        unless old_photo.city.blank?
          new_photo.city = City.where( :cityname => old_photo.city.name_seo ).first
        end
        new_photo.descr = "#{old_photo.name} -- "
        new_photo.descr = "#{new_photo.descr}#{old_photo.descr}"
        new_photo.is_public = old_photo.is_public
        f.puts "saving new #{new_photo.old_id}..."
        f.puts new_photo.save
        
        old_photo.is_trash = 1
        old_photo.save
    
      else
        f.puts "not updating existing photo #{old_photo.id}"
        old_photo.is_trash = 1
        old_photo.save
        
      end
    end
  end
end