[mb-commits] r11065 - in mb_server/branches/TemplateToolkit: lib lib/MusicBrainz/Server lib/MusicBrainz/Server/Controller lib/MusicBrainz/Server/Model root/main
root at musicbrainz.org
root at musicbrainz.org
Sun Jan 18 16:19:55 UTC 2009
Author: acid2
Date: 2009-01-18 16:19:54 +0000 (Sun, 18 Jan 2009)
New Revision: 11065
Added:
mb_server/branches/TemplateToolkit/root/main/500.tt
Modified:
mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Adapter.pm
mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Artist.pm
mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Controller.pm
mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Controller/Artist.pm
mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Controller/Label.pm
mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Controller/Root.pm
mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Label.pm
mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Model/Artist.pm
mb_server/branches/TemplateToolkit/lib/TableBase.pm
Log:
Don't blow up on missing artists, labels, releases, etc - fixes #4410
Modified: mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Adapter.pm
===================================================================
--- mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Adapter.pm 2009-01-18 14:31:24 UTC (rev 11064)
+++ mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Adapter.pm 2009-01-18 16:19:54 UTC (rev 11065)
@@ -47,20 +47,15 @@
{
$entity->mbid($mbid);
}
- else
+ elsif (MusicBrainz::Server::Validation::IsNonNegInteger($mbid))
{
- if (MusicBrainz::Server::Validation::IsNonNegInteger($mbid))
- {
- $entity->id($mbid);
- }
- else
- {
- croak "$mbid is not a valid MBID or row ID";
- }
+ $entity->id($mbid);
}
+
+ return unless ($entity->id || $entity->mbid);
$entity->LoadFromId(1)
- or croak "Could not load entity";
+ or return;
return $entity;
}
Modified: mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Artist.pm
===================================================================
--- mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Artist.pm 2009-01-18 14:31:24 UTC (rev 11064)
+++ mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Artist.pm 2009-01-18 16:19:54 UTC (rev 11065)
@@ -816,6 +816,8 @@
$id,
),
);
+
+ return unless $obj;
$obj->mbid($obj->{gid}) if $obj;
@@ -864,6 +866,8 @@
);
}
}
+
+ return unless $obj;
$obj->{mbid} = delete $obj->{gid} if $obj;
@@ -949,16 +953,16 @@
language, script, quality, modpending_qual, tracks, discids,
firstreleasedate, coverarturl, asin, puids
FROM Album, Albummeta
- WHERE artist=$this->{id} AND albummeta.id = album.id/;
+ WHERE artist = ? AND albummeta.id = album.id/;
}
else
{
$query = qq/SELECT album.id, name, modpending, GID,
attributes, language, script, quality, modpending_qual
FROM Album
- WHERE artist=$this->{id}/;
+ WHERE artist = ?/;
}
- if ($sql->Select($query))
+ if ($sql->Select($query, $this->id))
{
while(@row = $sql->NextRow)
{
Modified: mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Controller/Artist.pm
===================================================================
--- mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Controller/Artist.pm 2009-01-18 14:31:24 UTC (rev 11064)
+++ mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Controller/Artist.pm 2009-01-18 16:19:54 UTC (rev 11065)
@@ -56,8 +56,7 @@
if ($self->entity->id == ModDefs::DARTIST_ID)
{
- $c->error("You cannot view the special artist 'DELETED ARTIST'");
- $c->detach;
+ $c->detach('/error_404');
}
if ($c->user_exists)
Modified: mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Controller/Label.pm
===================================================================
--- mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Controller/Label.pm 2009-01-18 14:31:24 UTC (rev 11064)
+++ mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Controller/Label.pm 2009-01-18 16:19:54 UTC (rev 11065)
@@ -32,6 +32,11 @@
sub label : Chained('load') PathPart('') CaptureArgs(0)
{
my ($self, $c) = @_;
+
+ if ($self->entity->id == ModDefs::DLABEL_ID)
+ {
+ $c->detach('/error_404');
+ }
if ($c->user_exists)
{
Modified: mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Controller/Root.pm
===================================================================
--- mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Controller/Root.pm 2009-01-18 14:31:24 UTC (rev 11064)
+++ mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Controller/Root.pm 2009-01-18 16:19:54 UTC (rev 11065)
@@ -61,7 +61,13 @@
sub default : Path
{
my ($self, $c) = @_;
+ $c->detach('/error_404');
+}
+sub error_404 : Private
+{
+ my ($self, $c) = @_;
+
$c->response->status(404);
$c->stash->{template} = 'main/404.tt';
}
Modified: mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Controller.pm
===================================================================
--- mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Controller.pm 2009-01-18 14:31:24 UTC (rev 11064)
+++ mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Controller.pm 2009-01-18 16:19:54 UTC (rev 11065)
@@ -5,6 +5,8 @@
use base qw/Catalyst::Controller Class::Accessor/;
+use MusicBrainz::Server::Validation;
+
__PACKAGE__->mk_accessors(qw/ entity form /);
__PACKAGE__->config(
form_namespace => 'MusicBrainz::Server::Form'
@@ -27,13 +29,26 @@
sub load : Chained('base') PathPart('') CaptureArgs(1)
{
- my ($self, $c, $id) = @_;
-
- my $entity = $c->model($self->{model})->load($id);
-
- $self->entity($entity);
- $c->stash->{$self->{entity_name}} = $entity;
- $c->stash->{entity} = $entity;
+ my ($self, $c, $id) = @_;
+
+ unless (MusicBrainz::Server::Validation::IsGUID($id) ||
+ (MusicBrainz::Server::Validation::IsNonNegInteger($id) && $id > 0))
+ {
+ $c->detach('/error_404');
+ }
+
+ my $entity = $c->model($self->{model})->load($id);
+
+ if (defined $entity)
+ {
+ $self->entity($entity);
+ $c->stash->{$self->{entity_name}} = $entity;
+ $c->stash->{entity} = $entity;
+ }
+ else
+ {
+ $c->detach('/error_404');
+ }
}
=head2 submit_and_validate
Modified: mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Label.pm
===================================================================
--- mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Label.pm 2009-01-18 14:31:24 UTC (rev 11064)
+++ mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Label.pm 2009-01-18 16:19:54 UTC (rev 11065)
@@ -150,7 +150,7 @@
$self->{country_ref} = MusicBrainz::Server::Country->newFromId($self->dbh, $self->country);
}
- return $self->{country_ref}->name;
+ return defined $self->{country_ref} ? $self->{country_ref}->name : '';
}
=head3 type_name
Modified: mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Model/Artist.pm
===================================================================
--- mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Model/Artist.pm 2009-01-18 14:31:24 UTC (rev 11064)
+++ mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Model/Artist.pm 2009-01-18 16:19:54 UTC (rev 11065)
@@ -22,7 +22,7 @@
my ($self, $id) = @_;
my $artist = new MusicBrainz::Server::Artist($self->dbh);
- LoadEntity($artist, $id);
+ LoadEntity($artist, $id) or return;
return $artist;
}
Modified: mb_server/branches/TemplateToolkit/lib/TableBase.pm
===================================================================
--- mb_server/branches/TemplateToolkit/lib/TableBase.pm 2009-01-18 14:31:24 UTC (rev 11064)
+++ mb_server/branches/TemplateToolkit/lib/TableBase.pm 2009-01-18 16:19:54 UTC (rev 11065)
@@ -122,6 +122,7 @@
sub _new_from_row
{
my ($self, $row) = @_;
+ return unless $row;
return $self->new($self->dbh, $row);
}
More information about the MusicBrainz-commits
mailing list