1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC
6 # <jesse@bestpractical.com>
8 # (Except where explicitly superseded by other copyright notices)
13 # This work is made available to you under the terms of Version 2 of
14 # the GNU General Public License. A copy of that license should have
15 # been provided with this software, but in any event can be snarfed
18 # This work is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 # 02110-1301 or visit their web page on the internet at
27 # http://www.gnu.org/copyleft/gpl.html.
30 # CONTRIBUTION SUBMISSION POLICY:
32 # (The following paragraph is not intended to limit the rights granted
33 # to you to modify and distribute this software under the terms of
34 # the GNU General Public License and is only of importance to you if
35 # you choose to contribute your changes and enhancements to the
36 # community by submitting them to Best Practical Solutions, LLC.)
38 # By intentionally submitting any modifications, corrections or
39 # derivatives to this work, or any other work intended for use with
40 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 # you are the copyright holder for those contributions and you grant
42 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 # royalty-free, perpetual, license to use, copy, create derivative
44 # works based on those contributions, and sublicense and distribute
45 # those contributions and any derivatives thereof.
47 # END BPS TAGGED BLOCK }}}
50 RT::Link - an RT Link object
58 This module should never be called directly by client code. it's an internal module which
59 should only be accessed through exported APIs in Ticket other similar objects.
68 my $link = RT::Link->new($RT::SystemUser);
72 ok (UNIVERSAL::isa($link, 'RT::Link'));
73 ok (UNIVERSAL::isa($link, 'RT::Base'));
74 ok (UNIVERSAL::isa($link, 'RT::Record'));
75 ok (UNIVERSAL::isa($link, 'DBIx::SearchBuilder::Record'));
85 no warnings qw(redefine);
94 =head2 Create PARAMHASH
96 Create a new link object. Takes 'Base', 'Target' and 'Type'.
97 Returns undef on failure or a Link Id on success.
103 my %args = ( Base => undef,
108 my $base = RT::URI->new( $self->CurrentUser );
109 $base->FromURI( $args{'Base'} );
111 unless ( $base->Resolver && $base->Scheme ) {
112 my $msg = $self->loc("Couldn't resolve base '[_1]' into a URI.",
114 $RT::Logger->warning( "$self $msg\n" );
123 my $target = RT::URI->new( $self->CurrentUser );
124 $target->FromURI( $args{'Target'} );
126 unless ( $target->Resolver ) {
127 my $msg = $self->loc("Couldn't resolve target '[_1]' into a URI.",
129 $RT::Logger->warning( "$self $msg\n" );
144 if ( $base->IsLocal ) {
145 unless (UNIVERSAL::can($base->Object, 'Id')) {
146 return (undef, $self->loc("[_1] appears to be a local object, but can't be found in the database", $args{'Base'}));
149 $base_id = $base->Object->Id;
151 if ( $target->IsLocal ) {
152 unless (UNIVERSAL::can($target->Object, 'Id')) {
153 return (undef, $self->loc("[_1] appears to be a local object, but can't be found in the database", $args{'Target'}));
156 $target_id = $target->Object->Id;
159 # {{{ We don't want references to ourself
160 if ( $base->URI eq $target->URI ) {
161 return ( 0, $self->loc("Can't link a ticket to itself") );
166 my ( $id, $msg ) = $self->SUPER::Create( Base => $base->URI,
167 Target => $target->URI,
168 LocalBase => $base_id,
169 LocalTarget => $target_id,
170 Type => $args{'Type'} );
171 return ( $id, $msg );
175 # {{{ sub LoadByParams
179 Load an RT::Link object from the database. Takes three parameters
185 Base and Target are expected to be integers which refer to Tickets or URIs
186 Type is the link type
192 my %args = ( Base => undef,
197 my $base = RT::URI->new($self->CurrentUser);
198 $base->FromURI( $args{'Base'} );
200 my $target = RT::URI->new($self->CurrentUser);
201 $target->FromURI( $args{'Target'} );
203 unless ($base->Resolver && $target->Resolver) {
204 return ( 0, $self->loc("Couldn't load link") );
208 my ( $id, $msg ) = $self->LoadByCols( Base => $base->URI,
209 Type => $args{'Type'},
210 Target => $target->URI );
213 return ( 0, $self->loc("Couldn't load link") );
222 Load an RT::Link object from the database. Takes one parameter, the id of an entry in the links table.
229 my $identifier = shift;
234 if ( $identifier !~ /^\d+$/ ) {
235 return ( 0, $self->loc("That's not a numerical id") );
238 my ( $id, $msg ) = $self->LoadById($identifier);
239 unless ( $self->Id ) {
240 return ( 0, $self->loc("Couldn't load link") );
242 return ( $id, $msg );
253 returns an RT::URI object for the "Target" of this link.
259 my $URI = RT::URI->new($self->CurrentUser);
260 $URI->FromURI($self->Target);
273 return $self->TargetURI->Object;
281 returns an RT::URI object for the "Base" of this link.
287 my $URI = RT::URI->new($self->CurrentUser);
288 $URI->FromURI($self->Base);
301 return $self->BaseURI->Object;
309 # {{{ sub BaseIsLocal
313 Returns true if the base of this link is a local ticket
319 $RT::Logger->crit("Link::BaseIsLocal is deprecated in favor of Link->BaseURI->IsLocal at (". join(":",caller).")");
320 return $self->BaseURI->IsLocal;
325 # {{{ sub TargetIsLocal
329 Returns true if the target of this link is a local ticket
335 $RT::Logger->crit("Link::BaseIsLocal is deprecated in favor of Link->BaseURI->IsLocal at (". join(":",caller).")");
336 return $self->TargetURI->IsLocal;
346 Returns an HTTP url to access the base of this link
352 $RT::Logger->crit("Link::BaseAsHREF deprecated in favor of ->BaseURI->AsHREF at (". join(":",caller).")");
353 return $self->BaseURI->AsHREF;
357 # {{{ sub TargetAsHREF
361 return an HTTP url to access the target of this link
367 $RT::Logger->crit("Link::TargetAsHREF deprecated in favor of ->TargetURI->AsHREF at (". join(":",caller).")");
368 return $self->TargetURI->AsHREF;
372 # {{{ sub AsHREF - Converts Link URIs to HTTP URLs
376 Takes a URI and returns an http: url to access that object.
384 $RT::Logger->crit("AsHREF is gone. look at URI::HREF to figure out what to do with \$URI");