#
# COPYRIGHT:
#
-# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
+# This software is Copyright (c) 1996-2019 Best Practical Solutions, LLC
# <sales@bestpractical.com>
#
# (Except where explicitly superseded by other copyright notices)
use warnings;
no warnings 'redefine';
-use RT::Article;
use base qw/RT::URI::base/;
+use RT::Article;
=head2 LocalURIPrefix
sub LocalURIPrefix {
my $self = shift;
- my $prefix = $self->Scheme. "://". RT->Config->Get('Organization')
- . "/article/";
+ my $prefix = $self->Scheme. "://". RT->Config->Get('Organization');
return ($prefix);
}
my $self = shift;
my $obj = shift;
- return ($self->LocalURIPrefix. $obj->Id);
+ return ($self->LocalURIPrefix . "/article/" . $obj->Id);
}
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
=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;
- }
}
sub Scheme {
my $self = shift;
- return "fsck.com-article";
+ return "fsck.com-article";
}
=head2 HREF
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(@_);
}