Fix exception for duplicate ebook placeholder on save

This commit is contained in:
Alex Cabal 2025-01-09 14:07:40 -06:00
parent d9fe3e9303
commit 94d62fdcdf
2 changed files with 47 additions and 36 deletions

View file

@ -1916,7 +1916,8 @@ final class Ebook{
} }
/** /**
* @throws Exceptions\InvalidEbookException * @throws Exceptions\InvalidEbookException If the `Ebook` is invalid.
* @throws Exceptions\DuplicateEbookException If an `Ebook` with the same title and author already exists.
*/ */
public function Save(): void{ public function Save(): void{
$this->Validate(); $this->Validate();
@ -1932,40 +1933,45 @@ final class Ebook{
throw $error; throw $error;
} }
Db::Query(' try{
UPDATE Ebooks Db::Query('
set UPDATE Ebooks
Identifier = ?, set
WwwFilesystemPath = ?, Identifier = ?,
RepoFilesystemPath = ?, WwwFilesystemPath = ?,
KindleCoverUrl = ?, RepoFilesystemPath = ?,
EpubUrl = ?, KindleCoverUrl = ?,
AdvancedEpubUrl = ?, EpubUrl = ?,
KepubUrl = ?, AdvancedEpubUrl = ?,
Azw3Url = ?, KepubUrl = ?,
DistCoverUrl = ?, Azw3Url = ?,
Title = ?, DistCoverUrl = ?,
FullTitle = ?, Title = ?,
AlternateTitle = ?, FullTitle = ?,
Description = ?, AlternateTitle = ?,
LongDescription = ?, Description = ?,
Language = ?, LongDescription = ?,
WordCount = ?, Language = ?,
ReadingEase = ?, WordCount = ?,
GitHubUrl = ?, ReadingEase = ?,
WikipediaUrl = ?, GitHubUrl = ?,
EbookCreated = ?, WikipediaUrl = ?,
EbookUpdated = ?, EbookCreated = ?,
TextSinglePageByteCount = ?, EbookUpdated = ?,
IndexableText = ? TextSinglePageByteCount = ?,
where IndexableText = ?
EbookId = ? where
', [$this->Identifier, $this->WwwFilesystemPath, $this->RepoFilesystemPath, $this->KindleCoverUrl, $this->EpubUrl, EbookId = ?
$this->AdvancedEpubUrl, $this->KepubUrl, $this->Azw3Url, $this->DistCoverUrl, $this->Title, ', [$this->Identifier, $this->WwwFilesystemPath, $this->RepoFilesystemPath, $this->KindleCoverUrl, $this->EpubUrl,
$this->FullTitle, $this->AlternateTitle, $this->Description, $this->LongDescription, $this->AdvancedEpubUrl, $this->KepubUrl, $this->Azw3Url, $this->DistCoverUrl, $this->Title,
$this->Language, $this->WordCount, $this->ReadingEase, $this->GitHubUrl, $this->WikipediaUrl, $this->FullTitle, $this->AlternateTitle, $this->Description, $this->LongDescription,
$this->EbookCreated, $this->EbookUpdated, $this->TextSinglePageByteCount, $this->IndexableText, $this->Language, $this->WordCount, $this->ReadingEase, $this->GitHubUrl, $this->WikipediaUrl,
$this->EbookId]); $this->EbookCreated, $this->EbookUpdated, $this->TextSinglePageByteCount, $this->IndexableText,
$this->EbookId]);
}
catch(Exceptions\DuplicateDatabaseKeyException){
throw new Exceptions\DuplicateEbookException($this->Identifier);
}
try{ try{

View file

@ -69,7 +69,12 @@ try{
$ebook->EbookId = $originalEbook->EbookId; $ebook->EbookId = $originalEbook->EbookId;
$ebook->Created = $originalEbook->Created; $ebook->Created = $originalEbook->Created;
$ebook->Save(); try{
$ebook->Save();
}
catch(Exceptions\DuplicateEbookException){
throw new Exceptions\EbookPlaceholderExistsException();
}
$_SESSION['is-ebook-placeholder-saved'] = true; $_SESSION['is-ebook-placeholder-saved'] = true;
http_response_code(Enums\HttpCode::SeeOther->value); http_response_code(Enums\HttpCode::SeeOther->value);