caboose-rets 0.1.36 → 0.1.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,15 +23,17 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
23
23
  end
24
24
 
25
25
  def self.get_config
26
- rets_config = CabooseRets::RetsConfig.where("rets_url ILIKE ?","%mlsmatrix%").order('RANDOM()').first
27
26
  @@config = {
28
- 'url' => rets_config.rets_url,
29
- 'username' => rets_config.rets_username,
30
- 'password' => rets_config.rets_password
27
+ 'url' => nil, # URL to the RETS login
28
+ 'username' => nil,
29
+ 'password' => nil,
30
+ 'temp_path' => nil,
31
+ 'log_file' => nil,
32
+ 'media_base_url' => nil
31
33
  }
32
- # config = YAML::load(File.open("#{Rails.root}/config/rets_importer.yml"))
33
- # config = config[Rails.env]
34
- # config.each { |key,val| @@config[key] = val }
34
+ config = YAML::load(File.open("#{Rails.root}/config/rets_importer.yml"))
35
+ config = config[Rails.env]
36
+ config.each { |key,val| @@config[key] = val }
35
37
  end
36
38
 
37
39
  def self.client
@@ -48,11 +50,11 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
48
50
 
49
51
  def self.meta(class_type)
50
52
  case class_type
51
- when 'Office' then Caboose::StdClass.new({ :search_type => 'Office' , :remote_key_field => 'Matrix_Unique_ID' , :local_key_field => 'matrix_unique_id' , :local_table => 'rets_offices' , :date_modified_field => 'MatrixModifiedDT'})
52
- when 'Agent' then Caboose::StdClass.new({ :search_type => 'Agent' , :remote_key_field => 'Matrix_Unique_ID' , :local_key_field => 'matrix_unique_id' , :local_table => 'rets_agents' , :date_modified_field => 'MatrixModifiedDT'})
53
- when 'OpenHouse' then Caboose::StdClass.new({ :search_type => 'OpenHouse' , :remote_key_field => 'matrix_unique_id' , :local_key_field => 'matrix_unique_id' , :local_table => 'rets_open_houses' , :date_modified_field => 'MatrixModifiedDT'})
54
- when 'Listing' then Caboose::StdClass.new({ :search_type => 'Property' , :remote_key_field => 'Matrix_Unique_ID' , :local_key_field => 'matrix_unique_id' , :local_table => 'rets_properties' , :date_modified_field => 'MatrixModifiedDT'})
55
- when 'GFX' then Caboose::StdClass.new({ :search_type => 'Media' , :remote_key_field => 'MEDIA_ID' , :local_key_field => 'media_id' , :local_table => 'rets_media' , :date_modified_field => 'DATE_MODIFIED' })
53
+ when 'Office' then Caboose::StdClass.new({ :search_type => 'Office' , :remote_key_field => 'OfficeMlsId' , :local_key_field => 'lo_mls_id' , :local_table => 'rets_offices' , :date_modified_field => 'ModificationTimestamp'})
54
+ when 'Member' then Caboose::StdClass.new({ :search_type => 'Member' , :remote_key_field => 'MemberMlsId' , :local_key_field => 'mls_id' , :local_table => 'rets_agents' , :date_modified_field => 'ModificationTimestamp'})
55
+ when 'OpenHouse' then Caboose::StdClass.new({ :search_type => 'OpenHouse' , :remote_key_field => 'OpenHouseKey' , :local_key_field => 'matrix_unique_id' , :local_table => 'rets_open_houses' , :date_modified_field => 'ModificationTimestamp'})
56
+ when 'Property' then Caboose::StdClass.new({ :search_type => 'Property' , :remote_key_field => 'ListingId' , :local_key_field => 'mls_number' , :local_table => 'rets_properties' , :date_modified_field => 'ModificationTimestamp'})
57
+ when 'Media' then Caboose::StdClass.new({ :search_type => 'Media' , :remote_key_field => 'MediaObjectID' , :local_key_field => 'media_id' , :local_table => 'rets_media' , :date_modified_field => 'ModificationTimestamp' })
56
58
  end
57
59
  end
58
60
 
@@ -68,6 +70,7 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
68
70
  :search_type => m.search_type,
69
71
  :class => class_type,
70
72
  :query => query,
73
+ # :limit => 3,
71
74
  :timeout => -1
72
75
  }
73
76
  obj = nil
@@ -91,20 +94,22 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
91
94
 
92
95
  def self.get_instance_with_id(class_type, data)
93
96
  obj = nil
97
+ self.log "Getting instance of #{class_type}..."
94
98
  m = case class_type
95
- when 'Listing' then CabooseRets::Property
99
+ when 'Property' then CabooseRets::Property
96
100
  when 'OpenHouse' then CabooseRets::OpenHouse
97
- when 'Agent' then CabooseRets::Agent
101
+ when 'Member' then CabooseRets::Agent
98
102
  when 'Office' then CabooseRets::Office
99
- when 'GFX' then CabooseRets::Media
103
+ when 'Media' then CabooseRets::Media
100
104
  end
101
105
  obj = case class_type
102
- when 'Listing' then m.where(:matrix_unique_id => data['Matrix_Unique_ID']).exists? ? m.where(:matrix_unique_id => data['Matrix_Unique_ID']).first : m.new(:matrix_unique_id => data['Matrix_Unique_ID'])
103
- when 'OpenHouse' then m.where(:matrix_unique_id => data['matrix_unique_id']).exists? ? m.where(:matrix_unique_id => data['matrix_unique_id']).first : m.new(:matrix_unique_id => data['matrix_unique_id'])
104
- when 'Agent' then m.where(:matrix_unique_id => data['Matrix_Unique_ID']).exists? ? m.where(:matrix_unique_id => data['Matrix_Unique_ID']).first : m.new(:matrix_unique_id => data['Matrix_Unique_ID'])
105
- when 'Office' then m.where(:matrix_unique_id => data['Matrix_Unique_ID']).exists? ? m.where(:matrix_unique_id => data['Matrix_Unique_ID']).first : m.new(:matrix_unique_id => data['Matrix_Unique_ID'])
106
- when 'GFX' then m.where(:media_id => data['MEDIA_ID'] ).exists? ? m.where(:media_id => data['MEDIA_ID'] ).first : m.new(:media_id => data['MEDIA_ID'] )
106
+ when 'Property' then m.where(:mls_number => data['ListingId']).exists? ? m.where(:mls_number => data['ListingId']).first : m.create(:mls_number => data['ListingId'])
107
+ when 'OpenHouse' then m.where(:matrix_unique_id => data['OpenHouseKey']).exists? ? m.where(:matrix_unique_id => data['OpenHouseKey']).first : m.create(:matrix_unique_id => data['OpenHouseKey'])
108
+ when 'Member' then m.where(:mls_id => data['MemberMlsId']).exists? ? m.where(:mls_id => data['MemberMlsId']).first : m.create(:mls_id => data['MemberMlsId'])
109
+ when 'Office' then m.where(:lo_mls_id => data['OfficeMlsId']).exists? ? m.where(:lo_mls_id => data['OfficeMlsId']).first : m.create(:lo_mls_id => data['OfficeMlsId'])
110
+ when 'Media' then m.where(:media_id => data['MediaObjectID'] ).exists? ? m.where(:media_id => data['MediaObjectID'] ).first : m.create(:media_id => data['MediaObjectID'] )
107
111
  end
112
+ self.log "Found matching object ID #{obj.id}"
108
113
  return obj
109
114
  end
110
115
 
@@ -113,31 +118,42 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
113
118
  #=============================================================================
114
119
 
115
120
  def self.update_after(date_modified, save_images = true)
116
- self.delay(:priority => 10, :queue => 'rets').update_helper('Listing' , date_modified, save_images)
121
+ self.log "Updating after #{date_modified}"
122
+ self.delay(:priority => 10, :queue => 'rets').update_helper('Property' , date_modified, save_images)
117
123
  self.delay(:priority => 10, :queue => 'rets').update_helper('Office' , date_modified, save_images)
118
- self.delay(:priority => 10, :queue => 'rets').update_helper('Agent' , date_modified, save_images)
124
+ self.delay(:priority => 10, :queue => 'rets').update_helper('Member' , date_modified, save_images)
119
125
  self.delay(:priority => 10, :queue => 'rets').update_helper('OpenHouse', date_modified, save_images)
120
126
  end
121
127
 
122
- def self.update_helper(class_type, date_modified, save_images = true)
128
+ def self.update_helper(class_type, date_modified, save_images = true)
129
+ self.log "In update helper for #{class_type}"
123
130
  m = self.meta(class_type)
124
131
  k = m.remote_key_field
125
132
  d = date_modified.in_time_zone(CabooseRets::timezone).strftime("%FT%T")
133
+
134
+ statusquery = ""
135
+ case class_type
136
+ when 'Property' then statusquery = "MlsStatus=Active"
137
+ when 'Office' then statusquery = "OfficeStatus=Active"
138
+ when 'Member' then statusquery = "MemberStatus=Active"
139
+ when 'OpenHouse' then statusquery = "OpenHouseKeyNumeric=0+"
140
+ end
141
+
126
142
  params = {
127
143
  :search_type => m.search_type,
128
144
  :class => class_type,
129
145
  :select => [m.remote_key_field],
130
146
  :querytype => 'DMQL2',
131
- :query => "(#{m.date_modified_field}=#{d}+)",
147
+ :query => "(#{m.date_modified_field}=#{d}+)AND(#{statusquery})",
132
148
  :standard_names_only => true,
133
149
  :timeout => -1
134
150
  }
135
151
  self.log(params)
136
152
  self.client.search(params) do |data|
137
153
  case class_type
138
- when 'Listing' then self.delay(:priority => 10, :queue => 'rets').import_properties(data[k], save_images)
154
+ when 'Property' then self.delay(:priority => 10, :queue => 'rets').import_properties(data[k], save_images)
139
155
  when 'Office' then self.delay(:priority => 10, :queue => 'rets').import_office( data[k], save_images)
140
- when 'Agent' then self.delay(:priority => 10, :queue => 'rets').import_agent( data[k], save_images)
156
+ when 'Member' then self.delay(:priority => 10, :queue => 'rets').import_agent( data[k], save_images)
141
157
  when 'OpenHouse' then self.delay(:priority => 10, :queue => 'rets').import_open_house(data[k], save_images)
142
158
  end
143
159
  end
@@ -158,36 +174,33 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
158
174
  # end
159
175
  # end
160
176
 
161
- def self.import_properties(mui, save_images = true)
162
- self.import('Listing', "(Matrix_Unique_ID=#{mui})")
163
- p = CabooseRets::Property.where(:matrix_unique_id => mui.to_s).first
164
- # p = CabooseRets::Property.create(:matrix_unique_id => mui.to_s) if p.nil?
177
+ def self.import_properties(mls_id, save_images = true)
178
+ self.import('Property', "(ListingId=#{mls_id})")
179
+ p = CabooseRets::Property.where(:mls_number => mls_id.to_s).first
165
180
  if p != nil
166
- self.download_property_images(p)
181
+ self.download_property_images(p) if save_images
167
182
  self.update_coords(p)
168
183
  else
169
- self.log("No Property associated with #{mui}")
184
+ self.log("No Property associated with #{mls_id}")
170
185
  end
171
186
  end
172
187
 
173
- def self.import_office(mui, save_images = true)
174
- self.import('Office', "(matrix_unique_id=#{mui})")
175
- office = CabooseRets::Office.where(:matrix_unique_id => mui.to_s).first
176
- # self.download_office_image(office) if save_images == true
188
+ def self.import_office(mls_id, save_images = true)
189
+ self.import('Office', "(OfficeMlsId=#{mls_id})")
190
+ office = CabooseRets::Office.where(:matrix_unique_id => mls_id.to_s).first
177
191
  end
178
192
 
179
- def self.import_agent(mui, save_images = true)
180
- self.import('Agent', "(Matrix_Unique_ID=#{mui})")
181
- a = CabooseRets::Agent.where(:matrix_unique_id => mui.to_s).first
182
- # self.download_agent_image(a) #if save_images == true
193
+ def self.import_agent(mls_id, save_images = true)
194
+ self.import('Member', "(MemberMlsId=#{mls_id})")
195
+ a = CabooseRets::Agent.where(:mls_id => mls_id.to_s).first
183
196
  end
184
197
 
185
- def self.import_open_house(mui, save_images = true)
186
- self.import('OpenHouse', "(Matrix_Unique_ID=#{mui})")
198
+ def self.import_open_house(oh_id, save_images = true)
199
+ self.import('OpenHouse', "(OpenHouseKey=#{oh_id})")
187
200
  end
188
201
 
189
202
  def self.import_media(id, save_images = true)
190
- self.import('GFX', "((MEDIA_ID=#{id}+),(MEDIA_ID=#{id}-))")
203
+ self.import('Media', "((MediaObjectID=#{id}+),(MediaObjectID=#{id}-))")
191
204
  end
192
205
 
193
206
  #=============================================================================
@@ -233,11 +246,13 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
233
246
  # end
234
247
 
235
248
  def self.download_property_images(p)
236
- self.log "Saving images for #{p.matrix_unique_id}..."
249
+ self.log "Saving images for #{p.mls_number}..."
237
250
  begin
238
- # url = "http://rets.wamls.mlsmatrix.com/rets/GetObject.ashx?Type=Photo&Resource=Property&ID=1026514:1"
239
- self.client.get_object(:resource => 'Property', :type => 'LargePhoto', :location=> false, :id => "#{p.matrix_unique_id}:*") do |headers, content|
240
- m = CabooseRets::Media.where(:media_mui => headers['content-id'], :media_order => headers['object-id']).first
251
+ self.client.get_object(:resource => 'Property', :type => 'Photo', :location=> false, :id => "#{p.matrix_unique_id}:*") do |headers, content|
252
+
253
+ self.log "headers: #{headers.to_s}"
254
+
255
+ m = CabooseRets::Media.where(:media_mui => headers['content-id'], :media_order => headers['orderhint']).first
241
256
  m = CabooseRets::Media.new if m.nil?
242
257
 
243
258
  tmp_path = "#{Rails.root}/tmp/rets_media_#{headers['content-id']}:#{headers['object-id']}.jpeg"
@@ -249,8 +264,8 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
249
264
 
250
265
  # Parse downloaded content
251
266
  m.media_mui = headers['content-id']
252
- m.media_order = headers['object-id']
253
- m.media_remarks = headers['content-description']
267
+ m.media_order = headers['orderhint']
268
+ # m.media_remarks = headers['ShortDescription']
254
269
  m.media_type = 'Photo'
255
270
 
256
271
  cm = Caboose::Media.new
@@ -266,26 +281,26 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
266
281
  # Remove temporary file
267
282
  `rm #{tmp_path}`
268
283
 
269
- self.log("Image #{headers['content-id']}:#{headers['object-id']} saved")
284
+ self.log("Image rets_media_#{headers['content-id']}_#{headers['object-id']} saved")
270
285
  end
271
286
  rescue RETS::APIError => err
272
- self.log "No image for #{p.matrix_unique_id}."
287
+ self.log "No image for #{p.mls_number}."
273
288
  self.log err
274
289
  end
275
290
  end
276
291
 
277
292
  def self.download_agent_image(agent)
278
- self.log "Saving image for #{agent.first_name} #{agent.last_name}..."
279
- begin
280
- self.client.get_object(:resource => :Agent, :type => :Photo, :location => true, :id => property.list_agent_mls_id) do |headers, content|
281
- agent.verify_meta_exists
282
- agent.meta.image_location = headers['location']
283
- agent.meta.save
284
- end
285
- rescue RETS::APIError => err
286
- self.log "No image for #{agent.first_name} #{agent.last_name}."
287
- self.log err
288
- end
293
+ # self.log "Saving image for #{agent.first_name} #{agent.last_name}..."
294
+ # begin
295
+ # self.client.get_object(:resource => :Member, :type => :Photo, :location => true, :id => property.list_agent_mls_id) do |headers, content|
296
+ # agent.verify_meta_exists
297
+ # agent.meta.image_location = headers['location']
298
+ # agent.meta.save
299
+ # end
300
+ # rescue RETS::APIError => err
301
+ # self.log "No image for #{agent.first_name} #{agent.last_name}."
302
+ # self.log err
303
+ # end
289
304
  end
290
305
 
291
306
  def self.download_office_image(office)
@@ -311,16 +326,16 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
311
326
  model = CabooseRets::Property
312
327
  i = 0
313
328
  self.log "Updating coords properties..."
314
- model.where(:latitude => nil).reorder(:matrix_unique_id).each do |p1|
329
+ model.where(:latitude => nil).reorder(:mls_number).each do |p1|
315
330
  self.delay(:priority => 10, :queue => 'rets').update_coords(p1)
316
331
  end
317
332
  return
318
333
  end
319
334
 
320
- self.log "Getting coords for Matrix_Unique_ID #{p.matrix_unique_id}..."
335
+ self.log "Getting coords for MLS # #{p.mls_number}..."
321
336
  coords = self.coords_from_address(CGI::escape "#{p.street_number} #{p.street_name}, #{p.city}, #{p.state_or_province} #{p.postal_code}")
322
337
  if coords.nil? || coords == false
323
- self.log "Can't set coords for Matrix_Unique_ID #{p.matrix_unique_id}..."
338
+ self.log "Can't set coords for MLS # #{p.mls_number}..."
324
339
  return
325
340
  end
326
341
 
@@ -330,9 +345,8 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
330
345
  end
331
346
 
332
347
  def self.coords_from_address(address)
333
- #return false
334
348
  begin
335
- uri = "https://maps.googleapis.com/maps/api/geocode/json?address=#{address}&sensor=false"
349
+ uri = "https://maps.googleapis.com/maps/api/geocode/json?key=AIzaSyBD34Da5DhRH5wkq3sROsE7-jv90-f1v6o&address=#{address}"
336
350
  uri.gsub!(" ", "+")
337
351
  resp = HTTParty.get(uri)
338
352
  json = JSON.parse(resp.body)
@@ -352,13 +366,13 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
352
366
  self.log('purging')
353
367
  self.purge_properties
354
368
  self.purge_offices
355
- #self.purge_agents
369
+ self.purge_agents
356
370
  self.purge_open_houses
357
371
  end
358
372
 
359
- def self.purge_properties() self.delay(:priority => 10, :queue => 'rets').purge_helper('Listing', '2012-01-01') end
373
+ def self.purge_properties() self.delay(:priority => 10, :queue => 'rets').purge_helper('Property', '2012-01-01') end
360
374
  def self.purge_offices() self.delay(:priority => 10, :queue => 'rets').purge_helper('Office', '2012-01-01') end
361
- def self.purge_agents() self.delay(:priority => 10, :queue => 'rets').purge_helper('Agent', '2012-01-01') end
375
+ def self.purge_agents() self.delay(:priority => 10, :queue => 'rets').purge_helper('Member', '2012-01-01') end
362
376
  def self.purge_open_houses() self.delay(:priority => 10, :queue => 'rets').purge_helper('OpenHouse', '2012-01-01') end
