mirror of
https://github.com/standardebooks/web.git
synced 2025-07-06 06:40:33 -04:00
Use exists() for some SQL statements; send thank-you email to patron donors who donate again
This commit is contained in:
parent
a4910b8d67
commit
a442f92e28
3 changed files with 41 additions and 19 deletions
|
@ -52,14 +52,16 @@ $faItemsPerPage = 20; // How many items are on a full page of FA results?
|
||||||
// If /tmp/last-fa-donation doesn't exist, get all transactions from today and create the file.
|
// If /tmp/last-fa-donation doesn't exist, get all transactions from today and create the file.
|
||||||
|
|
||||||
function InsertTransaction($transactionId){
|
function InsertTransaction($transactionId){
|
||||||
$exists = Db::QueryInt('SELECT count(*)
|
$exists = Db::QueryInt('SELECT exists(
|
||||||
from
|
select *
|
||||||
( select 1
|
from
|
||||||
from Payments
|
( select 1
|
||||||
where TransactionId = ?
|
from Payments
|
||||||
union select 1
|
where TransactionId = ?
|
||||||
from PendingPayments
|
union select 1
|
||||||
where TransactionId = ? ) x',
|
from PendingPayments
|
||||||
|
where TransactionId = ? ) x
|
||||||
|
)',
|
||||||
[$transactionId, $transactionId]);
|
[$transactionId, $transactionId]);
|
||||||
|
|
||||||
if(!$exists){
|
if(!$exists){
|
||||||
|
|
|
@ -74,9 +74,11 @@ try{
|
||||||
$log->Write('Processing donation ' . $pendingPayment->TransactionId . ' ...');
|
$log->Write('Processing donation ' . $pendingPayment->TransactionId . ' ...');
|
||||||
|
|
||||||
if(Db::QueryInt('
|
if(Db::QueryInt('
|
||||||
SELECT count(*)
|
SELECT exists(
|
||||||
from Payments
|
select *
|
||||||
where TransactionId = ?
|
from Payments
|
||||||
|
where TransactionId = ?
|
||||||
|
)
|
||||||
', [$pendingPayment->TransactionId]) > 0){
|
', [$pendingPayment->TransactionId]) > 0){
|
||||||
$log->Write('Donation already exists in database.');
|
$log->Write('Donation already exists in database.');
|
||||||
continue;
|
continue;
|
||||||
|
@ -201,10 +203,12 @@ try{
|
||||||
if($payment->User !== null){
|
if($payment->User !== null){
|
||||||
// Are we already a patron?
|
// Are we already a patron?
|
||||||
if(Db::QueryInt('
|
if(Db::QueryInt('
|
||||||
SELECT count(*)
|
SELECT exists(
|
||||||
from Patrons
|
select *
|
||||||
where UserId = ?
|
from Patrons
|
||||||
and Ended is null
|
where UserId = ?
|
||||||
|
and Ended is null
|
||||||
|
)
|
||||||
', [$payment->UserId]) == 0){
|
', [$payment->UserId]) == 0){
|
||||||
// Not a patron yet, add them to the Patrons Circle
|
// Not a patron yet, add them to the Patrons Circle
|
||||||
|
|
||||||
|
@ -224,6 +228,21 @@ try{
|
||||||
$log->Write('Adding donor as patron ...');
|
$log->Write('Adding donor as patron ...');
|
||||||
$patron->Create();
|
$patron->Create();
|
||||||
}
|
}
|
||||||
|
elseif(!$payment->IsRecurring && !$payment->IsMatchingDonation){
|
||||||
|
// User is already a patron, but they made another non-recurring, non-matching donation.
|
||||||
|
// Send a thank-you email.
|
||||||
|
|
||||||
|
$log->Write('Sending thank you email to patron donor donating extra.');
|
||||||
|
$em = new Email();
|
||||||
|
$em->To = $payment->User->Email;
|
||||||
|
$em->ToName = $payment->User->Name;
|
||||||
|
$em->From = EDITOR_IN_CHIEF_EMAIL_ADDRESS;
|
||||||
|
$em->FromName = EDITOR_IN_CHIEF_NAME;
|
||||||
|
$em->Subject = 'Thank you for supporting Standard Ebooks!';
|
||||||
|
$em->Body = Template::EmailDonationThankYou();
|
||||||
|
$em->TextBody = Template::EmailDonationThankYouText();
|
||||||
|
$em->Send();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
elseif(!$payment->IsRecurring && !$payment->IsMatchingDonation){
|
elseif(!$payment->IsRecurring && !$payment->IsMatchingDonation){
|
||||||
// Fully-anonymous, non-recurring donation eligible for the Patrons Circle. We can't notify them, but do notify the admins.
|
// Fully-anonymous, non-recurring donation eligible for the Patrons Circle. We can't notify them, but do notify the admins.
|
||||||
|
|
|
@ -25,10 +25,11 @@ try{
|
||||||
$isUserAgentAllowed = false;
|
$isUserAgentAllowed = false;
|
||||||
if(isset($_SERVER['HTTP_USER_AGENT'])){
|
if(isset($_SERVER['HTTP_USER_AGENT'])){
|
||||||
$isUserAgentAllowed = Db::QueryInt('
|
$isUserAgentAllowed = Db::QueryInt('
|
||||||
SELECT count(*)
|
SELECT exists(
|
||||||
from FeedUserAgents
|
select *
|
||||||
where instr(?, UserAgent)
|
from FeedUserAgents
|
||||||
limit 1
|
where instr(?, UserAgent)
|
||||||
|
)
|
||||||
', [$_SERVER['HTTP_USER_AGENT']]);
|
', [$_SERVER['HTTP_USER_AGENT']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue