Permalink
Browse files

Fix issue with migrations sending emails

  • Loading branch information...
1 parent 0738c3a commit b5a34c2bfcc5849fcffabc8a9146ecf6cc05545d Gerry Gleason committed Nov 30, 2012
@@ -148,10 +148,13 @@ def show_file
when Wagn::BadAddress, ActionController::UnknownController, AbstractController::ActionNotFound
[ :bad_address, 404 ]
else
+
notify_airbrake exception if Airbrake.configuration.api_key
if [Wagn::Oops, ActiveRecord::RecordInvalid].member?( exception.class ) && @card && @card.errors.any?
[ :errors, 422]
+ elsif Wagn::Conf[:migration]
+ raise exception
else
Rails.logger.info "\n\nController exception: #{exception.message}"
Rails.logger.debug exception.backtrace*"\n"
View
@@ -21,12 +21,11 @@ def account_info user, subject, message
@message = message.clone
args = { :to => @email, :subject => subject }
- set_from_args args, ( Card.setting('*invite+*from') || begin
+ mail_from args, ( Card.setting('*invite+*from') || begin
curr = Account.user
from_user = curr.anonymous? || curr.id == user.id ? User.admin : curr
"#{from_user.card.name} <#{from_user.email}>"
end ) #FIXME - might want different "from" settings for different contexts?
- mail args
end
def signup_alert invite_request
@@ -43,8 +42,7 @@ def signup_alert invite_request
:subject => "#{invite_request.name} signed up for #{@site}",
:content_type => 'text/html',
}
- set_from_args args, Card.setting('*request+*from') || "#{@name} <#{@email}>"
- mail args
+ mail_from args, Card.setting('*request+*from') || "#{@name} <#{@email}>"
end
@@ -68,8 +66,7 @@ def change_notice user, card, action, watched, subedits=[], updated_card=nil
:subject => "[#{Card.setting :title} notice] #{@updater} #{action} \"#{card.name}\"" ,
:content_type => 'text/html',
}
- set_from_args args, User.admin.email
- mail args
+ mail_from args, User.admin.email
end
def flexmail config
@@ -83,20 +80,20 @@ def flexmail config
end
end
- set_from_args config, config[:from]
- mail config
+ mail_from config, config[:from]
end
private
- def set_from_args args, from
+ def mail_from args, from
from_name, from_email = parse_address( from )
if default_from=@@defaults[:from]
args[:from] = !from_email ? default_from : "#{from_name || from_email} <#{default_from}>"
args[:reply_to] ||= from
else
args[:from] = from
end
+ mail args unless Wagn::Conf[:migration]
end
def parse_address addr
View
@@ -11,13 +11,14 @@
module Wagn
class Conf
class << self
- def [](key) @@hash[key.to_sym] end
- def []=(key, value) @@hash[key.to_sym]=value end
+ def [](key) @@config[key.to_sym] end
+ def []=(key, value) @@config[key.to_sym]=value end
+ def config; @@config.inspect end
WAGN_CONFIG_FILE = ENV['WAGN_CONFIG_FILE'] || File.expand_path('../wagn.yml', __FILE__)
def load
- @@hash = h = {}
+ @@config = h = {}
f = WAGN_CONFIG_FILE
if File.exists?( f ) and y = YAML.load_file( f ) and Hash === y
h.merge! y
@@ -27,7 +28,7 @@ def load
def load_after_app
#could do these at normal load time but can't use Rails.root
- h = @@hash
+ h = @@config
if base_u = h[:base_url]
h[:base_url] = base_u.gsub!(/\/$/,'')
h[:host] = base_u.gsub(/^https?:\/\//,'') unless h[:host]
@@ -1,5 +1,7 @@
class AccountTrait < ActiveRecord::Migration
def up
+ Wagn::Conf[:migration]=true
+
Account.as_bot do
User.all.each do |user|
#next if user.card_id == Card::WagnBotID || user.card_id == Card::AnonID
@@ -16,7 +18,7 @@ def up
def down
Account.as_bot do
- Card.search(:right=>Card::AccountID).items { |c| c.delete; }
+ Card.search(:right=>Card::AccountID).each { |c| c.delete; }
end
end
end
@@ -37,6 +37,7 @@ def send_notifications
end
end
rescue Exception=>e
+ raise e if Wagn::Conf[:migration]
Airbrake.notify e if Airbrake.configuration.api_key
Rails.logger.info "\nController exception: #{e.message}"
Rails.logger.debug e.backtrace*"\n"

0 comments on commit b5a34c2

Please sign in to comment.