We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit eb108ccd authored by P. J. McDermott's avatar P. J. McDermott

Catch Exceptions thrown by Artist::__construct().

All code instantiating Artist objects has been encapsulated in
try...catch blocks. This should help solve some potential problems with
invalid artist names.
parent 05e2aab6
......@@ -23,7 +23,14 @@ require_once('database.php');
require_once('templating.php');
require_once('data/Album.php');
$artist = new Artist(urldecode($_GET['artist']));
try {
$artist = new Artist(urldecode($_GET['artist']));
} catch (Exception $e) {
$smarty->assign('pageheading', 'Artist not found.');
$smarty->assign('details', 'The artist ' . $_GET['artist'] . ' was not found in the database.');
$smarty->display('error.tpl');
die();
}
if(!isset($this_user) || !$this_user->manages($artist->name)) {
$smarty->assign('pageheading', 'Permission denied');
......
......@@ -25,7 +25,15 @@ require_once('templating.php');
require_once('data/Album.php');
$album = new Album(urldecode($_GET['album']), urldecode($_GET['artist']));
$artist = new Artist($album->artist_name);
try {
$artist = new Artist($album->artist_name);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Artist not found.');
$smarty->assign('details', 'The artist ' . $track->artist_name . ' was not found in the database.');
$smarty->display('error.tpl');
die();
}
$smarty->assign('name', $album->name);
$smarty->assign('id', $album->id);
......
......@@ -40,10 +40,10 @@ class ArtistXML {
return;
}
$artist = new Artist($artistName, $mbid);
if (!$artist) {
return(XML::error('failed', '7', 'Invalid resource specified'));
try {
$artist = new Artist($artistName, $mbid);
} catch (Exception $e) {
return XML::error('failed', '7', 'Invalid resource specified');
}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
......@@ -64,9 +64,9 @@ class ArtistXML {
public static function getTopTracks($artistName) {
$artist = new Artist($artistName);
if (!$artist) {
try {
$artist = new Artist($artistName);
} catch (Exception $e) {
return(XML::error('failed', '7', 'Invalid resource specified'));
}
......@@ -91,9 +91,9 @@ class ArtistXML {
public static function getTopTags($artistName) {
$artist = new Artist($artistName);
if (!$artist) {
try {
$artist = new Artist($artistName);
} catch (Exception $e) {
return(XML::error('failed', '7', 'Invalid resource specified'));
}
......@@ -114,9 +114,9 @@ class ArtistXML {
public static function getFlattr($artistName) {
$artist = new Artist($artistName);
if(!$artist) {
try {
$artist = new Artist($artistName);
} catch (Exception $e) {
return(XML::error('failed', '7', 'Invalid resource specified'));
}
......
......@@ -88,8 +88,12 @@ class Album {
. $adodb->qstr($artist_name) . ', '
. $adodb->qstr($image) . ')');
$artist = new Artist($artist_name);
$artist->clearAlbumCache();
try {
$artist = new Artist($artist_name);
$artist->clearAlbumCache();
} catch (Exception $e) {
// No such artist.
}
return new Album($name, $artist_name);
}
......
......@@ -173,8 +173,12 @@ class Track {
if($streamable) {
$adodb->Execute('UPDATE Artist SET streamable=1 WHERE name=' . $adodb->qstr($this->artist_name));
$artist = new Artist($this->artist_name);
$artist->clearCache();
try {
$artist = new Artist($this->artist_name);
$artist->clearCache();
} catch (Exception $e) {
// No such artist.
}
}
$this->clearCache();
}
......@@ -232,7 +236,11 @@ class Track {
* @return An artist object
*/
function getArtist() {
return new Artist($this->artist_name);
try {
return new Artist($this->artist_name);
} catch (Exception $e) {
throw $e;
}
}
function getURL() {
......
......@@ -82,7 +82,11 @@ function make_playlist($session, $old_format=false) {
$tag = $regs[2];
$res = $adodb->Execute('SELECT Track.name, Track.artist_name, Track.album_name, Track.duration, Track.streamurl FROM Track INNER JOIN Tags ON Track.name=Tags.track AND Track.artist_name=Tags.artist WHERE streamable=1 AND lower(tag) = ' . $adodb->qstr(mb_strtolower($tag, 'UTF-8')));
} elseif(preg_match('@l(ast|ibre)fm://artist/(.*)/similarartists@', $url, $regs)) {
$artist = new Artist($regs[2]);
try {
$artist = new Artist($regs[2]);
} catch (Exception $e) {
die("FAILED\n"); // this should return a blank dummy playlist instead
}
$similarArtists = $artist->getSimilar(20);
$res = get_artist_selection($similarArtists, $artist);
} elseif(preg_match('@l(ast|ibre)fm://artist/(.*)@', $url, $regs)) {
......
......@@ -26,7 +26,15 @@ require_once('data/Album.php');
require_once('data/Track.php');
require_once('utils/licenses.php');
$artist = new Artist(urldecode($_GET['artist']));
try {
$artist = new Artist(urldecode($_GET['artist']));
} catch (Exception $e) {
$smarty->assign('pageheading', 'Artist not found.');
$smarty->assign('details', 'The artist ' . $_GET['artist'] . ' was not found in the database.');
$smarty->display('error.tpl');
die();
}
$album = new Album(urldecode($_GET['album']), $artist->name);
if(!isset($this_user) || !$this_user->manages($artist->name)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment