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{
|
public function Save(): void{
|
||||||
$this->Validate();
|
$this->Validate();
|
||||||
|
@ -1932,6 +1933,7 @@ final class Ebook{
|
||||||
throw $error;
|
throw $error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try{
|
||||||
Db::Query('
|
Db::Query('
|
||||||
UPDATE Ebooks
|
UPDATE Ebooks
|
||||||
set
|
set
|
||||||
|
@ -1966,6 +1968,10 @@ final class Ebook{
|
||||||
$this->Language, $this->WordCount, $this->ReadingEase, $this->GitHubUrl, $this->WikipediaUrl,
|
$this->Language, $this->WordCount, $this->ReadingEase, $this->GitHubUrl, $this->WikipediaUrl,
|
||||||
$this->EbookCreated, $this->EbookUpdated, $this->TextSinglePageByteCount, $this->IndexableText,
|
$this->EbookCreated, $this->EbookUpdated, $this->TextSinglePageByteCount, $this->IndexableText,
|
||||||
$this->EbookId]);
|
$this->EbookId]);
|
||||||
|
}
|
||||||
|
catch(Exceptions\DuplicateDatabaseKeyException){
|
||||||
|
throw new Exceptions\DuplicateEbookException($this->Identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
|
@ -69,7 +69,12 @@ try{
|
||||||
$ebook->EbookId = $originalEbook->EbookId;
|
$ebook->EbookId = $originalEbook->EbookId;
|
||||||
$ebook->Created = $originalEbook->Created;
|
$ebook->Created = $originalEbook->Created;
|
||||||
|
|
||||||
|
try{
|
||||||
$ebook->Save();
|
$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);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue