1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2005 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., 675 Mass Ave, Cambridge, MA 02139, USA.
28 # CONTRIBUTION SUBMISSION POLICY:
30 # (The following paragraph is not intended to limit the rights granted
31 # to you to modify and distribute this software under the terms of
32 # the GNU General Public License and is only of importance to you if
33 # you choose to contribute your changes and enhancements to the
34 # community by submitting them to Best Practical Solutions, LLC.)
36 # By intentionally submitting any modifications, corrections or
37 # derivatives to this work, or any other work intended for use with
38 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
39 # you are the copyright holder for those contributions and you grant
40 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
41 # royalty-free, perpetual, license to use, copy, create derivative
42 # works based on those contributions, and sublicense and distribute
43 # those contributions and any derivatives thereof.
45 # END BPS TAGGED BLOCK }}}
49 RT::Link - an RT Link object
57 This module should never be called directly by client code. it's an internal module which
58 should only be accessed through exported APIs in Ticket other similar objects.
67 my $link = RT::Link->new($RT::SystemUser);
71 ok (UNIVERSAL::isa($link, 'RT::Link'));
72 ok (UNIVERSAL::isa($link, 'RT::Base'));
73 ok (UNIVERSAL::isa($link, 'RT::Record'));
74 ok (UNIVERSAL::isa($link, 'DBIx::SearchBuilder::Record'));
84 no warnings qw(redefine);
93 =head2 Create PARAMHASH
95 Create a new link object. Takes 'Base', 'Target' and 'Type'.
96 Returns undef on failure or a Link Id on success.
102 my %args = ( Base => undef,
107 my $base = RT::URI->new( $self->CurrentUser );
108 $base->FromURI( $args{'Base'} );
110 unless ( $base->Resolver && $base->Scheme ) {
111 my $msg = $self->loc("Couldn't resolve base '[_1]' into a URI.",
113 $RT::Logger->warning( "$self $msg\n" );
122 my $target = RT::URI->new( $self->CurrentUser );
123 $target->FromURI( $args{'Target'} );
125 unless ( $target->Resolver ) {
126 my $msg = $self->loc("Couldn't resolve target '[_1]' into a URI.",
128 $RT::Logger->warning( "$self $msg\n" );
143 if ( $base->IsLocal ) {
144 unless (UNIVERSAL::can($base->Object, 'Id')) {
145 return (undef, $self->loc("[_1] appears to be a local object, but can't be found in the database", $args{'Base'}));
148 $base_id = $base->Object->Id;
150 if ( $target->IsLocal ) {
151 unless (UNIVERSAL::can($target->Object, 'Id')) {
152 return (undef, $self->loc("[_1] appears to be a local object, but can't be found in the database", $args{'Target'}));
155 $target_id = $target->Object->Id;
158 # {{{ We don't want references to ourself
159 if ( $base->URI eq $target->URI ) {
160 return ( 0, $self->loc("Can't link a ticket to itself") );
165 my ( $id, $msg ) = $self->SUPER::Create( Base => $base->URI,
166 Target => $target->URI,
167 LocalBase => $base_id,
168 LocalTarget => $target_id,
169 Type => $args{'Type'} );
170 return ( $id, $msg );
174 # {{{ sub LoadByParams
178 Load an RT::Link object from the database. Takes three parameters
184 Base and Target are expected to be integers which refer to Tickets or URIs
185 Type is the link type
191 my %args = ( Base => undef,
196 my $base = RT::URI->new($self->CurrentUser);
197 $base->FromURI( $args{'Base'} );
199 my $target = RT::URI->new($self->CurrentUser);
200 $target->FromURI( $args{'Target'} );
202 unless ($base->Resolver && $target->Resolver) {
203 return ( 0, $self->loc("Couldn't load link") );
207 my ( $id, $msg ) = $self->LoadByCols( Base => $base->URI,
208 Type => $args{'Type'},
209 Target => $target->URI );
212 return ( 0, $self->loc("Couldn't load link") );
221 Load an RT::Link object from the database. Takes one parameter, the id of an entry in the links table.
228 my $identifier = shift;
233 if ( $identifier !~ /^\d+$/ ) {
234 return ( 0, $self->loc("That's not a numerical id") );
237 my ( $id, $msg ) = $self->LoadById($identifier);
238 unless ( $self->Id ) {
239 return ( 0, $self->loc("Couldn't load link") );
241 return ( $id, $msg );
252 returns an RT::URI object for the "Target" of this link.
258 my $URI = RT::URI->new($self->CurrentUser);
259 $URI->FromURI($self->Target);
272 return $self->TargetURI->Object;
280 returns an RT::URI object for the "Base" of this link.
286 my $URI = RT::URI->new($self->CurrentUser);
287 $URI->FromURI($self->Base);
300 return $self->BaseURI->Object;
308 # {{{ sub BaseIsLocal
312 Returns true if the base of this link is a local ticket
318 $RT::Logger->crit("Link::BaseIsLocal is deprecated in favor of Link->BaseURI->IsLocal at (". join(":",caller).")");
319 return $self->BaseURI->IsLocal;
324 # {{{ sub TargetIsLocal
328 Returns true if the target of this link is a local ticket
334 $RT::Logger->crit("Link::BaseIsLocal is deprecated in favor of Link->BaseURI->IsLocal at (". join(":",caller).")");
335 return $self->TargetURI->IsLocal;
345 Returns an HTTP url to access the base of this link
351 $RT::Logger->crit("Link::BaseAsHREF deprecated in favor of ->BaseURI->AsHREF at (". join(":",caller).")");
352 return $self->BaseURI->HREF;
356 # {{{ sub TargetAsHREF
360 return an HTTP url to access the target of this link
366 $RT::Logger->crit("Link::TargetAsHREF deprecated in favor of ->TargetURI->AsHREF at (". join(":",caller).")");
367 return $self->TargetURI->HREF;
371 # {{{ sub AsHREF - Converts Link URIs to HTTP URLs
375 Takes a URI and returns an http: url to access that object.
383 $RT::Logger->crit("AsHREF is gone. look at URI::HREF to figure out what to do with \$URI");