Remove sent boolean from requests, finish migration

This commit is contained in:
danielvincent 2010-12-14 19:27:18 -08:00
parent dea8d248e2
commit 2cf332e120
3 changed files with 7 additions and 4 deletions

View file

@ -31,7 +31,7 @@ class RequestsController < ApplicationController
aspect = current_user.aspect_by_id(params[:request][:into])
account = params[:request][:to].strip
person = Person.by_account_identifier(account)
existing_request = Request.from(person).to(current_user.person).where(:sent => false).first if person
existing_request = Request.from(person).to(current_user.person).first if person
if existing_request
current_user.accept_and_respond(existing_request.id, aspect.id)
redirect_to :back

View file

@ -15,7 +15,6 @@ class Request
belongs_to :into, :class => Aspect
belongs_to :from, :class => Person
belongs_to :to, :class => Person
key :sent, Boolean, :default => false
validates_presence_of :from, :to
validate :not_already_connected_if_sent
@ -69,7 +68,7 @@ class Request
end
def self.hashes_for_person person
requests = Request.to(person).all(:sent => false)
requests = Request.to(person).all
senders = Person.all(:id.in => requests.map{|r| r.from_id}, :fields => [:profile])
senders_hash = {}
senders.each{|sender| senders_hash[sender.id] = sender}

View file

@ -29,9 +29,13 @@ namespace :migrations do
task :contacts_as_requests do
require File.join(Rails.root,"config/environment")
puts "Migrating contacts..."
old_contacts = Contact.all(:pending => nil)
old_contacts.each{|contact| contact.pending = false; contact.save}
puts "all done"
puts "Deleting stale requests..."
old_requests = Request.all(:sent => true)
old_requests.each{|request| request.delete}
puts "Done!"
end
desc 'allow to upgrade old image urls to use rel path'