X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Flib%2FRT%2FURI%2Ffsck_com_article.pm;h=713277080f076b763f9d2627235ce5ff3f3243d1;hb=1c538bfabc2cd31f27067505f0c3d1a46cba6ef0;hp=2b2132f5f72a99cd55374e7d2abfcbe4f011c225;hpb=3d0a1bb06b895c5be6e3f0517d355442a6b1e125;p=freeside.git diff --git a/rt/lib/RT/URI/fsck_com_article.pm b/rt/lib/RT/URI/fsck_com_article.pm index 2b2132f5f..713277080 100644 --- a/rt/lib/RT/URI/fsck_com_article.pm +++ b/rt/lib/RT/URI/fsck_com_article.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC # # # (Except where explicitly superseded by other copyright notices) @@ -52,8 +52,8 @@ use strict; use warnings; no warnings 'redefine'; -use RT::Article; use base qw/RT::URI::base/; +use RT::Article; =head2 LocalURIPrefix @@ -63,8 +63,7 @@ Returns the prefix for a local article URI sub LocalURIPrefix { my $self = shift; - my $prefix = $self->Scheme. "://". RT->Config->Get('Organization') - . "/article/"; + my $prefix = $self->Scheme. "://". RT->Config->Get('Organization'); return ($prefix); } @@ -79,7 +78,7 @@ sub URIForObject { my $self = shift; my $obj = shift; - return ($self->LocalURIPrefix. $obj->Id); + return ($self->LocalURIPrefix . "/article/" . $obj->Id); } @@ -100,39 +99,45 @@ sub ParseURI { my $self = shift; my $uri = shift; - my $article; - - if ($uri =~ /^(\d+)$/) { - $article = RT::Article->new($self->CurrentUser); - $article->Load($uri); - $self->{'uri'} = $article->URI; - } - else { - $self->{'uri'} = $uri; - } - + my $article; + + if ($uri =~ /^(\d+)$/) { + $article = RT::Article->new($self->CurrentUser); + $article->Load($uri); + $self->{'uri'} = $article->URI; + } + else { + $self->{'uri'} = $uri; + } + #If it's a local URI, load the article object and return its URI if ( $self->IsLocal) { - my $local_uri_prefix = $self->LocalURIPrefix; - if ($self->{'uri'} =~ /^$local_uri_prefix(\d+)$/) { - my $id = $1; - - - $article = RT::Article->new( $self->CurrentUser ); - $article->Load($id); - - #If we couldn't find a article, return undef. - unless ( defined $article->Id ) { - return undef; - } - } else { - return undef; - } + if ($self->{'uri'} =~ /^$local_uri_prefix\/article\/(\d+)$/) { + my $id = $1; + $article = RT::Article->new( $self->CurrentUser ); + my ($ret, $msg) = $article->Load($id); + + #If we couldn't find a article, return undef. + unless ( $article and $article->Id ) { + # We got an id, but couldn't load it, so warn that it may + # have been deleted. + RT::Logger->warning("Unable to load article for id $id. It may" + . " have been deleted: $msg"); + return undef; + } + } else { + return undef; + } + } + + #If we couldn't find a article, return undef. + unless ( $article and $article->Id ) { + return undef; } - - $self->{'object'} = $article; - return ($article->Id); + + $self->{'object'} = $article; + return ($article->Id); } =head2 IsLocal @@ -143,14 +148,14 @@ Returns undef otherwise. =cut sub IsLocal { - my $self = shift; - my $local_uri_prefix = $self->LocalURIPrefix; - if ($self->{'uri'} =~ /^$local_uri_prefix/) { - return 1; + my $self = shift; + my $local_uri_prefix = $self->LocalURIPrefix; + if ($self->{'uri'} =~ /^$local_uri_prefix/) { + return 1; + } + else { + return undef; } - else { - return undef; - } } @@ -175,7 +180,7 @@ Return the URI scheme for RT articles sub Scheme { my $self = shift; - return "fsck.com-article"; + return "fsck.com-article"; } =head2 HREF @@ -203,9 +208,12 @@ Return "Article 23" sub AsString { my $self = shift; - if ($self->IsLocal && $self->Object) { - return $self->loc('Article [_1]', $self->Object->id); - + if ($self->IsLocal && ( my $object = $self->Object )) { + if ( $object->Name ) { + return $self->loc('Article #[_1]: [_2]', $object->id, $object->Name); + } else { + return $self->loc('Article #[_1]', $object->id); + } } else { return $self->SUPER::AsString(@_); }