Allow PATCHing of artwork ebook URL to empty string

This commit is contained in:
Alex Cabal 2024-01-29 18:27:56 -06:00
parent 69dc4580ed
commit 6ff60d8d96

View file

@ -110,24 +110,28 @@ try{
$exceptionRedirectUrl = $artwork->Url;
// We can PATCH the status, the ebook www filesystem path, or both.
if(isset($_POST['artwork-status'])){
$newStatus = ArtworkStatus::tryFrom(HttpInput::Str(POST, 'artwork-status') ?? '');
if($newStatus !== null){
if($artwork->Status != $newStatus && !$artwork->CanStatusBeChangedBy($GLOBALS['User'])){
throw new Exceptions\InvalidPermissionsException();
}
$newStatus = ArtworkStatus::tryFrom(HttpInput::Str(POST, 'artwork-status') ?? '');
if($newStatus !== null){
if($artwork->Status != $newStatus && !$artwork->CanStatusBeChangedBy($GLOBALS['User'])){
$artwork->ReviewerUserId = $GLOBALS['User']->UserId;
}
$artwork->Status = $newStatus;
}
if(isset($_POST['artwork-ebook-url'])){
$newEbookUrl = HttpInput::Str(POST, 'artwork-ebook-url');
if($artwork->EbookUrl != $newEbookUrl && !$artwork->CanEbookUrlBeChangedBy($GLOBALS['User'])){
throw new Exceptions\InvalidPermissionsException();
}
$artwork->ReviewerUserId = $GLOBALS['User']->UserId;
$artwork->EbookUrl = $newEbookUrl;
}
$newEbookUrl = HttpInput::Str(POST, 'artwork-ebook-url') ?? null;
if($artwork->EbookUrl != $newEbookUrl && !$artwork->CanEbookUrlBeChangedBy($GLOBALS['User'])){
throw new Exceptions\InvalidPermissionsException();
}
$artwork->Status = $newStatus ?? $artwork->Status;
$artwork->EbookUrl = $newEbookUrl ?? $artwork->EbookUrl;
$artwork->Save();
$_SESSION['artwork'] = $artwork;