mirror of
https://github.com/standardebooks/web.git
synced 2025-07-14 18:42:00 -04:00
Fix exception for duplicate ebook placeholder on save
This commit is contained in:
parent
d9fe3e9303
commit
94d62fdcdf
2 changed files with 47 additions and 36 deletions
|
@ -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{
|
||||
$this->Validate();
|
||||
|
@ -1932,40 +1933,45 @@ final class Ebook{
|
|||
throw $error;
|
||||
}
|
||||
|
||||
Db::Query('
|
||||
UPDATE Ebooks
|
||||
set
|
||||
Identifier = ?,
|
||||
WwwFilesystemPath = ?,
|
||||
RepoFilesystemPath = ?,
|
||||
KindleCoverUrl = ?,
|
||||
EpubUrl = ?,
|
||||
AdvancedEpubUrl = ?,
|
||||
KepubUrl = ?,
|
||||
Azw3Url = ?,
|
||||
DistCoverUrl = ?,
|
||||
Title = ?,
|
||||
FullTitle = ?,
|
||||
AlternateTitle = ?,
|
||||
Description = ?,
|
||||
LongDescription = ?,
|
||||
Language = ?,
|
||||
WordCount = ?,
|
||||
ReadingEase = ?,
|
||||
GitHubUrl = ?,
|
||||
WikipediaUrl = ?,
|
||||
EbookCreated = ?,
|
||||
EbookUpdated = ?,
|
||||
TextSinglePageByteCount = ?,
|
||||
IndexableText = ?
|
||||
where
|
||||
EbookId = ?
|
||||
', [$this->Identifier, $this->WwwFilesystemPath, $this->RepoFilesystemPath, $this->KindleCoverUrl, $this->EpubUrl,
|
||||
$this->AdvancedEpubUrl, $this->KepubUrl, $this->Azw3Url, $this->DistCoverUrl, $this->Title,
|
||||
$this->FullTitle, $this->AlternateTitle, $this->Description, $this->LongDescription,
|
||||
$this->Language, $this->WordCount, $this->ReadingEase, $this->GitHubUrl, $this->WikipediaUrl,
|
||||
$this->EbookCreated, $this->EbookUpdated, $this->TextSinglePageByteCount, $this->IndexableText,
|
||||
$this->EbookId]);
|
||||
try{
|
||||
Db::Query('
|
||||
UPDATE Ebooks
|
||||
set
|
||||
Identifier = ?,
|
||||
WwwFilesystemPath = ?,
|
||||
RepoFilesystemPath = ?,
|
||||
KindleCoverUrl = ?,
|
||||
EpubUrl = ?,
|
||||
AdvancedEpubUrl = ?,
|
||||
KepubUrl = ?,
|
||||
Azw3Url = ?,
|
||||
DistCoverUrl = ?,
|
||||
Title = ?,
|
||||
FullTitle = ?,
|
||||
AlternateTitle = ?,
|
||||
Description = ?,
|
||||
LongDescription = ?,
|
||||
Language = ?,
|
||||
WordCount = ?,
|
||||
ReadingEase = ?,
|
||||
GitHubUrl = ?,
|
||||
WikipediaUrl = ?,
|
||||
EbookCreated = ?,
|
||||
EbookUpdated = ?,
|
||||
TextSinglePageByteCount = ?,
|
||||
IndexableText = ?
|
||||
where
|
||||
EbookId = ?
|
||||
', [$this->Identifier, $this->WwwFilesystemPath, $this->RepoFilesystemPath, $this->KindleCoverUrl, $this->EpubUrl,
|
||||
$this->AdvancedEpubUrl, $this->KepubUrl, $this->Azw3Url, $this->DistCoverUrl, $this->Title,
|
||||
$this->FullTitle, $this->AlternateTitle, $this->Description, $this->LongDescription,
|
||||
$this->Language, $this->WordCount, $this->ReadingEase, $this->GitHubUrl, $this->WikipediaUrl,
|
||||
$this->EbookCreated, $this->EbookUpdated, $this->TextSinglePageByteCount, $this->IndexableText,
|
||||
$this->EbookId]);
|
||||
}
|
||||
catch(Exceptions\DuplicateDatabaseKeyException){
|
||||
throw new Exceptions\DuplicateEbookException($this->Identifier);
|
||||
}
|
||||
|
||||
|
||||
try{
|
||||
|
|
|
@ -69,7 +69,12 @@ try{
|
|||
$ebook->EbookId = $originalEbook->EbookId;
|
||||
$ebook->Created = $originalEbook->Created;
|
||||
|
||||
$ebook->Save();
|
||||
try{
|
||||
$ebook->Save();
|
||||
}
|
||||
catch(Exceptions\DuplicateEbookException){
|
||||
throw new Exceptions\EbookPlaceholderExistsException();
|
||||
}
|
||||
|
||||
$_SESSION['is-ebook-placeholder-saved'] = true;
|
||||
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue