Pretty print SQL

This commit is contained in:
Alex Cabal 2022-12-24 15:44:42 -06:00
parent 31a8bc2d6c
commit 26a24cdbe2
17 changed files with 316 additions and 82 deletions

View file

@ -47,7 +47,14 @@ class NewsletterSubscription extends PropertiesBase{
$this->Created = new DateTime(); $this->Created = new DateTime();
try{ try{
Db::Query('INSERT into NewsletterSubscriptions (UserId, IsConfirmed, IsSubscribedToNewsletter, IsSubscribedToSummary, Created) values (?, ?, ?, ?, ?);', [$this->User->UserId, false, $this->IsSubscribedToNewsletter, $this->IsSubscribedToSummary, $this->Created]); Db::Query('
INSERT into NewsletterSubscriptions (UserId, IsConfirmed, IsSubscribedToNewsletter, IsSubscribedToSummary, Created)
values (?,
?,
?,
?,
?)
', [$this->User->UserId, false, $this->IsSubscribedToNewsletter, $this->IsSubscribedToSummary, $this->Created]);
} }
catch(PDOException $ex){ catch(PDOException $ex){
if($ex->errorInfo[1] == 1062){ if($ex->errorInfo[1] == 1062){
@ -66,7 +73,13 @@ class NewsletterSubscription extends PropertiesBase{
public function Save(): void{ public function Save(): void{
$this->Validate(); $this->Validate();
Db::Query('UPDATE NewsletterSubscriptions set IsConfirmed = ?, IsSubscribedToNewsletter = ?, IsSubscribedToSummary = ? where UserId = ?', [$this->IsConfirmed, $this->IsSubscribedToNewsletter, $this->IsSubscribedToSummary, $this->UserId]); Db::Query('
UPDATE NewsletterSubscriptions
set IsConfirmed = ?,
IsSubscribedToNewsletter = ?,
IsSubscribedToSummary = ?
where UserId = ?
', [$this->IsConfirmed, $this->IsSubscribedToNewsletter, $this->IsSubscribedToSummary, $this->UserId]);
} }
public function SendConfirmationEmail(): void{ public function SendConfirmationEmail(): void{
@ -83,11 +96,19 @@ class NewsletterSubscription extends PropertiesBase{
} }
public function Confirm(): void{ public function Confirm(): void{
Db::Query('UPDATE NewsletterSubscriptions set IsConfirmed = true where UserId = ?;', [$this->UserId]); Db::Query('
UPDATE NewsletterSubscriptions
set IsConfirmed = true
where UserId = ?
', [$this->UserId]);
} }
public function Delete(): void{ public function Delete(): void{
Db::Query('DELETE from NewsletterSubscriptions where UserId = ?;', [$this->UserId]); Db::Query('
DELETE
from NewsletterSubscriptions
where UserId = ?
', [$this->UserId]);
} }
public function Validate(): void{ public function Validate(): void{
@ -112,7 +133,12 @@ class NewsletterSubscription extends PropertiesBase{
// *********** // ***********
public static function Get(string $uuid): NewsletterSubscription{ public static function Get(string $uuid): NewsletterSubscription{
$result = Db::Query('SELECT ns.* from NewsletterSubscriptions ns inner join Users u using(UserId) where u.Uuid = ?', [$uuid], 'NewsletterSubscription'); $result = Db::Query('
SELECT ns.*
from NewsletterSubscriptions ns
inner join Users u using(UserId)
where u.Uuid = ?
', [$uuid], 'NewsletterSubscription');
if(sizeof($result) == 0){ if(sizeof($result) == 0){
throw new Exceptions\InvalidNewsletterSubscriptionException(); throw new Exceptions\InvalidNewsletterSubscriptionException();

View file

@ -20,14 +20,33 @@ class Patron extends PropertiesBase{
public function Create(): void{ public function Create(): void{
$this->Created = new DateTime(); $this->Created = new DateTime();
Db::Query('INSERT into Patrons (Created, UserId, IsAnonymous, AlternateName, IsSubscribedToEmails) values(?, ?, ?, ?, ?);', [$this->Created, $this->UserId, $this->IsAnonymous, $this->AlternateName, $this->IsSubscribedToEmails]); Db::Query('
INSERT into Patrons (Created, UserId, IsAnonymous, AlternateName, IsSubscribedToEmails)
values(?,
?,
?,
?,
?)
', [$this->Created, $this->UserId, $this->IsAnonymous, $this->AlternateName, $this->IsSubscribedToEmails]);
Db::Query('
Db::Query('INSERT into Benefits (UserId, CanVote, CanAccessFeeds, CanBulkDownload) values (?, true, true, true) on duplicate key update CanVote = true, CanAccessFeeds = true, CanBulkDownload = true', [$this->UserId]); INSERT into Benefits (UserId, CanVote, CanAccessFeeds, CanBulkDownload)
values (?,
true,
true,
true) on duplicate key
update CanVote = true,
CanAccessFeeds = true,
CanBulkDownload = true
', [$this->UserId]);
// If this is a patron for the first time, send the first-time patron email. // If this is a patron for the first time, send the first-time patron email.
// Otherwise, send the returning patron email. // Otherwise, send the returning patron email.
$isReturning = Db::QueryInt('SELECT count(*) from Patrons where UserId = ?', [$this->UserId]) > 1; $isReturning = Db::QueryInt('
SELECT count(*)
from Patrons
where UserId = ?
', [$this->UserId]) > 1;
$this->SendWelcomeEmail($isReturning); $this->SendWelcomeEmail($isReturning);
} }
@ -60,7 +79,11 @@ class Patron extends PropertiesBase{
// *********** // ***********
public static function Get(?int $userId): Patron{ public static function Get(?int $userId): Patron{
$result = Db::Query('SELECT * from Patrons where UserId = ?', [$userId], 'Patron'); $result = Db::Query('
SELECT *
from Patrons
where UserId = ?
', [$userId], 'Patron');
if(sizeof($result) == 0){ if(sizeof($result) == 0){
throw new Exceptions\InvalidPatronException(); throw new Exceptions\InvalidPatronException();
@ -70,7 +93,12 @@ class Patron extends PropertiesBase{
} }
public static function GetByEmail(?string $email): Patron{ public static function GetByEmail(?string $email): Patron{
$result = Db::Query('SELECT p.* from Patrons p inner join Users u using(UserId) where u.Email = ?', [$email], 'Patron'); $result = Db::Query('
SELECT p.*
from Patrons p
inner join Users u using(UserId)
where u.Email = ?
', [$email], 'Patron');
if(sizeof($result) == 0){ if(sizeof($result) == 0){
throw new Exceptions\InvalidPatronException(); throw new Exceptions\InvalidPatronException();

View file

@ -33,7 +33,11 @@ class Payment extends PropertiesBase{
$this->User = $user; $this->User = $user;
// Update their name in case we have their email (but not name) recorded from a newsletter subscription // Update their name in case we have their email (but not name) recorded from a newsletter subscription
Db::Query('UPDATE Users set Name = ? where UserId = ?', [$this->User->Name, $this->User->UserId]); Db::Query('
UPDATE Users
set Name = ?
where UserId = ?
', [$this->User->Name, $this->User->UserId]);
} }
catch(Exceptions\InvalidUserException $ex){ catch(Exceptions\InvalidUserException $ex){
// User doesn't exist, create it now // User doesn't exist, create it now
@ -45,7 +49,16 @@ class Payment extends PropertiesBase{
} }
try{ try{
Db::Query('INSERT into Payments (UserId, Created, ChannelId, TransactionId, Amount, Fee, IsRecurring) values(?, ?, ?, ?, ?, ?, ?);', [$this->UserId, $this->Created, $this->ChannelId, $this->TransactionId, $this->Amount, $this->Fee, $this->IsRecurring]); Db::Query('
INSERT into Payments (UserId, Created, ChannelId, TransactionId, Amount, Fee, IsRecurring)
values(?,
?,
?,
?,
?,
?,
?)
', [$this->UserId, $this->Created, $this->ChannelId, $this->TransactionId, $this->Amount, $this->Fee, $this->IsRecurring]);
} }
catch(PDOException $ex){ catch(PDOException $ex){
if($ex->errorInfo[1] == 1062){ if($ex->errorInfo[1] == 1062){

View file

@ -36,7 +36,12 @@ class Poll extends PropertiesBase{
protected function GetVoteCount(): int{ protected function GetVoteCount(): int{
if($this->_VoteCount === null){ if($this->_VoteCount === null){
$this->_VoteCount = Db::QueryInt('SELECT count(*) from PollVotes pv inner join PollItems pi using (PollItemId) where pi.PollId = ?', [$this->PollId]); $this->_VoteCount = Db::QueryInt('
SELECT count(*)
from PollVotes pv
inner join PollItems pi using (PollItemId)
where pi.PollId = ?
', [$this->PollId]);
} }
return $this->_VoteCount; return $this->_VoteCount;
@ -47,7 +52,12 @@ class Poll extends PropertiesBase{
*/ */
protected function GetPollItems(): array{ protected function GetPollItems(): array{
if($this->_PollItems === null){ if($this->_PollItems === null){
$this->_PollItems = Db::Query('SELECT * from PollItems where PollId = ? order by SortOrder asc', [$this->PollId], 'PollItem'); $this->_PollItems = Db::Query('
SELECT *
from PollItems
where PollId = ?
order by SortOrder asc
', [$this->PollId], 'PollItem');
} }
return $this->_PollItems; return $this->_PollItems;
@ -91,7 +101,11 @@ class Poll extends PropertiesBase{
throw new Exceptions\InvalidPollException(); throw new Exceptions\InvalidPollException();
} }
$result = Db::Query('SELECT * from Polls where PollId = ?', [$pollId], 'Poll'); $result = Db::Query('
SELECT *
from Polls
where PollId = ?
', [$pollId], 'Poll');
if(sizeof($result) == 0){ if(sizeof($result) == 0){
throw new Exceptions\InvalidPollException(); throw new Exceptions\InvalidPollException();
@ -105,7 +119,11 @@ class Poll extends PropertiesBase{
throw new Exceptions\InvalidPollException(); throw new Exceptions\InvalidPollException();
} }
$result = Db::Query('SELECT * from Polls where UrlName = ?', [$urlName], 'Poll'); $result = Db::Query('
SELECT *
from Polls
where UrlName = ?
', [$urlName], 'Poll');
if(sizeof($result) == 0){ if(sizeof($result) == 0){
throw new Exceptions\InvalidPollException(); throw new Exceptions\InvalidPollException();

View file

@ -19,7 +19,12 @@ class PollItem extends PropertiesBase{
protected function GetVoteCount(): int{ protected function GetVoteCount(): int{
if($this->_VoteCount === null){ if($this->_VoteCount === null){
$this->_VoteCount = Db::QueryInt('SELECT count(*) from PollVotes pv inner join PollItems pi using (PollItemId) where pi.PollItemId = ?', [$this->PollItemId]); $this->_VoteCount = Db::QueryInt('
SELECT count(*)
from PollVotes pv
inner join PollItems pi using (PollItemId)
where pi.PollItemId = ?
', [$this->PollItemId]);
} }
return $this->_VoteCount; return $this->_VoteCount;
@ -35,7 +40,11 @@ class PollItem extends PropertiesBase{
throw new Exceptions\InvalidPollItemException(); throw new Exceptions\InvalidPollItemException();
} }
$result = Db::Query('SELECT * from PollItems where PollItemId = ?', [$pollItemId], 'PollItem'); $result = Db::Query('
SELECT *
from PollItems
where PollItemId = ?
', [$pollItemId], 'PollItem');
if(sizeof($result) == 0){ if(sizeof($result) == 0){
throw new Exceptions\InvalidPollItemException(); throw new Exceptions\InvalidPollItemException();

View file

@ -93,7 +93,12 @@ class PollVote extends PropertiesBase{
$this->Validate(); $this->Validate();
$this->Created = new DateTime(); $this->Created = new DateTime();
Db::Query('INSERT into PollVotes (UserId, PollItemId, Created) values (?, ?, ?)', [$this->UserId, $this->PollItemId, $this->Created]); Db::Query('
INSERT into PollVotes (UserId, PollItemId, Created)
values (?,
?,
?)
', [$this->UserId, $this->PollItemId, $this->Created]);
} }
public static function Get(?string $pollUrlName, ?int $userId): PollVote{ public static function Get(?string $pollUrlName, ?int $userId): PollVote{
@ -101,10 +106,16 @@ class PollVote extends PropertiesBase{
throw new Exceptions\InvalidPollVoteException(); throw new Exceptions\InvalidPollVoteException();
} }
$result = Db::Query('SELECT pv.* from PollVotes pv inner join $result = Db::Query('
(select pi.PollItemId from PollItems pi inner join Polls p using (PollId) SELECT pv.*
where p.UrlName = ? from PollVotes pv
) x using (PollItemId) where pv.UserId = ?', [$pollUrlName, $userId], 'PollVote'); inner join
(select pi.PollItemId
from PollItems pi
inner join Polls p using (PollId)
where p.UrlName = ? ) x using (PollItemId)
where pv.UserId = ?
', [$pollUrlName, $userId], 'PollVote');
if(sizeof($result) == 0){ if(sizeof($result) == 0){
throw new Exceptions\InvalidPollVoteException(); throw new Exceptions\InvalidPollVoteException();

View file

@ -36,7 +36,12 @@ class Session extends PropertiesBase{
$this->User = User::GetIfRegistered($email); $this->User = User::GetIfRegistered($email);
$this->UserId = $this->User->UserId; $this->UserId = $this->User->UserId;
$existingSessions = Db::Query('SELECT SessionId, Created from Sessions where UserId = ?', [$this->UserId]); $existingSessions = Db::Query('
SELECT SessionId,
Created
from Sessions
where UserId = ?
', [$this->UserId]);
if(sizeof($existingSessions) > 0){ if(sizeof($existingSessions) > 0){
$this->SessionId = $existingSessions[0]->SessionId; $this->SessionId = $existingSessions[0]->SessionId;
@ -46,7 +51,12 @@ class Session extends PropertiesBase{
$uuid = Uuid::uuid4(); $uuid = Uuid::uuid4();
$this->SessionId = $uuid->toString(); $this->SessionId = $uuid->toString();
$this->Created = new DateTime(); $this->Created = new DateTime();
Db::Query('INSERT into Sessions (UserId, SessionId, Created) values (?, ?, ?)', [$this->UserId, $this->SessionId, $this->Created]); Db::Query('
INSERT into Sessions (UserId, SessionId, Created)
values (?,
?,
?)
', [$this->UserId, $this->SessionId, $this->Created]);
} }
$this->SetSessionCookie($this->SessionId); $this->SetSessionCookie($this->SessionId);
@ -56,7 +66,12 @@ class Session extends PropertiesBase{
$sessionId = HttpInput::Str(COOKIE, 'sessionid'); $sessionId = HttpInput::Str(COOKIE, 'sessionid');
if($sessionId !== null){ if($sessionId !== null){
$result = Db::Query('SELECT u.* from Users u inner join Sessions s using (UserId) where s.SessionId = ?', [$sessionId], 'User'); $result = Db::Query('
SELECT u.*
from Users u
inner join Sessions s using (UserId)
where s.SessionId = ?
', [$sessionId], 'User');
if(sizeof($result) > 0){ if(sizeof($result) > 0){
self::SetSessionCookie($sessionId); self::SetSessionCookie($sessionId);
@ -76,7 +91,11 @@ class Session extends PropertiesBase{
throw new Exceptions\InvalidSessionException(); throw new Exceptions\InvalidSessionException();
} }
$result = Db::Query('SELECT * from Sessions where SessionId = ?', [$sessionId], 'Session'); $result = Db::Query('
SELECT *
from Sessions
where SessionId = ?
', [$sessionId], 'Session');
if(sizeof($result) == 0){ if(sizeof($result) == 0){
throw new Exceptions\InvalidSessionException(); throw new Exceptions\InvalidSessionException();

View file

@ -26,7 +26,12 @@ class User extends PropertiesBase{
*/ */
protected function GetPayments(): array{ protected function GetPayments(): array{
if($this->_Payments === null){ if($this->_Payments === null){
$this->_Payments = Db::Query('select * from Payments where UserId = ? order by Created desc', [$this->UserId], 'Payment'); $this->_Payments = Db::Query('
SELECT *
from Payments
where UserId = ?
order by Created desc
', [$this->UserId], 'Payment');
} }
return $this->_Payments; return $this->_Payments;
@ -34,7 +39,11 @@ class User extends PropertiesBase{
protected function GetBenefits(): Benefits{ protected function GetBenefits(): Benefits{
if($this->_Benefits === null){ if($this->_Benefits === null){
$result = Db::Query('select * from Benefits where UserId = ?', [$this->UserId], 'Benefits'); $result = Db::Query('
SELECT *
from Benefits
where UserId = ?
', [$this->UserId], 'Benefits');
if(sizeof($result) == 0){ if(sizeof($result) == 0){
$this->_Benefits = new Benefits(); $this->_Benefits = new Benefits();
@ -70,7 +79,13 @@ class User extends PropertiesBase{
$this->Created = new DateTime(); $this->Created = new DateTime();
try{ try{
Db::Query('INSERT into Users (Email, Name, Uuid, Created) values (?, ?, ?, ?);', [$this->Email, $this->Name, $this->Uuid, $this->Created]); Db::Query('
INSERT into Users (Email, Name, Uuid, Created)
values (?,
?,
?,
?)
', [$this->Email, $this->Name, $this->Uuid, $this->Created]);
} }
catch(PDOException $ex){ catch(PDOException $ex){
if($ex->errorInfo[1] == 1062){ if($ex->errorInfo[1] == 1062){
@ -91,7 +106,11 @@ class User extends PropertiesBase{
// *********** // ***********
public static function Get(?int $userId): User{ public static function Get(?int $userId): User{
$result = Db::Query('SELECT * from Users where UserId = ?', [$userId], 'User'); $result = Db::Query('
SELECT *
from Users
where UserId = ?
', [$userId], 'User');
if(sizeof($result) == 0){ if(sizeof($result) == 0){
throw new Exceptions\InvalidUserException(); throw new Exceptions\InvalidUserException();
@ -105,7 +124,11 @@ class User extends PropertiesBase{
throw new Exceptions\InvalidUserException(); throw new Exceptions\InvalidUserException();
} }
$result = Db::Query('SELECT * from Users where Email = ?', [$email], 'User'); $result = Db::Query('
SELECT *
from Users
where Email = ?
', [$email], 'User');
if(sizeof($result) == 0){ if(sizeof($result) == 0){
throw new Exceptions\InvalidUserException(); throw new Exceptions\InvalidUserException();
@ -122,7 +145,13 @@ class User extends PropertiesBase{
throw new Exceptions\InvalidUserException(); throw new Exceptions\InvalidUserException();
} }
$result = Db::Query('SELECT u.* from Users u inner join Benefits using (UserId) where u.Email = ? or u.Uuid = ?', [$identifier, $identifier], 'User'); $result = Db::Query('
SELECT u.*
from Users u
inner join Benefits using (UserId)
where u.Email = ?
or u.Uuid = ?
', [$identifier, $identifier], 'User');
if(sizeof($result) == 0){ if(sizeof($result) == 0){
throw new Exceptions\InvalidUserException(); throw new Exceptions\InvalidUserException();

View file

@ -3,5 +3,10 @@
require_once('/standardebooks.org/web/lib/Core.php'); require_once('/standardebooks.org/web/lib/Core.php');
// Delete unconfirmed newsletter subscribers who are more than a week old // Delete unconfirmed newsletter subscribers who are more than a week old
Db::Query('DELETE from NewsletterSubscriptions where IsConfirmed = false and datediff(utc_timestamp(), Created) >= 7'); Db::Query('
DELETE
from NewsletterSubscriptions
where IsConfirmed = false
and datediff(utc_timestamp(), Created) >= 7
');
?> ?>

View file

@ -44,10 +44,19 @@ $faPassword = get_cfg_var('se.secrets.fractured_atlas.password');
// 946554ca-ffc0-4259-bcc6-be6c844fbbdc Regular donation, patrons, private, recurring // 946554ca-ffc0-4259-bcc6-be6c844fbbdc Regular donation, patrons, private, recurring
// 416608c6-cbf5-4153-8956-cb9051bb849e Regular donation, patrons, public, one time, in memory of // 416608c6-cbf5-4153-8956-cb9051bb849e Regular donation, patrons, public, one time, in memory of
$pendingPayments = Db::Query('start transaction; $pendingPayments = Db::Query('
select * from PendingPayments where ProcessedOn is null; start transaction;
update PendingPayments set ProcessedOn = utc_timestamp() where ProcessedOn is null;
commit;'); SELECT *
from PendingPayments
where ProcessedOn is null;
UPDATE PendingPayments
set ProcessedOn = utc_timestamp()
where ProcessedOn is null;
commit;
');
if(sizeof($pendingPayments) == 0){ if(sizeof($pendingPayments) == 0){
// Don't start the very slow Selenium driver if we have nothing to process // Don't start the very slow Selenium driver if we have nothing to process
@ -61,7 +70,11 @@ try{
if($pendingPayment->ChannelId == PAYMENT_CHANNEL_FA){ if($pendingPayment->ChannelId == PAYMENT_CHANNEL_FA){
$log->Write('Processing donation ' . $pendingPayment->TransactionId . ' ...'); $log->Write('Processing donation ' . $pendingPayment->TransactionId . ' ...');
if(Db::QueryInt('SELECT count(*) from Payments where TransactionId = ?', [$pendingPayment->TransactionId]) > 0){ if(Db::QueryInt('
SELECT count(*)
from Payments
where TransactionId = ?
', [$pendingPayment->TransactionId]) > 0){
$log->Write('Donation already exists in database.'); $log->Write('Donation already exists in database.');
continue; continue;
} }
@ -157,7 +170,12 @@ try{
// This payment is eligible for the Patrons Circle! // This payment is eligible for the Patrons Circle!
if($payment->User !== null){ if($payment->User !== null){
// Are we already a patron? // Are we already a patron?
if(Db::QueryInt('SELECT count(*) from Patrons where UserId = ? and Ended is null', [$payment->UserId]) == 0){ if(Db::QueryInt('
SELECT count(*)
from Patrons
where UserId = ?
and Ended is null
', [$payment->UserId]) == 0){
// Not a patron yet, add them to the Patrons Circle // Not a patron yet, add them to the Patrons Circle
$patron = new Patron(); $patron = new Patron();
@ -194,7 +212,12 @@ try{
else{ else{
// Not eligible to be a patron; send a thank you email anyway, but only if this is a non-recurring donation, or if it's their very first recurring donation // Not eligible to be a patron; send a thank you email anyway, but only if this is a non-recurring donation, or if it's their very first recurring donation
if($payment->User !== null){ if($payment->User !== null){
$previousPaymentCount = Db::QueryInt('SELECT count(*) from Payments where UserId = ? and IsRecurring = true', [$payment->UserId]); $previousPaymentCount = Db::QueryInt('
SELECT count(*)
from Payments
where UserId = ?
and IsRecurring = true
', [$payment->UserId]);
// We just added a payment to the system, so if this is their very first recurring payment, we expect the count to be exactly 1 // We just added a payment to the system, so if this is their very first recurring payment, we expect the count to be exactly 1
if(!$payment->IsRecurring || $previousPaymentCount == 1){ if(!$payment->IsRecurring || $previousPaymentCount == 1){
@ -212,7 +235,11 @@ try{
} }
} }
Db::Query('DELETE from PendingPayments where TransactionId = ?;', [$pendingPayment->TransactionId]); Db::Query('
DELETE
from PendingPayments
where TransactionId = ?
', [$pendingPayment->TransactionId]);
$log->Write('Donation processed.'); $log->Write('Donation processed.');
} }

View file

@ -46,12 +46,29 @@ if(sizeof($expiredPatrons) > 0){
} }
foreach($expiredPatrons as $patron){ foreach($expiredPatrons as $patron){
Db::Query('UPDATE Patrons set Ended = ? where UserId = ?', [$now, $patron->UserId]); Db::Query('
Db::Query('UPDATE Benefits set CanAccessFeeds = false, CanVote = false, CanBulkDownload = false where UserId = ?', [$patron->UserId]); UPDATE Patrons
set Ended = ?
where UserId = ?
', [$now, $patron->UserId]);
Db::Query('
UPDATE Benefits
set CanAccessFeeds = false,
CanVote = false,
CanBulkDownload = false
where UserId = ?
', [$patron->UserId]);
// Email the patron to notify them their term has ended // Email the patron to notify them their term has ended
// Is the patron a recurring subscriber? // Is the patron a recurring subscriber?
$lastPayment = Db::Query('SELECT * from Payments where UserId = ? order by Created desc limit 1;', [$patron->UserId], 'Payment'); $lastPayment = Db::Query('
SELECT *
from Payments
where UserId = ?
order by Created desc
limit 1
', [$patron->UserId], 'Payment');
if(sizeof($lastPayment) > 0 && $patron->User->Email !== null){ if(sizeof($lastPayment) > 0 && $patron->User->Email !== null){
$em = new Email(); $em = new Email();

View file

@ -7,38 +7,32 @@ $anonymousPatronCount = 0;
// Get the Patrons Circle and try to sort by last name ascending // Get the Patrons Circle and try to sort by last name ascending
// See <https://mariadb.com/kb/en/pcre/#unicode-character-properties> for Unicode character properties // See <https://mariadb.com/kb/en/pcre/#unicode-character-properties> for Unicode character properties
$patronsCircle = Db::Query('SELECT if(p.AlternateName is not null, p.AlternateName, u.Name) as SortedName $patronsCircle = Db::Query('
from Patrons p inner join Users u SELECT if(p.AlternateName is not null, p.AlternateName, u.Name) as SortedName
using(UserId) from Patrons p
where inner join Users u using(UserId)
p.IsAnonymous = false where p.IsAnonymous = false
and p.Ended is null and p.Ended is null
order by regexp_substr(SortedName, "[\\\p{Lu}][\\\p{L}\-]*$") asc; order by regexp_substr(SortedName, "[\\\p{Lu}][\\\p{L}\-]*$") asc;
'); ');
$anonymousPatronCount = Db::QueryInt('SELECT sum(cnt) $anonymousPatronCount = Db::QueryInt('
from SELECT sum(cnt)
( from (
( ( select count(*) cnt
select count(*) cnt from Payments from Payments
where where UserId is null
UserId is null and ( (IsRecurring = true
and and Amount >= 10
( and Created >= utc_timestamp() - interval 30 day)
(IsRecurring = true and Amount >= 10 and Created >= utc_timestamp() - interval 30 day) or (IsRecurring = false
or and Amount >= 100
(IsRecurring = false and Amount >= 100 and Created >= utc_timestamp() - interval 1 year) and Created >= utc_timestamp() - interval 1 year) ) )
)
)
union all union all
( ( select count(*) as cnt
select count(*) as cnt from Patrons from Patrons
where where IsAnonymous = true
IsAnonymous = true and Ended is null ) ) x
and
Ended is null
)
) x
'); ');
?><?= Template::Header(['title' => 'About Standard Ebooks', 'highlight' => 'about', 'description' => 'Standard Ebooks is a volunteer-driven effort to produce a collection of high quality, carefully formatted, accessible, open source, and free public domain ebooks that meet or exceed the quality of commercially produced ebooks. The text and cover art in our ebooks is already believed to be in the public domain, and Standard Ebook dedicates its own work to the public domain, thus releasing the entirety of each ebook file into the public domain.']) ?> ?><?= Template::Header(['title' => 'About Standard Ebooks', 'highlight' => 'about', 'description' => 'Standard Ebooks is a volunteer-driven effort to produce a collection of high quality, carefully formatted, accessible, open source, and free public domain ebooks that meet or exceed the quality of commercially produced ebooks. The text and cover art in our ebooks is already believed to be in the public domain, and Standard Ebook dedicates its own work to the public domain, thus releasing the entirety of each ebook file into the public domain.']) ?>

View file

@ -1,7 +1,11 @@
<? <?
require_once('Core.php'); require_once('Core.php');
$newsletterSubscriberCount = floor(Db::QueryInt('SELECT count(*) from NewsletterSubscriptions where IsConfirmed = true') / 100) * 100; $newsletterSubscriberCount = floor(Db::QueryInt('
SELECT count(*)
from NewsletterSubscriptions
where IsConfirmed = true
') / 100) * 100;
?><?= Template::Header(['title' => 'Donate', 'highlight' => 'donate', 'description' => 'Donate to Standard Ebooks.']) ?> ?><?= Template::Header(['title' => 'Donate', 'highlight' => 'donate', 'description' => 'Donate to Standard Ebooks.']) ?>
<main> <main>

View file

@ -26,7 +26,12 @@ try{
// Certain user agents may bypass login entirely // Certain user agents may bypass login entirely
$isUserAgentAllowed = false; $isUserAgentAllowed = false;
if(isset($_SERVER['HTTP_USER_AGENT'])){ if(isset($_SERVER['HTTP_USER_AGENT'])){
$isUserAgentAllowed = Db::QueryInt('select count(*) from FeedUserAgents where instr(?, UserAgent) limit 1', [$_SERVER['HTTP_USER_AGENT']]); $isUserAgentAllowed = Db::QueryInt('
SELECT count(*)
from FeedUserAgents
where instr(?, UserAgent)
limit 1
', [$_SERVER['HTTP_USER_AGENT']]);
} }
if(!$isUserAgentAllowed){ if(!$isUserAgentAllowed){

View file

@ -1,9 +1,23 @@
<? <?
require_once('Core.php'); require_once('Core.php');
$pastPolls = Db::Query('select * from Polls where utc_timestamp() >= End order by Created desc', [], 'Poll'); $pastPolls = Db::Query('
SELECT *
from Polls
where utc_timestamp() >= end
order by Created desc
', [], 'Poll');
$openPolls = Db::Query('select * from Polls where (End is null or utc_timestamp() <= End) and (Start is null or Start <= utc_timestamp()) order by Created desc', [], 'Poll'); $openPolls = Db::Query('
SELECT *
from Polls
where (end is null
or utc_timestamp() <= end)
and
(start is null
or start <= utc_timestamp())
order by Created desc
', [], 'Poll');
?><?= Template::Header(['title' => 'Polls', 'highlight' => '', 'description' => 'The various polls active at Standard Ebooks.']) ?> ?><?= Template::Header(['title' => 'Polls', 'highlight' => '', 'description' => 'The various polls active at Standard Ebooks.']) ?>
<main> <main>

View file

@ -36,7 +36,12 @@ try{
// Received when a user marks an email as spam // Received when a user marks an email as spam
$log->Write('Event type: spam complaint.'); $log->Write('Event type: spam complaint.');
Db::Query('DELETE ns.* from NewsletterSubscriptions ns inner join Users u using(UserId) where u.Email = ?', [$post->Email]); Db::Query('
DELETE ns.*
from NewsletterSubscriptions ns
inner join Users u using(UserId)
where u.Email = ?
', [$post->Email]);
} }
elseif($post->RecordType == 'SubscriptionChange' && $post->SuppressSending){ elseif($post->RecordType == 'SubscriptionChange' && $post->SuppressSending){
// Received when a user clicks Postmark's "Unsubscribe" link in a newsletter email // Received when a user clicks Postmark's "Unsubscribe" link in a newsletter email
@ -45,7 +50,12 @@ try{
$email = $post->Recipient; $email = $post->Recipient;
// Remove the email from our newsletter list // Remove the email from our newsletter list
Db::Query('DELETE ns.* from NewsletterSubscriptions ns inner join Users u using(UserId) where u.Email = ?', [$email]); Db::Query('
DELETE ns.*
from NewsletterSubscriptions ns
inner join Users u using(UserId)
where u.Email = ?
', [$email]);
// Remove the suppression from Postmark, since we deleted it from our own list we will never email them again anyway // Remove the suppression from Postmark, since we deleted it from our own list we will never email them again anyway
$handle = curl_init(); $handle = curl_init();

View file

@ -37,7 +37,12 @@ try{
if(sizeof($matches) == 2){ if(sizeof($matches) == 2){
$transactionId = $matches[1]; $transactionId = $matches[1];
Db::Query('INSERT into PendingPayments (Created, ChannelId, TransactionId) values (utc_timestamp(), ?, ?);', [PAYMENT_CHANNEL_FA, $transactionId]); Db::Query('
INSERT into PendingPayments (Created, ChannelId, TransactionId)
values (utc_timestamp(),
?,
?)
', [PAYMENT_CHANNEL_FA, $transactionId]);
$log->Write('Donation ID: ' . $transactionId); $log->Write('Donation ID: ' . $transactionId);
} }