From 2378320d0cf374c77d605fca3b056bfab5358f8d Mon Sep 17 00:00:00 2001 From: Mike Colagrosso Date: Thu, 3 Oct 2024 22:46:53 -0600 Subject: [PATCH] Contributor, EbookSource, GitCommit: Move INSERT statements to Create() methods --- lib/Contributor.php | 19 +++++++++++++++++++ lib/Ebook.php | 40 +++------------------------------------- lib/EbookSource.php | 11 +++++++++++ lib/GitCommit.php | 12 ++++++++++++ 4 files changed, 45 insertions(+), 37 deletions(-) diff --git a/lib/Contributor.php b/lib/Contributor.php index 0a3b0795..2982293b 100644 --- a/lib/Contributor.php +++ b/lib/Contributor.php @@ -22,4 +22,23 @@ class Contributor{ $instance->NacoafUrl = $nacoafUrl; return $instance; } + + public function Create(): void{ + Db::Query(' + INSERT into Contributors (EbookId, Name, UrlName, SortName, WikipediaUrl, MarcRole, FullName, + NacoafUrl, SortOrder) + values (?, + ?, + ?, + ?, + ?, + ?, + ?, + ?, + ?) + ', [$this->EbookId, $this->Name, $this->UrlName, $this->SortName, $this->WikipediaUrl, $this->MarcRole, $this->FullName, + $this->NacoafUrl, $this->SortOrder]); + + $this->ContributorId = Db::GetLastInsertedId(); + } } diff --git a/lib/Ebook.php b/lib/Ebook.php index ec8ea5ca..86a9a666 100644 --- a/lib/Ebook.php +++ b/lib/Ebook.php @@ -1605,16 +1605,7 @@ class Ebook{ private function InsertGitCommits(): void{ foreach($this->GitCommits as $commit){ $commit->EbookId = $this->EbookId; - - Db::Query(' - INSERT into GitCommits (EbookId, Created, Message, Hash) - values (?, - ?, - ?, - ?) - ', [$commit->EbookId, $commit->Created, $commit->Message, $commit->Hash]); - - $commit->GitCommitId = Db::GetLastInsertedId(); + $commit->Create(); } } @@ -1630,15 +1621,7 @@ class Ebook{ private function InsertSources(): void{ foreach($this->Sources as $source){ $source->EbookId = $this->EbookId; - - Db::Query(' - INSERT into EbookSources (EbookId, Type, Url) - values (?, - ?, - ?) - ', [$source->EbookId, $source->Type, $source->Url]); - - $source->EbookSourceId = Db::GetLastInsertedId(); + $source->Create(); } } @@ -1656,24 +1639,7 @@ class Ebook{ foreach($allContributors as $sortOrder => $contributor){ $contributor->EbookId = $this->EbookId; $contributor->SortOrder = $sortOrder; - - Db::Query(' - INSERT into Contributors (EbookId, Name, UrlName, SortName, WikipediaUrl, MarcRole, FullName, - NacoafUrl, SortOrder) - values (?, - ?, - ?, - ?, - ?, - ?, - ?, - ?, - ?) - ', [$contributor->EbookId, $contributor->Name, $contributor->UrlName, $contributor->SortName, - $contributor->WikipediaUrl, $contributor->MarcRole, $contributor->FullName, - $contributor->NacoafUrl, $contributor->SortOrder]); - - $contributor->ContributorId = Db::GetLastInsertedId(); + $contributor->Create(); } } diff --git a/lib/EbookSource.php b/lib/EbookSource.php index 96ab6f5a..4ab4dcb4 100644 --- a/lib/EbookSource.php +++ b/lib/EbookSource.php @@ -11,4 +11,15 @@ class EbookSource{ $instance->Url = $url; return $instance; } + + public function Create(): void{ + Db::Query(' + INSERT into EbookSources (EbookId, Type, Url) + values (?, + ?, + ?) + ', [$this->EbookId, $this->Type, $this->Url]); + + $this->EbookSourceId = Db::GetLastInsertedId(); + } } diff --git a/lib/GitCommit.php b/lib/GitCommit.php index 20fc9759..3df150df 100644 --- a/lib/GitCommit.php +++ b/lib/GitCommit.php @@ -23,4 +23,16 @@ class GitCommit{ $instance->Hash = $hash; return $instance; } + + public function Create(): void{ + Db::Query(' + INSERT into GitCommits (EbookId, Created, Message, Hash) + values (?, + ?, + ?, + ?) + ', [$this->EbookId, $this->Created, $this->Message, $this->Hash]); + + $this->GitCommitId = Db::GetLastInsertedId(); + } }