mirror of
https://github.com/standardebooks/web.git
synced 2025-07-15 19:06:49 -04:00
Use a NOW constant instead of new DateTimeImmutable objects, and tweak how some donation drive dates work
This commit is contained in:
parent
376dacd833
commit
eec79712fc
27 changed files with 108 additions and 143 deletions
|
@ -114,15 +114,13 @@ usort($allEbooks, 'SortByUpdatedDesc');
|
|||
usort($newestEbooks, function($a, $b){ return $b->Created <=> $a->Created; });
|
||||
$newestEbooks = array_slice($newestEbooks, 0, $ebooksPerNewestEbooksFeed);
|
||||
|
||||
$now = new DateTimeImmutable();
|
||||
|
||||
// Create OPDS feeds.
|
||||
$opdsRootEntries = [
|
||||
new OpdsNavigationEntry(
|
||||
'Newest Standard Ebooks',
|
||||
'The ' . number_format($ebooksPerNewestEbooksFeed) . ' latest Standard Ebooks, most-recently-released first.',
|
||||
'/feeds/opds/new-releases',
|
||||
$now,
|
||||
NOW,
|
||||
'http://opds-spec.org/sort/new',
|
||||
'acquisition'
|
||||
),
|
||||
|
@ -130,51 +128,51 @@ $opdsRootEntries = [
|
|||
'Standard Ebooks by Subject',
|
||||
'Browse Standard Ebooks by subject.',
|
||||
'/feeds/opds/subjects',
|
||||
$now,
|
||||
NOW,
|
||||
'subsection',
|
||||
'navigation'),
|
||||
new OpdsNavigationEntry(
|
||||
'Standard Ebooks by Collection',
|
||||
'Browse Standard Ebooks by collection.',
|
||||
'/feeds/opds/collections',
|
||||
$now,
|
||||
NOW,
|
||||
'subsection',
|
||||
'navigation'),
|
||||
new OpdsNavigationEntry(
|
||||
'Standard Ebooks by Author',
|
||||
'Browse Standard Ebooks by author.',
|
||||
'/feeds/opds/authors',
|
||||
$now,
|
||||
NOW,
|
||||
'subsection',
|
||||
'navigation'),
|
||||
new OpdsNavigationEntry(
|
||||
'All Standard Ebooks',
|
||||
'All Standard Ebooks, most-recently-updated first. This is a Complete Acquisition Feed as defined in OPDS 1.2 §2.5.',
|
||||
'/feeds/opds/all',
|
||||
$now,
|
||||
NOW,
|
||||
'http://opds-spec.org/crawlable',
|
||||
'acquisition')
|
||||
];
|
||||
|
||||
$opdsRoot = new OpdsNavigationFeed('Standard Ebooks', 'The Standard Ebooks catalog.', '/feeds/opds', $webRoot . '/feeds/opds/index.xml', $opdsRootEntries, null);
|
||||
SaveFeed($opdsRoot, $force, null, null, $now);
|
||||
SaveFeed($opdsRoot, $force, null, null, NOW);
|
||||
|
||||
// Create the Subjects feeds.
|
||||
CreateOpdsCollectionFeed('subject', '/feeds/opds/subjects', 'Standard Ebooks in the “%s” subject, most-recently-released first.', $subjects, $ebooksBySubject, $now, $webRoot, $opdsRoot, $force);
|
||||
CreateOpdsCollectionFeed('subject', '/feeds/opds/subjects', 'Standard Ebooks in the “%s” subject, most-recently-released first.', $subjects, $ebooksBySubject, NOW, $webRoot, $opdsRoot, $force);
|
||||
|
||||
// Create the Collections feeds.
|
||||
CreateOpdsCollectionFeed('collection', '/feeds/opds/collections', 'Standard Ebooks in the “%s” collection, most-recently-released first.', $collections, $ebooksByCollection, $now, $webRoot, $opdsRoot, $force);
|
||||
CreateOpdsCollectionFeed('collection', '/feeds/opds/collections', 'Standard Ebooks in the “%s” collection, most-recently-released first.', $collections, $ebooksByCollection, NOW, $webRoot, $opdsRoot, $force);
|
||||
|
||||
// Create the Author feeds.
|
||||
CreateOpdsCollectionFeed('author', '/feeds/opds/authors', 'Standard Ebooks by %s, most-recently-released first.', $authors, $ebooksByAuthor, $now, $webRoot, $opdsRoot, $force);
|
||||
CreateOpdsCollectionFeed('author', '/feeds/opds/authors', 'Standard Ebooks by %s, most-recently-released first.', $authors, $ebooksByAuthor, NOW, $webRoot, $opdsRoot, $force);
|
||||
|
||||
// Create the All feed.
|
||||
$allFeed = new OpdsAcquisitionFeed('All Standard Ebooks', 'All Standard Ebooks, most-recently-updated first. This is a Complete Acquisition Feed as defined in OPDS 1.2 §2.5.', '/feeds/opds/all', $webRoot . '/feeds/opds/all.xml', $allEbooks, $opdsRoot, true);
|
||||
SaveFeed($allFeed, $force, null, null, $now);
|
||||
SaveFeed($allFeed, $force, null, null, NOW);
|
||||
|
||||
// Create the Newest feed.
|
||||
$newestFeed = new OpdsAcquisitionFeed('Newest Standard Ebooks', 'The ' . number_format($ebooksPerNewestEbooksFeed) . ' latest Standard Ebooks, most-recently-released first.', '/feeds/opds/new-releases', $webRoot . '/feeds/opds/new-releases.xml', $newestEbooks, $opdsRoot);
|
||||
SaveFeed($newestFeed, $force, null, null, $now);
|
||||
SaveFeed($newestFeed, $force, null, null, NOW);
|
||||
|
||||
|
||||
|
||||
|
@ -190,11 +188,11 @@ SaveFeed($newestRssFeed, $force, null, null);
|
|||
|
||||
// Create the Atom All feed.
|
||||
$allAtomFeed = new AtomFeed('Standard Ebooks - All Ebooks', 'All Standard Ebooks, most-recently-released first.', '/feeds/atom/all', $webRoot . '/feeds/atom/all.xml', $allEbooks);
|
||||
SaveFeed($allAtomFeed, $force, null, null, $now);
|
||||
SaveFeed($allAtomFeed, $force, null, null, NOW);
|
||||
|
||||
// Create the Atom Newest feed.
|
||||
$newestAtomFeed = new AtomFeed('Standard Ebooks - Newest Ebooks', 'The ' . number_format($ebooksPerNewestEbooksFeed) . ' latest Standard Ebooks, most-recently-released first.', '/feeds/atom/new-releases', $webRoot . '/feeds/atom/new-releases.xml', $newestEbooks);
|
||||
SaveFeed($newestAtomFeed, $force, null, null, $now);
|
||||
SaveFeed($newestAtomFeed, $force, null, null, NOW);
|
||||
|
||||
// Generate each individual subject feed.
|
||||
foreach($ebooksBySubject as $subject => $ebooks){
|
||||
|
@ -207,7 +205,7 @@ foreach($ebooksBySubject as $subject => $ebooks){
|
|||
SaveFeed($subjectRssFeed, $force, $subjects[$subject]['name'], $subjects[$subject]['sortedname']);
|
||||
|
||||
$subjectAtomFeed = new AtomFeed($title, $subtitle, '/feeds/atom/subjects/' . Formatter::MakeUrlSafe($subject), $webRoot . '/feeds/atom/subjects/' . Formatter::MakeUrlSafe($subject) . '.xml', $ebooks);
|
||||
SaveFeed($subjectAtomFeed, $force, $subjects[$subject]['name'], $subjects[$subject]['sortedname'], $now);
|
||||
SaveFeed($subjectAtomFeed, $force, $subjects[$subject]['name'], $subjects[$subject]['sortedname'], NOW);
|
||||
}
|
||||
|
||||
// Generate each individual collection feed.
|
||||
|
@ -223,7 +221,7 @@ foreach($ebooksByCollection as $collection => $ebooks){
|
|||
SaveFeed($collectionRssFeed, $force, $collections[$collection]['name'], $collections[$collection]['sortedname']);
|
||||
|
||||
$collectionAtomFeed = new AtomFeed($title, $subtitle, '/feeds/atom/collections/' . Formatter::MakeUrlSafe($collection), $webRoot . '/feeds/atom/collections/' . Formatter::MakeUrlSafe($collection) . '.xml', $ebooks);
|
||||
SaveFeed($collectionAtomFeed, $force, $collections[$collection]['name'], $collections[$collection]['sortedname'], $now);
|
||||
SaveFeed($collectionAtomFeed, $force, $collections[$collection]['name'], $collections[$collection]['sortedname'], NOW);
|
||||
}
|
||||
|
||||
// Generate each individual author feed.
|
||||
|
@ -237,7 +235,7 @@ foreach($ebooksByAuthor as $collection => $ebooks){
|
|||
SaveFeed($collectionRssFeed, $force, $authors[$collection]['name'], $authors[$collection]['sortedname']);
|
||||
|
||||
$collectionAtomFeed = new AtomFeed($title, $subtitle, '/feeds/atom/authors/' . $authors[$collection]['id'], $webRoot . '/feeds/atom/authors/' . $authors[$collection]['id'] . '.xml', $ebooks);
|
||||
SaveFeed($collectionAtomFeed, $force, $authors[$collection]['name'], $authors[$collection]['sortedname'], $now);
|
||||
SaveFeed($collectionAtomFeed, $force, $authors[$collection]['name'], $authors[$collection]['sortedname'], NOW);
|
||||
}
|
||||
|
||||
// Set ownership and permissions.
|
||||
|
|
|
@ -46,8 +46,7 @@ $lastSeenTransactionId = null;
|
|||
$firstTransactionId = null;
|
||||
$transactionFilePath = '/tmp/last-fa-donation';
|
||||
$transactionIds = [];
|
||||
$now = new DateTimeImmutable();
|
||||
$today = $now->format('n/j/Y');
|
||||
$today = NOW->format('n/j/Y');
|
||||
$faItemsPerPage = 20; // How many items are on a full page of FA results?
|
||||
|
||||
// General plan: Read /tmp/last-fa-donation to see what the last transaction ID was that we processed.
|
||||
|
@ -94,7 +93,7 @@ try{
|
|||
}
|
||||
|
||||
if($lastSeenTransactionId === null){
|
||||
$log->Write('No last transaction ID, checking everything from ' . $now->format('Y-m-d'));
|
||||
$log->Write('No last transaction ID, checking everything from ' . NOW->format('Y-m-d'));
|
||||
}
|
||||
else{
|
||||
$log->Write('Checking from last transaction ID ' . $lastSeenTransactionId);
|
||||
|
|
|
@ -11,7 +11,6 @@ use function Safe\shell_exec;
|
|||
// Get a list of payments that are within 1 year / 45 days of today, and deactivate Patrons Circle members who aren't in that list.
|
||||
// We give a 15 day grace period to Patrons Circle members because sometimes FA can be delayed in charging.
|
||||
|
||||
$now = new DateTimeImmutable();
|
||||
$lastYear = new DateTimeImmutable('-1 year');
|
||||
|
||||
$expiredPatrons = Db::Query('
|
||||
|
@ -29,7 +28,7 @@ $expiredPatrons = Db::Query('
|
|||
(IsRecurring = false and Amount >= 100 and Created > ? - interval 1 year)
|
||||
)
|
||||
)
|
||||
', [$now, $now], Patron::class);
|
||||
', [NOW, NOW], Patron::class);
|
||||
|
||||
if(sizeof($expiredPatrons) > 0){
|
||||
$ebooksThisYear = 0;
|
||||
|
@ -54,7 +53,7 @@ if(sizeof($expiredPatrons) > 0){
|
|||
UPDATE Patrons
|
||||
set Ended = ?
|
||||
where UserId = ?
|
||||
', [$now, $patron->UserId]);
|
||||
', [NOW, $patron->UserId]);
|
||||
|
||||
Db::Query('
|
||||
UPDATE Benefits
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue