mirror of
https://github.com/standardebooks/web.git
synced 2025-07-17 11:56:38 -04:00
Redirect an artwork if it's found under an artist's alternate name.
This commit is contained in:
parent
71c2dfc55b
commit
f97539f399
2 changed files with 40 additions and 2 deletions
|
@ -130,7 +130,26 @@ class Artist{
|
||||||
where ArtistId = ?
|
where ArtistId = ?
|
||||||
', [$artistId], Artist::class);
|
', [$artistId], Artist::class);
|
||||||
|
|
||||||
return $result[0] ?? throw new Exceptions\ArtistNotFoundException();;
|
return $result[0] ?? throw new Exceptions\ArtistNotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exceptions\ArtistNotFoundException
|
||||||
|
*/
|
||||||
|
public static function GetByAlternateUrlName(?string $urlName): Artist{
|
||||||
|
if($urlName === null){
|
||||||
|
throw new Exceptions\ArtistNotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = Db::Query('
|
||||||
|
SELECT a.*
|
||||||
|
from Artists a
|
||||||
|
left outer join ArtistAlternateNames aan using (ArtistId)
|
||||||
|
where aan.UrlName = ?
|
||||||
|
limit 1
|
||||||
|
', [$urlName], Artist::class);
|
||||||
|
|
||||||
|
return $result[0] ?? throw new Exceptions\ArtistNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -8,7 +8,26 @@ $isSaved = HttpInput::Bool(SESSION, 'is-saved') ?? false;
|
||||||
$exception = $_SESSION['exception'] ?? null;
|
$exception = $_SESSION['exception'] ?? null;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$artwork = Artwork::GetByUrl(HttpInput::Str(GET, 'artist-url-name'), HttpInput::Str(GET, 'artwork-url-name'));
|
try{
|
||||||
|
$artwork = Artwork::GetByUrl(HttpInput::Str(GET, 'artist-url-name'), HttpInput::Str(GET, 'artwork-url-name'));
|
||||||
|
}
|
||||||
|
catch(Exceptions\ArtworkNotFoundException $ex){
|
||||||
|
// We didn't find the artwork under this artist, does the artist exist under an alternate name?
|
||||||
|
try{
|
||||||
|
$artist = Artist::GetByAlternateUrlName(HttpInput::Str(GET, 'artist-url-name'));
|
||||||
|
$artwork = Artwork::GetByUrl($artist->UrlName, HttpInput::Str(GET, 'artwork-url-name'));
|
||||||
|
|
||||||
|
// Artwork found under an artist alternate name, redirect there and exit.
|
||||||
|
http_response_code(Enums\HttpCode::MovedPermanently->value);
|
||||||
|
header('Location: ' . $artwork->Url);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
catch(Exceptions\ArtistNotFoundException){
|
||||||
|
// The artwork is really not found, throw the original exception.
|
||||||
|
throw $ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$isReviewerView = $GLOBALS['User']->Benefits->CanReviewArtwork ?? false;
|
$isReviewerView = $GLOBALS['User']->Benefits->CanReviewArtwork ?? false;
|
||||||
$isAdminView = $GLOBALS['User']->Benefits->CanReviewOwnArtwork ?? false;
|
$isAdminView = $GLOBALS['User']->Benefits->CanReviewOwnArtwork ?? false;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue