1 # {{{ BEGIN BPS TAGGED BLOCK
5 # This software is Copyright (c) 1996-2004 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
48 RT::Link - an RT Link object
56 This module should never be called directly by client code. it's an internal module which
57 should only be accessed through exported APIs in Ticket other similar objects.
66 my $link = RT::Link->new($RT::SystemUser);
70 ok (UNIVERSAL::isa($link, 'RT::Link'));
71 ok (UNIVERSAL::isa($link, 'RT::Base'));
72 ok (UNIVERSAL::isa($link, 'RT::Record'));
73 ok (UNIVERSAL::isa($link, 'DBIx::SearchBuilder::Record'));
80 no warnings qw(redefine);
89 =head2 Create PARAMHASH
91 Create a new link object. Takes 'Base', 'Target' and 'Type'.
92 Returns undef on failure or a Link Id on success.
98 my %args = ( Base => undef,
103 my $base = RT::URI->new( $self->CurrentUser );
104 $base->FromURI( $args{'Base'} );
106 unless ( $base->Resolver and $base->Scheme ) {
107 $RT::Logger->warning( "$self couldn't resolve base:'"
108 . $args{'Base'} . " - "
109 . "' into a URI\n" );
114 my $target = RT::URI->new( $self->CurrentUser );
115 $target->FromURI( $args{'Target'} );
117 unless ( $target->Resolver ) {
118 $RT::Logger->warning( "$self couldn't resolve target:'"
119 . $args{'Target'} . " - "
120 . "' into a URI\n" );
131 if ( $base->IsLocal ) {
132 unless (UNIVERSAL::can($base->Object, 'Id')) {
133 return (undef, $self->loc("[_1] appears to be a local object, but can't be found in the database", $args{'Base'}));
136 $base_id = $base->Object->Id;
138 if ( $target->IsLocal ) {
139 unless (UNIVERSAL::can($target->Object, 'Id')) {
140 return (undef, $self->loc("[_1] appears to be a local object, but can't be found in the database", $args{'Target'}));
143 $target_id = $target->Object->Id;
146 # {{{ We don't want references to ourself
147 if ( $base->URI eq $target->URI ) {
148 return ( 0, $self->loc("Can't link a ticket to itself") );
153 my ( $id, $msg ) = $self->SUPER::Create( Base => $base->URI,
154 Target => $target->URI,
155 LocalBase => $base_id,
156 LocalTarget => $target_id,
157 Type => $args{'Type'} );
158 return ( $id, $msg );
162 # {{{ sub LoadByParams
166 Load an RT::Link object from the database. Takes three parameters
172 Base and Target are expected to be integers which refer to Tickets or URIs
173 Type is the link type
179 my %args = ( Base => undef,
184 my $base = RT::URI->new($self->CurrentUser);
185 $base->FromURI( $args{'Base'} );
187 my $target = RT::URI->new($self->CurrentUser);
188 $target->FromURI( $args{'Target'} );
190 unless ($base->Resolver && $target->Resolver) {
191 return ( 0, $self->loc("Couldn't load link") );
195 my ( $id, $msg ) = $self->LoadByCols( Base => $base->URI,
196 Type => $args{'Type'},
197 Target => $target->URI );
200 return ( 0, $self->loc("Couldn't load link") );
209 Load an RT::Link object from the database. Takes one parameter, the id of an entry in the links table.
216 my $identifier = shift;
221 if ( $identifier !~ /^\d+$/ ) {
222 return ( 0, $self->loc("That's not a numerical id") );
225 my ( $id, $msg ) = $self->LoadById($identifier);
226 unless ( $self->Id ) {
227 return ( 0, $self->loc("Couldn't load link") );
229 return ( $id, $msg );
240 returns an RT::URI object for the "Target" of this link.
246 my $URI = RT::URI->new($self->CurrentUser);
247 $URI->FromURI($self->Target);
260 return $self->TargetURI->Object;
268 returns an RT::URI object for the "Base" of this link.
274 my $URI = RT::URI->new($self->CurrentUser);
275 $URI->FromURI($self->Base);
288 return $self->BaseURI->Object;
296 # {{{ sub BaseIsLocal
300 Returns true if the base of this link is a local ticket
306 $RT::Logger->crit("Link::BaseIsLocal is deprecated in favor of Link->BaseURI->IsLocal");
307 return $self->BaseURI->IsLocal;
312 # {{{ sub TargetIsLocal
316 Returns true if the target of this link is a local ticket
322 $RT::Logger->crit("Link::BaseIsLocal is deprecated in favor of Link->BaseURI->IsLocal");
323 return $self->TargetURI->IsLocal;
333 Returns an HTTP url to access the base of this link
339 $RT::Logger->crit("Link::BaseAsHREF deprecated in favor of ->BaseURI->AsHREF");
340 return $self->BaseURI->HREF;
344 # {{{ sub TargetAsHREF
348 return an HTTP url to access the target of this link
354 $RT::Logger->crit("Link::TargetAsHREF deprecated in favor of ->TargetURI->AsHREF");
355 return $self->TargetURI->HREF;
359 # {{{ sub AsHREF - Converts Link URIs to HTTP URLs
363 Takes a URI and returns an http: url to access that object.
371 $RT::Logger->crit("AsHREF is gone. look at URI::HREF to figure out what to do with \$URI");