mirror of
https://github.com/standardebooks/web.git
synced 2025-07-07 15:20:32 -04:00
Remove primary key EbookLocSubjectId
Add a SortOrder column to keep the LocSubjects in the same order as given in content.opf.
This commit is contained in:
parent
cada95383f
commit
b4b6fde778
2 changed files with 6 additions and 6 deletions
|
@ -1,7 +1,6 @@
|
|||
CREATE TABLE `EbookLocSubjects` (
|
||||
`EbookLocSubjectId` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`EbookId` int(10) unsigned NOT NULL,
|
||||
`LocSubjectId` int(10) unsigned NOT NULL,
|
||||
PRIMARY KEY (`EbookLocSubjectId`),
|
||||
`SortOrder` tinyint(3) unsigned NOT NULL,
|
||||
UNIQUE KEY `idxUnique` (`EbookId`,`LocSubjectId`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
|
|
@ -161,7 +161,7 @@ class Ebook{
|
|||
from LocSubjects l
|
||||
inner join EbookLocSubjects el using (LocSubjectId)
|
||||
where EbookId = ?
|
||||
order by el.EbookLocSubjectId
|
||||
order by SortOrder asc
|
||||
', [$this->EbookId], LocSubject::class);
|
||||
}
|
||||
|
||||
|
@ -1714,13 +1714,14 @@ class Ebook{
|
|||
}
|
||||
|
||||
private function AddLocSubjects(): void{
|
||||
foreach($this->LocSubjects as $locSubject){
|
||||
foreach($this->LocSubjects as $sortOrder => $locSubject){
|
||||
try{
|
||||
Db::Query('
|
||||
INSERT into EbookLocSubjects (EbookId, LocSubjectId)
|
||||
INSERT into EbookLocSubjects (EbookId, LocSubjectId, SortOrder)
|
||||
values (?,
|
||||
?,
|
||||
?)
|
||||
', [$this->EbookId, $locSubject->LocSubjectId]);
|
||||
', [$this->EbookId, $locSubject->LocSubjectId, $sortOrder]);
|
||||
}
|
||||
catch(Exceptions\DuplicateDatabaseKeyException){
|
||||
// The Ebook already has the LocSubject, which is fine.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue