From 2cf332e120ee695c49f436f08ebb3b268218ebbc Mon Sep 17 00:00:00 2001 From: danielvincent <danielgrippi@gmail.com> Date: Tue, 14 Dec 2010 19:27:18 -0800 Subject: [PATCH] Remove sent boolean from requests, finish migration --- app/controllers/requests_controller.rb | 2 +- app/models/request.rb | 3 +-- lib/tasks/migrations.rake | 6 +++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/controllers/requests_controller.rb b/app/controllers/requests_controller.rb index db0d8aba14..843f67c850 100644 --- a/app/controllers/requests_controller.rb +++ b/app/controllers/requests_controller.rb @@ -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 diff --git a/app/models/request.rb b/app/models/request.rb index 15a5371135..1456785aee 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -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} diff --git a/lib/tasks/migrations.rake b/lib/tasks/migrations.rake index c3ec99a4c5..8defa79f99 100644 --- a/lib/tasks/migrations.rake +++ b/lib/tasks/migrations.rake @@ -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' -- GitLab