mirror of
https://github.com/standardebooks/web.git
synced 2025-07-17 20:06:39 -04:00
Add check for DuplicateDatabaseKeyException
when inserting into join tables EbookTags, EbookLocSubjects, CollectionEbooks
This commit is contained in:
parent
38860c4729
commit
d0926370be
1 changed files with 32 additions and 17 deletions
|
@ -1692,11 +1692,16 @@ class Ebook{
|
||||||
|
|
||||||
private function AddTags(): void{
|
private function AddTags(): void{
|
||||||
foreach($this->Tags as $tag){
|
foreach($this->Tags as $tag){
|
||||||
Db::Query('
|
try{
|
||||||
INSERT into EbookTags (EbookId, TagId)
|
Db::Query('
|
||||||
values (?,
|
INSERT into EbookTags (EbookId, TagId)
|
||||||
?)
|
values (?,
|
||||||
', [$this->EbookId, $tag->TagId]);
|
?)
|
||||||
|
', [$this->EbookId, $tag->TagId]);
|
||||||
|
}
|
||||||
|
catch(Exceptions\DuplicateDatabaseKeyException){
|
||||||
|
// The Ebook already has the Tag, which is fine.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1710,11 +1715,16 @@ class Ebook{
|
||||||
|
|
||||||
private function AddLocSubjects(): void{
|
private function AddLocSubjects(): void{
|
||||||
foreach($this->LocSubjects as $locSubject){
|
foreach($this->LocSubjects as $locSubject){
|
||||||
Db::Query('
|
try{
|
||||||
INSERT into EbookLocSubjects (EbookId, LocSubjectId)
|
Db::Query('
|
||||||
values (?,
|
INSERT into EbookLocSubjects (EbookId, LocSubjectId)
|
||||||
?)
|
values (?,
|
||||||
', [$this->EbookId, $locSubject->LocSubjectId]);
|
?)
|
||||||
|
', [$this->EbookId, $locSubject->LocSubjectId]);
|
||||||
|
}
|
||||||
|
catch(Exceptions\DuplicateDatabaseKeyException){
|
||||||
|
// The Ebook already has the LocSubject, which is fine.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1731,14 +1741,19 @@ class Ebook{
|
||||||
$collectionMembership->EbookId = $this->EbookId;
|
$collectionMembership->EbookId = $this->EbookId;
|
||||||
$collectionMembership->CollectionId = $collectionMembership->Collection->CollectionId;
|
$collectionMembership->CollectionId = $collectionMembership->Collection->CollectionId;
|
||||||
|
|
||||||
Db::Query('
|
try{
|
||||||
INSERT into CollectionEbooks (EbookId, CollectionId, SequenceNumber)
|
Db::Query('
|
||||||
values (?,
|
INSERT into CollectionEbooks (EbookId, CollectionId, SequenceNumber)
|
||||||
?,
|
values (?,
|
||||||
?)
|
?,
|
||||||
', [$collectionMembership->EbookId, $collectionMembership->CollectionId, $collectionMembership->SequenceNumber]);
|
?)
|
||||||
|
', [$collectionMembership->EbookId, $collectionMembership->CollectionId, $collectionMembership->SequenceNumber]);
|
||||||
|
|
||||||
$collectionMembership->CollectionEbookId = Db::GetLastInsertedId();
|
$collectionMembership->CollectionEbookId = Db::GetLastInsertedId();
|
||||||
|
}
|
||||||
|
catch(Exceptions\DuplicateDatabaseKeyException){
|
||||||
|
// The Ebook is already a member of this Collection.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue