1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
6 # <sales@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/licenses/old-licenses/gpl-2.0.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 }}}
51 RT::Link - an RT Link object
59 This module should never be called directly by client code. it's an internal module which
60 should only be accessed through exported APIs in Ticket other similar objects.
72 no warnings qw(redefine);
81 =head2 Create PARAMHASH
83 Create a new link object. Takes 'Base', 'Target' and 'Type'.
84 Returns undef on failure or a Link Id on success.
90 my %args = ( Base => undef,
95 my $base = RT::URI->new( $self->CurrentUser );
96 $base->FromURI( $args{'Base'} );
98 unless ( $base->Resolver && $base->Scheme ) {
99 my $msg = $self->loc("Couldn't resolve base '[_1]' into a URI.",
101 $RT::Logger->warning( "$self $msg" );
110 my $target = RT::URI->new( $self->CurrentUser );
111 $target->FromURI( $args{'Target'} );
113 unless ( $target->Resolver ) {
114 my $msg = $self->loc("Couldn't resolve target '[_1]' into a URI.",
116 $RT::Logger->warning( "$self $msg" );
131 if ( $base->IsLocal ) {
132 my $object = $base->Object;
133 unless (UNIVERSAL::can($object, 'Id')) {
134 return (undef, $self->loc("[_1] appears to be a local object, but can't be found in the database", $args{'Base'}));
137 $base_id = $object->Id if UNIVERSAL::isa($object, 'RT::Ticket');
139 if ( $target->IsLocal ) {
140 my $object = $target->Object;
141 unless (UNIVERSAL::can($object, 'Id')) {
142 return (undef, $self->loc("[_1] appears to be a local object, but can't be found in the database", $args{'Target'}));
145 $target_id = $object->Id if UNIVERSAL::isa($object, 'RT::Ticket');
148 # {{{ We don't want references to ourself
149 if ( $base->URI eq $target->URI ) {
150 return ( 0, $self->loc("Can't link a ticket to itself") );
155 my ( $id, $msg ) = $self->SUPER::Create( Base => $base->URI,
156 Target => $target->URI,
157 LocalBase => $base_id,
158 LocalTarget => $target_id,
159 Type => $args{'Type'} );
160 return ( $id, $msg );
164 # {{{ sub LoadByParams
168 Load an RT::Link object from the database. Takes three parameters
174 Base and Target are expected to be integers which refer to Tickets or URIs
175 Type is the link type
181 my %args = ( Base => undef,
186 my $base = RT::URI->new($self->CurrentUser);
187 $base->FromURI( $args{'Base'} );
189 my $target = RT::URI->new($self->CurrentUser);
190 $target->FromURI( $args{'Target'} );
192 unless ($base->Resolver && $target->Resolver) {
193 return ( 0, $self->loc("Couldn't load link") );
197 my ( $id, $msg ) = $self->LoadByCols( Base => $base->URI,
198 Type => $args{'Type'},
199 Target => $target->URI );
202 return ( 0, $self->loc("Couldn't load link") );
211 Load an RT::Link object from the database. Takes one parameter, the id of an entry in the links table.
218 my $identifier = shift;
223 if ( $identifier !~ /^\d+$/ ) {
224 return ( 0, $self->loc("That's not a numerical id") );
227 my ( $id, $msg ) = $self->LoadById($identifier);
228 unless ( $self->Id ) {
229 return ( 0, $self->loc("Couldn't load link") );
231 return ( $id, $msg );
242 returns an RT::URI object for the "Target" of this link.
248 my $URI = RT::URI->new($self->CurrentUser);
249 $URI->FromURI($self->Target);
262 return $self->TargetURI->Object;
270 returns an RT::URI object for the "Base" of this link.
276 my $URI = RT::URI->new($self->CurrentUser);
277 $URI->FromURI($self->Base);
290 return $self->BaseURI->Object;