diff --git a/lib/Exceptions/EbookPlaceholderExistsException.php b/lib/Exceptions/EbookPlaceholderExistsException.php new file mode 100644 index 00000000..c72bf838 --- /dev/null +++ b/lib/Exceptions/EbookPlaceholderExistsException.php @@ -0,0 +1,7 @@ +MessageType == Enums\ExceptionMessageType::Text){ + if(!($ex instanceof Exceptions\AppException) || $ex->MessageType == Enums\ExceptionMessageType::Text){ $message = '

' . str_replace('CAPTCHA', 'CAPTCHA', Formatter::EscapeHtml($message)) . '

'; } ?> diff --git a/www/ebook-placeholders/post.php b/www/ebook-placeholders/post.php index 7f9da5ca..a45a01ec 100644 --- a/www/ebook-placeholders/post.php +++ b/www/ebook-placeholders/post.php @@ -35,17 +35,14 @@ try{ $ebook->Create(); } catch(Exceptions\DuplicateEbookException $ex){ - // If the identifier already exists but a `Project` was sent with this request, create the `Project` anyway. - $existingEbook = Ebook::GetByIdentifier($ebook->Identifier); - if($ebook->EbookPlaceholder?->IsInProgress && $existingEbook->ProjectInProgress === null && $project !== null){ - $ebook->EbookId = $existingEbook->EbookId; - $_SESSION['is-only-ebook-project-created'] = true; - } - else{ - // The existing ebook already has a `Project`, throw the exception and really fail. - $ebook = $existingEbook; - throw new Exceptions\ProjectExistsException('This ebook already exists, and already has an in-progress project.'); - } + $ebook = Ebook::GetByIdentifier($ebook->Identifier); + + // An existing `EbookPlaceholder` already exists. + $ex = new Exceptions\EbookPlaceholderExistsException('An ebook placeholder already exists for this book: ' . Formatter::EscapeHtml($ebook->Title) . '.'); + + $ex->MessageType = Enums\ExceptionMessageType::Html; + + throw $ex; } if($ebook->EbookPlaceholder?->IsInProgress && $project !== null){ @@ -98,7 +95,7 @@ catch(Exceptions\LoginRequiredException){ catch(Exceptions\InvalidPermissionsException | Exceptions\InvalidHttpMethodException | Exceptions\HttpMethodNotAllowedException){ Template::ExitWithCode(Enums\HttpCode::Forbidden); } -catch(Exceptions\InvalidEbookException | Exceptions\ProjectExistsException | Exceptions\InvalidProjectException $ex){ +catch(Exceptions\InvalidEbookException | Exceptions\EbookPlaceholderExistsException | Exceptions\InvalidProjectException $ex){ $_SESSION['ebook'] = $ebook; $_SESSION['exception'] = $ex;