caboose-rets 0.0.29 → 0.0.30

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDY5ZWM1ODFmNGNjOTQ3NGU3MDA1YzU2MDI3ZmJhOTc3MDRiYTRkNA==
4
+ ODgwYjM2ZTA5ZGEwYjM4NDk0ZDg4ODFmMjNkZGMxMjVkYmYwNjkzMA==
5
5
  data.tar.gz: !binary |-
6
- OTAxYzQ3NzlkYThhNzhlNDUwMzM3MTEyYjRhM2FkOTE0NzU2YzQwOQ==
6
+ MDIyMTQ3YzM5MTA1MTkzOGM4ZjMwYWIwZGRhMDhkYWNkYWI3ODJhMg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YzY1ZDI3YzU3NTYyZjRiOTJjY2VkZmYxZGJiYjQwNWQ2MDRhNGFkZjRlOThj
10
- MTNhYzNmMzViZWQ3NGJlMWExOTllZmZkNmYzZTQzZTdiMzUwOTRjNGVmY2Vh
11
- Y2I2NzliYzU1MDgzZTFlNjdlYWU2Y2FjNWUyNTFhYzU0MjMwY2I=
9
+ NmJiYjQyYTQ5MzcwMzAyOTY1ZjIwZGI1NDNjMjhhODY3MzIyMTBhMzkyOTUw
10
+ ZTIwNjk5ZmU5MTM4N2RjY2IxODMyYzQ1NzcwZWNlZTk1ZmI3ZDE4N2JkOGM3
11
+ ODE4YjM2NjE5MjQ4N2Y3MWJlNWFmN2Q2YjdiZWYwMDU5ZmZkOGI=
12
12
  data.tar.gz: !binary |-
13
- M2RjMjQyNjVhYTY4ZTIwZDEyYWFiMmMxMWJmZWNjMzNmODFlMTI2NWY3NWY2
14
- MmUzNTNkYzYxMDZmZThjZWUxNjU4NjIxY2U3MTUxMzhjOTY3M2Y0MDEwZWY0
15
- NmY0YzgyMDIyYTA0MTRkODA5ZTlmNmE2Y2Y1M2QzNTM4YjA2YTc=
13
+ YjAyMmFiNjAyMzEwMTg3NzAzODc0YmVhMDlhZTg4MGQ1NTJiY2Y3ZjMxMGQ2
14
+ Y2FkZTI2OGQ0ZjIxM2Q5YTA3YjllZGRmOWQ4OThjOGQyMTU5NzQxNGYwY2Jk
15
+ OWUzYTUxMDI5MjBjODYzYmNkNWMwYjMzZWM3OWM4ZjY3YmY0Nzc=
@@ -69,5 +69,56 @@ class CabooseRets::Media < ActiveRecord::Base
69
69
 
70
70
  return true
71
71
  end
72
+
73
+ def self.reorder(media_ids, bucket_name)
74
+
75
+ s3 = AWS::S3.new
76
+ b = s3.buckets[bucket_name]
77
+
78
+ # Rename the s3 assets to temp names
79
+ media_ids.each do |id|
80
+ m = CabooseRets::Media.find(id)
81
+ (m.image.styles.keys+[:original]).each { |style| b.objects[m.image.path(style)].rename_to "#{m.image.path(style)}.temp" } if m.media_type == 'Photo'
82
+ b.objects[m.file.path].rename_to "#{m.file.path}.temp" if m.media_type == 'File'
83
+ end
84
+
85
+ # Rename the assets to their new names
86
+ i = 1
87
+ j = 1
88
+ media_ids.each do |id|
89
+ m = CabooseRets::Media.find(id)
90
+ if m.media_type == 'Photo'
91
+ orig_name = "#{m.image.path}.temp"
92
+ m.media_order = i
93
+ (m.image.styles.keys+[:original]).each { |style| b.objects[orig_name.gsub("original", style.to_s)].rename_to m.image.path(style) }
94
+ m.save
95
+ i = i + 1
96
+ elsif m.media_type == 'File'
97
+ b.objects["#{m.file.path}.temp"].rename_to m.file.path
98
+ m.media_order = j
99
+ m.save
100
+ j = j + 1
101
+ end
102
+ end
103
+
104
+ return true
105
+ end
106
+
107
+ def self.rename_media
108
+ s3 = AWS::S3.new
109
+ b = s3.buckets["advantagerealtygroup"]
110
+
111
+ CabooseRets::Media.where(:media_type => 'Photo').reorder("mls_acct, media_order").all.each do |m|
112
+ puts "Renaming #{m.mls_acct}_#{m.id}..."
113
+ if m.image_file_name && m.image
114
+ ext = File.extname(m.image_file_name)
115
+ (m.image.styles.keys+[:original]).each do |style|
116
+ b.objects[m.image.path(style)].copy_to "rets/media_new/#{m.id}_#{style}.#{ext}"
117
+ end
118
+ end
119
+ end
120
+
121
+ return true
122
+ end
72
123
 
73
124
  end
@@ -1,3 +1,3 @@
1
1
  module CabooseRets
2
- VERSION = '0.0.29'
2
+ VERSION = '0.0.30'
3
3
  end
@@ -2,6 +2,11 @@ require "caboose_rets/version"
2
2
 
3
3
  namespace :caboose_rets do
4
4
 
5
+ desc "Initializes the database for a caboose installation"
6
+ task :rename_media => :environment do
7
+ CabooseRets::Media.rename_media
8
+ end
9
+
5
10
  desc "Initializes the database for a caboose installation"
6
11
  task :db => :environment do
7
12
  CabooseRets::Schema.create_schema
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caboose-rets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.29
4
+ version: 0.0.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Barry