From c8e6524ef23eacda85e6b43ea590e6ae2b408d22 Mon Sep 17 00:00:00 2001 From: Mike Colagrosso Date: Sun, 13 Oct 2024 21:21:28 -0600 Subject: [PATCH] Remove primary key TocEntryId Add a SortOrder column to order the TocEntries instead. --- config/sql/se/TocEntries.sql | 3 +-- lib/Ebook.php | 9 +++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/sql/se/TocEntries.sql b/config/sql/se/TocEntries.sql index 86c1f990..ce7d729b 100644 --- a/config/sql/se/TocEntries.sql +++ b/config/sql/se/TocEntries.sql @@ -1,7 +1,6 @@ CREATE TABLE `TocEntries` ( - `TocEntryId` int(10) unsigned NOT NULL AUTO_INCREMENT, `EbookId` int(10) unsigned NOT NULL, `TocEntry` text NOT NULL, - PRIMARY KEY (`TocEntryId`), + `SortOrder` tinyint(3) unsigned NOT NULL, KEY `index1` (`EbookId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/lib/Ebook.php b/lib/Ebook.php index 78e10066..415107b7 100644 --- a/lib/Ebook.php +++ b/lib/Ebook.php @@ -279,7 +279,7 @@ class Ebook{ SELECT * from TocEntries where EbookId = ? - order by TocEntryId + order by SortOrder asc ', [$this->EbookId], stdClass::class); foreach($result as $row){ @@ -1827,12 +1827,13 @@ class Ebook{ private function AddTocEntries(): void{ if($this->TocEntries !== null){ - foreach($this->TocEntries as $tocEntry){ + foreach($this->TocEntries as $sortOrder => $tocEntry){ Db::Query(' - INSERT into TocEntries (EbookId, TocEntry) + INSERT into TocEntries (EbookId, TocEntry, SortOrder) values (?, + ?, ?) - ', [$this->EbookId, $tocEntry]); + ', [$this->EbookId, $tocEntry, $sortOrder]); } } }