Some type check fixes

This commit is contained in:
Alex Cabal 2024-12-13 23:21:04 -06:00
parent 1979b27432
commit 79fdc8c20f
4 changed files with 21 additions and 13 deletions

View file

@ -7,6 +7,10 @@ $ebook = null;
try{
$ebook = Ebook::GetByIdentifier($identifier);
if($ebook->EbookPlaceholder === null){
throw new Exceptions\EbookNotFoundException();
}
}
catch(Exceptions\EbookNotFoundException){
Template::Emit404();

View file

@ -19,19 +19,23 @@ try{
if($isCreated){
// We got here because an `Ebook` was successfully created.
http_response_code(Enums\HttpCode::Created->value);
$createdEbook = clone $ebook;
if($ebook !== null){
$createdEbook = clone $ebook;
if(sizeof($ebook->CollectionMemberships) > 0){
// If the `EbookPlaceholder` we just added is part of a collection, prefill the form with the same data to make it easier to submit series.
unset($ebook->EbookId);
unset($ebook->Title);
$ebook->EbookPlaceholder->YearPublished = null;
foreach($ebook->CollectionMemberships as $collectionMembership){
$collectionMembership->SequenceNumber++;
if(sizeof($ebook->CollectionMemberships) > 0){
// If the `EbookPlaceholder` we just added is part of a collection, prefill the form with the same data to make it easier to submit series.
unset($ebook->EbookId);
unset($ebook->Title);
if($ebook->EbookPlaceholder !== null){
$ebook->EbookPlaceholder->YearPublished = null;
}
foreach($ebook->CollectionMemberships as $collectionMembership){
$collectionMembership->SequenceNumber++;
}
}
else{
$ebook = null;
}
}
else{
$ebook = null;
}
session_unset();