From f605a4df60803343e4fb50d99ac1cdd66bf7f37b Mon Sep 17 00:00:00 2001 From: Mike Colagrosso Date: Mon, 20 May 2024 22:23:38 -0600 Subject: [PATCH] Rename `Created` and `Updated` in PHP code to `EbookCreated` and `EbookUpdated` to match the schema --- lib/AtomFeed.php | 2 +- lib/Ebook.php | 20 ++++++++++---------- lib/Library.php | 4 ++-- scripts/generate-bulk-downloads | 4 ++-- scripts/generate-feeds | 4 ++-- www/ebooks/ebook.php | 4 ++-- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/AtomFeed.php b/lib/AtomFeed.php index 1762f44f..fb4520e0 100644 --- a/lib/AtomFeed.php +++ b/lib/AtomFeed.php @@ -56,7 +56,7 @@ class AtomFeed extends Feed{ foreach($this->Entries as $entry){ $obj = new StdClass(); if($entry instanceof Ebook){ - $obj->Updated = $entry->Updated->format('Y-m-d\TH:i:s\Z'); + $obj->Updated = $entry->EbookUpdated->format('Y-m-d\TH:i:s\Z'); $obj->Id = SITE_URL . $entry->Url; } else{ diff --git a/lib/Ebook.php b/lib/Ebook.php index 3845f624..c5795418 100644 --- a/lib/Ebook.php +++ b/lib/Ebook.php @@ -82,12 +82,12 @@ class Ebook{ public $Contributors = []; public ?string $ContributorsHtml = null; public string $TitleWithCreditsHtml = ''; - public DateTimeImmutable $Created; - public DateTimeImmutable $Updated; public ?string $TextUrl; public ?string $TextSinglePageUrl; public ?string $TextSinglePageSizeNumber = null; public ?string $TextSinglePageSizeUnit = null; + public DateTimeImmutable $EbookCreated; + public DateTimeImmutable $EbookUpdated; public ?int $TextSinglePageByteCount = null; /** @var ?array $TocEntries */ public $TocEntries = null; // A list of non-Roman ToC entries ONLY IF the work has the 'se:is-a-collection' metadata element, null otherwise @@ -296,13 +296,13 @@ class Ebook{ $date = $xml->xpath('/package/metadata/dc:date') ?: []; if($date !== false && sizeof($date) > 0){ /** @throws void */ - $this->Created = new DateTimeImmutable((string)$date[0]); + $this->EbookCreated = new DateTimeImmutable((string)$date[0]); } $modifiedDate = $xml->xpath('/package/metadata/meta[@property="dcterms:modified"]') ?: []; if($modifiedDate !== false && sizeof($modifiedDate) > 0){ /** @throws void */ - $this->Updated = new DateTimeImmutable((string)$modifiedDate[0]); + $this->EbookUpdated = new DateTimeImmutable((string)$modifiedDate[0]); } // Get SE tags @@ -722,12 +722,12 @@ class Ebook{ $error->Add(new Exceptions\StringTooLongException('Ebook WikipediaUrl')); } - if($this->Created > $now || $this->Created < EBOOK_EARLIEST_CREATION_DATE){ - $error->Add(new Exceptions\InvalidEbookCreatedDatetimeException($this->Created)); + if($this->EbookCreated > $now || $this->EbookCreated < EBOOK_EARLIEST_CREATION_DATE){ + $error->Add(new Exceptions\InvalidEbookCreatedDatetimeException($this->EbookCreated)); } - if($this->Updated > $now || $this->Updated < EBOOK_EARLIEST_CREATION_DATE){ - $error->Add(new Exceptions\InvalidEbookUpdatedDatetimeException($this->Updated)); + if($this->EbookUpdated > $now || $this->EbookUpdated < EBOOK_EARLIEST_CREATION_DATE){ + $error->Add(new Exceptions\InvalidEbookUpdatedDatetimeException($this->EbookUpdated)); } @@ -1144,7 +1144,7 @@ class Ebook{ $this->AdvancedEpubUrl, $this->KepubUrl, $this->Azw3Url, $this->DistCoverUrl, $this->Title, $this->FullTitle, $this->AlternateTitle, $this->Description, $this->LongDescription, $this->Language, $this->WordCount, $this->ReadingEase, $this->GitHubUrl, $this->WikipediaUrl, - $this->Created, $this->Updated, $this->TextSinglePageByteCount, $this->IndexableText]); + $this->EbookCreated, $this->EbookUpdated, $this->TextSinglePageByteCount, $this->IndexableText]); $this->EbookId = Db::GetLastInsertedId(); @@ -1198,7 +1198,7 @@ class Ebook{ $this->AdvancedEpubUrl, $this->KepubUrl, $this->Azw3Url, $this->DistCoverUrl, $this->Title, $this->FullTitle, $this->AlternateTitle, $this->Description, $this->LongDescription, $this->Language, $this->WordCount, $this->ReadingEase, $this->GitHubUrl, $this->WikipediaUrl, - $this->Created, $this->Updated, $this->TextSinglePageByteCount, $this->IndexableText, + $this->EbookCreated, $this->EbookUpdated, $this->TextSinglePageByteCount, $this->IndexableText, $this->EbookId]); $this->DeleteTags(); diff --git a/lib/Library.php b/lib/Library.php index 281ffb3f..fe32b248 100644 --- a/lib/Library.php +++ b/lib/Library.php @@ -59,10 +59,10 @@ class Library{ case EbookSortType::Newest: usort($matches, function($a, $b){ - if($a->Created < $b->Created){ + if($a->EbookCreated < $b->EbookCreated){ return -1; } - elseif($a->Created == $b->Created){ + elseif($a->EbookCreated == $b->EbookCreated){ return 0; } else{ diff --git a/scripts/generate-bulk-downloads b/scripts/generate-bulk-downloads index 535aecdd..077c8936 100755 --- a/scripts/generate-bulk-downloads +++ b/scripts/generate-bulk-downloads @@ -105,8 +105,8 @@ function CreateZip(string $filePath, array $ebooks, string $type, string $webRoo // Iterate over all ebooks and arrange them by publication month foreach(Library::GetEbooksFromFilesystem($webRoot) as $ebook){ - $timestamp = $ebook->Created->format('Y-m'); - $updatedTimestamp = $ebook->Updated->getTimestamp(); + $timestamp = $ebook->EbookCreated->format('Y-m'); + $updatedTimestamp = $ebook->EbookUpdated->getTimestamp(); // Add to the 'ebooks by month' list if(!isset($ebooksByGroup['months'][$timestamp])){ diff --git a/scripts/generate-feeds b/scripts/generate-feeds index c7a583b0..482d8aee 100755 --- a/scripts/generate-feeds +++ b/scripts/generate-feeds @@ -10,7 +10,7 @@ use function Safe\mkdir; use function Safe\preg_replace; function SortByUpdatedDesc(Ebook $a, Ebook $b): int{ - return $b->Updated <=> $a->Updated; + return $b->EbookUpdated <=> $a->EbookUpdated; } function SaveFeed(Feed $feed, bool $force, ?string $label = null, ?string $labelSort = null, DateTimeImmutable $now = null): void{ @@ -111,7 +111,7 @@ foreach(Library::GetEbooksFromFilesystem($webRoot) as $ebook){ } usort($allEbooks, 'SortByUpdatedDesc'); -usort($newestEbooks, function($a, $b){ return $b->Created <=> $a->Created; }); +usort($newestEbooks, function($a, $b){ return $b->EbookCreated <=> $a->EbookCreated; }); $newestEbooks = array_slice($newestEbooks, 0, $ebooksPerNewestEbooksFeed); // Create OPDS feeds. diff --git a/www/ebooks/ebook.php b/www/ebooks/ebook.php index 361955e1..7aedb904 100644 --- a/www/ebooks/ebook.php +++ b/www/ebooks/ebook.php @@ -198,8 +198,8 @@ catch(Exceptions\EbookNotFoundException){ - - + +