summaryrefslogtreecommitdiff
path: root/rt/lib/RT/URI/fsck_com_article.pm
diff options
context:
space:
mode:
Diffstat (limited to 'rt/lib/RT/URI/fsck_com_article.pm')
-rw-r--r--rt/lib/RT/URI/fsck_com_article.pm96
1 files changed, 52 insertions, 44 deletions
diff --git a/rt/lib/RT/URI/fsck_com_article.pm b/rt/lib/RT/URI/fsck_com_article.pm
index 580bccd..7132770 100644
--- a/rt/lib/RT/URI/fsck_com_article.pm
+++ b/rt/lib/RT/URI/fsck_com_article.pm
@@ -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(@_);
}