diff options
author | Ivan Kohler <ivan@freeside.biz> | 2015-07-09 22:18:55 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2015-07-09 22:18:55 -0700 |
commit | 1c538bfabc2cd31f27067505f0c3d1a46cba6ef0 (patch) | |
tree | 96922ad4459eda1e649327fd391d60c58d454c53 /rt/lib/RT/URI | |
parent | 4f5619288413a185e9933088d9dd8c5afbc55dfa (diff) |
RT 4.2.11, ticket#13852
Diffstat (limited to 'rt/lib/RT/URI')
-rw-r--r-- | rt/lib/RT/URI/a.pm | 10 | ||||
-rw-r--r-- | rt/lib/RT/URI/fsck_com_article.pm | 96 | ||||
-rw-r--r-- | rt/lib/RT/URI/fsck_com_rt.pm | 18 |
3 files changed, 72 insertions, 52 deletions
diff --git a/rt/lib/RT/URI/a.pm b/rt/lib/RT/URI/a.pm index eca253fa5..baab6585e 100644 --- a/rt/lib/RT/URI/a.pm +++ b/rt/lib/RT/URI/a.pm @@ -51,8 +51,8 @@ package RT::URI::a; use strict; use warnings; -use RT::Article; use base qw/RT::URI::fsck_com_article/; +use RT::Article; my $scheme = "a"; @@ -71,11 +71,11 @@ sub ParseURI { # articles after stripping off the a: prefix. if ($uri =~ /^$scheme:(\d+)/) { - my $value = $1; - return $self->SUPER::ParseURI($value); + my $value = $1; + return $self->SUPER::ParseURI($value); } else { - $self->{'uri'} = $uri; - return undef; + $self->{'uri'} = $uri; + return undef; } } diff --git a/rt/lib/RT/URI/fsck_com_article.pm b/rt/lib/RT/URI/fsck_com_article.pm index 580bccdc3..713277080 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(@_); } diff --git a/rt/lib/RT/URI/fsck_com_rt.pm b/rt/lib/RT/URI/fsck_com_rt.pm index 0a9001e43..053268f9e 100644 --- a/rt/lib/RT/URI/fsck_com_rt.pm +++ b/rt/lib/RT/URI/fsck_com_rt.pm @@ -209,14 +209,26 @@ sub HREF { =head2 AsString -Returns either a localized string 'ticket #23' or the full URI if the object is not local +Returns either a localized string C<#23: Subject> for tickets, C<ObjectType #13: +Name> for other object types (not really used), or the full URI if the object +is not local. =cut sub AsString { my $self = shift; - if ($self->IsLocal && $self->Object) { - return $self->loc("[_1] #[_2]", $self->ObjectType, $self->Object->Id); + if ($self->IsLocal && ( my $object = $self->Object )) { + if ($object->isa('RT::Ticket')) { + return $self->loc("#[_1]: [_2]", $object->Id, $object->Subject || ''); + } else { + my $name = $object->_Accessible('Name', 'read') ? $object->Name : undef; + + if ( defined $name and length $name ) { + return $self->loc("[_1] #[_2]: [_3]", $self->ObjectType, $object->Id, $name); + } else { + return $self->loc("[_1] #[_2]", $self->ObjectType, $object->Id); + } + } } else { return $self->URI; |