Fix bug.
This commit is contained in:
parent
8d47bf931d
commit
567073ec3f
|
@ -49,7 +49,7 @@ def initialize
|
||||||
paper_criteria = PaperCriteria.find(params[:id])
|
paper_criteria = PaperCriteria.find(params[:id])
|
||||||
page = Page.where(:module => "e_paper").first.url rescue ""
|
page = Page.where(:module => "e_paper").first.url rescue ""
|
||||||
papers_data = Admin::EpaperHelper.get_paper_data(paper_criteria)
|
papers_data = Admin::EpaperHelper.get_paper_data(paper_criteria)
|
||||||
email = Email.new(:mail_subject => paper_criteria.sending_title, :mail_lang => :zh_tw, :template => "admin/e_paper_criterias/emailer", :template_data => {"paper" => paper_criteria, "page" => "http://" + request.host_with_port + page, "siteurl" => "http://" + request.host_with_port ,"papers_data" => papers_data }, :mail_to => params[:email])
|
email = Email.new(:mail_subject => paper_criteria.sending_title, :mail_lang => I18n.locale, :template => "admin/e_paper_criterias/emailer", :template_data => {"paper" => paper_criteria, "page" => "http://" + request.host_with_port + page, "siteurl" => "http://" + request.host_with_port ,"papers_data" => papers_data }, :mail_to => params[:email], :module_app_key=>'e_paper')
|
||||||
email.deliver
|
email.deliver
|
||||||
render :json => {"success" => true}.to_json
|
render :json => {"success" => true}.to_json
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,9 +3,18 @@ class EPaperSubscriber
|
||||||
include Mongoid::Document
|
include Mongoid::Document
|
||||||
include Mongoid::Timestamps
|
include Mongoid::Timestamps
|
||||||
|
|
||||||
field :email
|
field :email, type: String
|
||||||
field :subscribed, type: Boolean, :default => true
|
field :subscribed, type: Boolean, :default => true
|
||||||
field :language
|
field :language
|
||||||
field :last_paper_sent
|
field :last_paper_sent
|
||||||
|
before_save do
|
||||||
|
self.fix_email
|
||||||
|
if self.class.where(:email=>self.email, :language=>self.language,:subscribed=>true).count != 0
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
def fix_email(save_flag=false)
|
||||||
|
self.email = self.email.to_s.gsub(/[ ]/,'').sub(/;$/, '')
|
||||||
|
self.save if save_flag
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -56,7 +56,10 @@
|
||||||
dataType : "json",
|
dataType : "json",
|
||||||
type : "get"
|
type : "get"
|
||||||
}).done(function(){
|
}).done(function(){
|
||||||
alert("Email sent.")
|
alert("Email sent.");
|
||||||
|
}).fail(function(jqXHR, textStatus, errorThrown){
|
||||||
|
alert("Something went wrong!\nPlease contact customer service!");
|
||||||
|
console.log(errorThrown);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -85,6 +88,10 @@
|
||||||
height: window_height*0.6
|
height: window_height*0.6
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
error: function(error){
|
||||||
|
alert("Something went wrong!\nPlease contact customer service!");
|
||||||
|
console.log(error);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,22 @@
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
|
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
|
||||||
|
Thread.new do
|
||||||
|
s = Site.first
|
||||||
|
update_flag = s.respond_to?(:tmp_flags)
|
||||||
|
need_update = !update_flag || !(s.tmp_flags.include?('ep1'))
|
||||||
|
if need_update
|
||||||
|
EPaperSubscriber.all.to_a.each do |subscriber|
|
||||||
|
subscriber.fix_email
|
||||||
|
EPaperSubscriber.where(:id=>subscriber.id).update_all(:email=>subscriber.email)
|
||||||
|
end
|
||||||
|
if update_flag
|
||||||
|
s = OrbitHelper::SharedHash['current_site']['site'] rescue Site.first
|
||||||
|
s.tmp_flags << 'ep1'
|
||||||
|
s.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
locales = Site.first.in_use_locales rescue I18n.available_locales
|
locales = Site.first.in_use_locales rescue I18n.available_locales
|
||||||
|
|
||||||
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
||||||
|
|
|
@ -26,6 +26,8 @@ namespace :epaper do
|
||||||
end
|
end
|
||||||
emails_invalid = emails - emails_valid
|
emails_invalid = emails - emails_valid
|
||||||
paper.send_failed_emails = []
|
paper.send_failed_emails = []
|
||||||
|
paper.invalid_emails = emails_invalid
|
||||||
|
paper.save
|
||||||
Thread.new do
|
Thread.new do
|
||||||
tmp = []
|
tmp = []
|
||||||
site = Site.first
|
site = Site.first
|
||||||
|
@ -39,7 +41,7 @@ namespace :epaper do
|
||||||
emails_valid.each_slice(mail_limit).each do |slice_emails|
|
emails_valid.each_slice(mail_limit).each do |slice_emails|
|
||||||
invalid_mails = epaper_verify_email(from_addr,slice_emails,tls)
|
invalid_mails = epaper_verify_email(from_addr,slice_emails,tls)
|
||||||
deliver_emails = slice_emails - invalid_mails
|
deliver_emails = slice_emails - invalid_mails
|
||||||
email = Email.new(:mail_subject => paper.sending_title, :mail_lang => args[:locale], :template => "admin/e_paper_criterias/emailer", :template_data => {"paper_id" => paper.id, "page" => "http://" + domain + page, "siteurl" => "http://" + domain, "papers_data" => papers_data }, :mail_to => deliver_emails)
|
email = Email.new(:mail_subject => paper.sending_title, :mail_lang => args[:locale], :template => "admin/e_paper_criterias/emailer", :template_data => {"paper_id" => paper.id, "page" => "http://" + domain + page, "siteurl" => "http://" + domain, "papers_data" => papers_data }, :mail_to => deliver_emails, :module_app_key=>'e_paper')
|
||||||
begin
|
begin
|
||||||
email.save
|
email.save
|
||||||
email.deliver
|
email.deliver
|
||||||
|
@ -51,7 +53,7 @@ namespace :epaper do
|
||||||
error_flag = 0
|
error_flag = 0
|
||||||
begin
|
begin
|
||||||
invalid_mails.each do |invalid_mail|
|
invalid_mails.each do |invalid_mail|
|
||||||
email = Email.create(:mail_subject => paper.sending_title, :mail_lang => args[:locale], :template => "admin/e_paper_criterias/emailer", :template_data => {"paper_id" => paper.id, "page" => "http://" + domain + page, "siteurl" => "http://" + domain, "papers_data" => papers_data }, :mail_to => invalid_mail)
|
email = Email.create(:mail_subject => paper.sending_title, :mail_lang => args[:locale], :template => "admin/e_paper_criterias/emailer", :template_data => {"paper_id" => paper.id, "page" => "http://" + domain + page, "siteurl" => "http://" + domain, "papers_data" => papers_data }, :mail_to => invalid_mail, :module_app_key=>'e_paper')
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
puts [e,e.backtrace]
|
puts [e,e.backtrace]
|
||||||
|
@ -62,8 +64,6 @@ namespace :epaper do
|
||||||
end
|
end
|
||||||
paper.update_attributes(:send_failed_emails => tmp)
|
paper.update_attributes(:send_failed_emails => tmp)
|
||||||
end
|
end
|
||||||
paper.invalid_emails = emails_invalid
|
|
||||||
paper.save
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def epaper_verify_email(from_addr,check_emails,tls) #true if check_email is ok
|
def epaper_verify_email(from_addr,check_emails,tls) #true if check_email is ok
|
||||||
|
|
Loading…
Reference in New Issue