363
377
 
364
378
 
@@ -370,10 +384,20 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
370
384
 
371
385
  # Get the total number of records
372
386
  self.log("- Getting total number of records for #{class_type}...")
387
+
388
+ statusquery = ""
389
+
390
+ case class_type
391
+ when 'Property' then statusquery = "MlsStatus=Active"
392
+ when 'Office' then statusquery = "OfficeStatus=Active"
393
+ when 'Member' then statusquery = "MemberStatus=Active"
394
+ when 'OpenHouse' then statusquery = "OpenHouseKeyNumeric=0+"
395
+ end
396
+
373
397
  params = {
374
398
  :search_type => m.search_type,
375
399
  :class => class_type,
376
- :query => "(#{m.date_modified_field}=#{date_modified}T00:00:01+)",
400
+ :query => "(#{m.date_modified_field}=#{date_modified}T00:00:01+)AND(#{statusquery})",
377
401
  :standard_names_only => true,
378
402
  :timeout => -1
379
403
  }
@@ -394,6 +418,8 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
394
418
  # Only do stuff if we got a real response from the server
395
419
  if ids.count > 0
396
420
 
421
+ puts "Remote IDs found: #{ids.to_s}"
422
+
397
423
  # Delete any records in the local database that shouldn't be there
398
424
  self.log("- Finding #{class_type} records in the local database that are not in the remote database...")
399
425
  t = m.local_table
@@ -401,6 +427,7 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
401
427
  query = "select distinct #{k} from #{t}"
402
428
  rows = ActiveRecord::Base.connection.select_all(ActiveRecord::Base.send(:sanitize_sql_array, query))
403
429
  local_ids = rows.collect{ |row| row[k] }
430
+ puts "Local IDs found: #{local_ids.to_s}"
404
431
  ids_to_remove = local_ids - ids
405
432
  self.log("- Found #{ids_to_remove.count} #{class_type} records in the local database that are not in the remote database.")
406
433
  self.log("- Deleting #{class_type} records in the local database that shouldn't be there...")
@@ -412,15 +439,16 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
412
439
  query = "select distinct #{k} from #{t}"
413
440
  rows = ActiveRecord::Base.connection.select_all(ActiveRecord::Base.send(:sanitize_sql_array, query))
414
441
  local_ids = rows.collect{ |row| row[k] }
442
+ puts "Local IDs found: #{local_ids.to_s}"
415
443
  ids_to_add = ids - local_ids
416
444
  ids_to_add = ids_to_add.sort.reverse
417
445
  self.log("- Found #{ids_to_add.count} #{class_type} records in the remote database that we need to add to the local database.")
418
446
  ids_to_add.each do |id|
419
447
  self.log("- Importing #{id}...")
420
448
  case class_type
421
- when "Listing" then self.delay(:priority => 10, :queue => 'rets').import_properties(id, false)
449
+ when "Property" then self.delay(:priority => 10, :queue => 'rets').import_properties(id, false)
422
450
  when "Office" then self.delay(:priority => 10, :queue => 'rets').import_office(id, false)
423
- when "Agent" then self.delay(:priority => 10, :queue => 'rets').import_agent(id, false)
451
+ when "Member" then self.delay(:priority => 10, :queue => 'rets').import_agent(id, false)
424
452
  when "OpenHouse" then self.delay(:priority => 10, :queue => 'rets').import_open_house(id, false)
425
453
  end
426
454
  end
@@ -465,9 +493,9 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
465
493
  ids_to_add.each do |id|
466
494
  self.log("Importing #{id}...")
467
495
  case class_type
468
- when "Listing" then self.delay(:priority => 10, :queue => 'rets').import_properties(id, false)
496
+ when "Property" then self.delay(:priority => 10, :queue => 'rets').import_properties(id, false)
469
497
  when "Office" then self.delay(:priority => 10, :queue => 'rets').import_office(id, false)
470
- when "Agent" then self.delay(:priority => 10, :queue => 'rets').import_agent(id, false)
498
+ when "Member" then self.delay(:priority => 10, :queue => 'rets').import_agent(id, false)
471
499
  when "OpenHouse" then self.delay(:priority => 10, :queue => 'rets').import_open_house(id, false)
472
500
  end
473
501
  end
@@ -337,50 +337,52 @@ class CabooseRets::Schema < Caboose::Utilities::Schema
337
337
  }
338
338
  end
339
339
 
340
- def self.load_data
340
+ def self.load_data
341
341
 
342
- bt = Caboose::BlockType.where(:name => 'layout_rets').first
343
- if bt.nil?
344
- cat = Caboose::BlockTypeCategory.where(:name => 'Layouts').first
345
- bt = Caboose::BlockType.create(:name => 'layout_rets', :description => 'RETS Layout', :block_type_category_id => cat.id, :allow_child_blocks => false, :field_type => 'block')
346
- end
342
+ # bt = Caboose::BlockType.where(:name => 'layout_rets').first
343
+ # if bt.nil?
344
+ # cat = Caboose::BlockTypeCategory.where(:name => 'Layouts').first
345
+ # bt = Caboose::BlockType.create(:name => 'layout_rets', :description => 'RETS Layout', :block_type_category_id => cat.id, :allow_child_blocks => false, :field_type => 'block')
346
+ # end
347
347
 
348
- Caboose::Site.where(:use_rets => true).reorder(:id).all.each do |site|
349
- home_page = Caboose::Page.index_page(site.id)
348
+ # Caboose::Site.where(:use_rets => true).reorder(:id).all.each do |site|
349
+ # home_page = Caboose::Page.index_page(site.id)
350
350
 
351
- # Check that the rets layout is applied to the site
352
- bt.add_to_site(site.id)
351
+ # # Check that the rets layout is applied to the site
352
+ # bt.add_to_site(site.id)
353
353
 
354
- # Verify that the site has all the rets pages created and each page has the rets layout
355
- rets_page = Caboose::Page.where(:site_id => site.id, :alias => 'rets').first
356
- rets_page = Caboose::Page.create(:site_id => site.id, :alias => 'rets', :slug => 'rets', :uri => 'rets', :title => 'RETS', :parent_id => home_page.id) if rets_page.nil?
354
+ # # Verify that the site has all the rets pages created and each page has the rets layout
355
+ # rets_page = Caboose::Page.where(:site_id => site.id, :alias => 'rets').first
356
+ # rets_page = Caboose::Page.create(:site_id => site.id, :alias => 'rets', :slug => 'rets', :uri => 'rets', :title => 'RETS', :parent_id => home_page.id) if rets_page.nil?
357
357
 
358
- pages = []
359
- if !Caboose::Page.where(:site_id => site.id, :alias => 'property').exists?
360
- then pages << Caboose::Page.create(:site_id => site.id, :slug => 'properties' , :alias => 'property' , :uri => 'property' , :title => 'Properties' , :parent_id => rets_page.id)
361
- end
362
- if !Caboose::Page.where(:site_id => site.id, :alias => 'open-houses' ).exists?
363
- then pages << Caboose::Page.create(:site_id => site.id, :slug => 'open-houses' , :alias => 'open-houses' , :uri => 'open-houses' , :title => 'Open Houses' , :parent_id => rets_page.id)
364
- end
365
- if !Caboose::Page.where(:site_id => site.id, :alias => 'agents' ).exists?
366
- then pages << Caboose::Page.create(:site_id => site.id, :slug => 'agents' , :alias => 'agents' , :uri => 'agents' , :title => 'Agents' , :parent_id => rets_page.id)
367
- end
368
- if !Caboose::Page.where(:site_id => site.id, :alias => 'saved-searches' ).exists?
369
- then pages << Caboose::Page.create(:site_id => site.id, :slug => 'saved-searches' , :alias => 'saved-searches' , :uri => 'saved-searches' , :title => 'Saved Searches' , :parent_id => rets_page.id)
370
- end
371
- if !Caboose::Page.where(:site_id => site.id, :alias => 'saved-properties' ).exists?
372
- then pages << Caboose::Page.create(:site_id => site.id, :slug => 'saved-properties' , :alias => 'saved-properties' , :uri => 'saved-properties' , :title => 'Saved Properties' , :parent_id => rets_page.id)
373
- end
358
+ # pages = []
359
+ # if !Caboose::Page.where(:site_id => site.id, :alias => 'property').exists?
360
+ # then pages << Caboose::Page.create(:site_id => site.id, :slug => 'properties' , :alias => 'property' , :uri => 'property' , :title => 'Properties' , :parent_id => rets_page.id)
361
+ # end
362
+ # if !Caboose::Page.where(:site_id => site.id, :alias => 'open-houses' ).exists?
363
+ # then pages << Caboose::Page.create(:site_id => site.id, :slug => 'open-houses' , :alias => 'open-houses' , :uri => 'open-houses' , :title => 'Open Houses' , :parent_id => rets_page.id)
364
+ # end
365
+ # if !Caboose::Page.where(:site_id => site.id, :alias => 'agents' ).exists?
366
+ # then pages << Caboose::Page.create(:site_id => site.id, :slug => 'agents' , :alias => 'agents' , :uri => 'agents' , :title => 'Agents' , :parent_id => rets_page.id)
367
+ # end
368
+ # if !Caboose::Page.where(:site_id => site.id, :alias => 'saved-searches' ).exists?
369
+ # then pages << Caboose::Page.create(:site_id => site.id, :slug => 'saved-searches' , :alias => 'saved-searches' , :uri => 'saved-searches' , :title => 'Saved Searches' , :parent_id => rets_page.id)
370
+ # end
371
+ # if !Caboose::Page.where(:site_id => site.id, :alias => 'saved-properties' ).exists?
372
+ # then pages << Caboose::Page.create(:site_id => site.id, :slug => 'saved-properties' , :alias => 'saved-properties' , :uri => 'saved-properties' , :title => 'Saved Properties' , :parent_id => rets_page.id)
373
+ # end
374
374
 
375
- pages.each do |p|
376
- Caboose::Block.where(:page_id => p.id).destroy_all
377
- Caboose::Block.create(:page_id => p.id, :block_type_id => bt.id, :name => bt.name)
375
+ # pages.each do |p|
376
+ # Caboose::Block.where(:page_id => p.id).destroy_all
377
+ # Caboose::Block.create(:page_id => p.id, :block_type_id => bt.id, :name => bt.name)
378
378
 
379
- viewers = Caboose::PagePermission.where(:page_id => home_page.id, :action => 'view').pluck(:role_id)
380
- editors = Caboose::PagePermission.where(:page_id => home_page.id, :action => 'edit').pluck(:role_id)
381
- Caboose::Page.update_authorized_for_action(p.id, 'view', viewers)
382
- Caboose::Page.update_authorized_for_action(p.id, 'edit', editors)
383
- end
384
- end
379
+ # viewers = Caboose::PagePermission.where(:page_id => home_page.id, :action => 'view').pluck(:role_id)
380
+ # editors = Caboose::PagePermission.where(:page_id => home_page.id, :action => 'edit').pluck(:role_id)
381
+ # Caboose::Page.update_authorized_for_action(p.id, 'view', viewers)
382
+ # Caboose::Page.update_authorized_for_action(p.id, 'edit', editors)
383
+ # end
384
+ # end
385
385
  end
386
+
387
+
386
388
  end