1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2014 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.
76 use base 'RT::Record';
84 =head2 Create PARAMHASH
86 Create a new link object. Takes 'Base', 'Target' and 'Type'.
87 Returns undef on failure or a Link Id on success.
93 my %args = ( Base => undef,
98 my $base = RT::URI->new( $self->CurrentUser );
99 unless ($base->FromURI( $args{'Base'} )) {
100 my $msg = $self->loc("Couldn't resolve base '[_1]' into a URI.", $args{'Base'});
101 $RT::Logger->warning( "$self $msg" );
102 return wantarray ? (undef, $msg) : undef;
105 my $target = RT::URI->new( $self->CurrentUser );
106 unless ($target->FromURI( $args{'Target'} )) {
107 my $msg = $self->loc("Couldn't resolve target '[_1]' into a URI.", $args{'Target'});
108 $RT::Logger->warning( "$self $msg" );
109 return wantarray ? (undef, $msg) : undef;
118 if ( $base->IsLocal ) {
119 my $object = $base->Object;
120 unless (UNIVERSAL::can($object, 'Id')) {
121 return (undef, $self->loc("[_1] appears to be a local object, but can't be found in the database", $args{'Base'}));
124 $base_id = $object->Id if UNIVERSAL::isa($object, 'RT::Ticket');
126 if ( $target->IsLocal ) {
127 my $object = $target->Object;
128 unless (UNIVERSAL::can($object, 'Id')) {
129 return (undef, $self->loc("[_1] appears to be a local object, but can't be found in the database", $args{'Target'}));
132 $target_id = $object->Id if UNIVERSAL::isa($object, 'RT::Ticket');
135 # We don't want references to ourself
136 if ( $base->URI eq $target->URI ) {
137 return ( 0, $self->loc("Can't link a ticket to itself") );
142 my ( $id, $msg ) = $self->SUPER::Create( Base => $base->URI,
143 Target => $target->URI,
144 LocalBase => $base_id,
145 LocalTarget => $target_id,
146 Type => $args{'Type'} );
147 return ( $id, $msg );
154 Load an RT::Link object from the database. Takes three parameters
160 Base and Target are expected to be integers which refer to Tickets or URIs
161 Type is the link type
167 my %args = ( Base => undef,
172 my $base = RT::URI->new($self->CurrentUser);
173 $base->FromURI( $args{'Base'} )
174 or return (0, $self->loc("Couldn't parse Base URI: [_1]", $args{Base}));
176 my $target = RT::URI->new($self->CurrentUser);
177 $target->FromURI( $args{'Target'} )
178 or return (0, $self->loc("Couldn't parse Target URI: [_1]", $args{Target}));
180 my ( $id, $msg ) = $self->LoadByCols( Base => $base->URI,
181 Type => $args{'Type'},
182 Target => $target->URI );
185 return ( 0, $self->loc("Couldn't load link: [_1]", $msg) );
194 Load an RT::Link object from the database. Takes one parameter, the id of an entry in the links table.
201 my $identifier = shift;
206 if ( $identifier !~ /^\d+$/ ) {
207 return ( 0, $self->loc("That's not a numerical id") );
210 my ( $id, $msg ) = $self->LoadById($identifier);
211 unless ( $self->Id ) {
212 return ( 0, $self->loc("Couldn't load link") );
214 return ( $id, $msg );
223 returns an RT::URI object for the "Target" of this link.
229 my $URI = RT::URI->new($self->CurrentUser);
230 $URI->FromURI($self->Target);
241 return $self->TargetURI->Object;
247 returns an RT::URI object for the "Base" of this link.
253 my $URI = RT::URI->new($self->CurrentUser);
254 $URI->FromURI($self->Base);
265 return $self->BaseURI->Object;
271 Returns the current value of id.
272 (In the database, id is stored as int(11).)
280 Returns the current value of Base.
281 (In the database, Base is stored as varchar(240).)
289 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
290 (In the database, Base will be stored as a varchar(240).)
298 Returns the current value of Target.
299 (In the database, Target is stored as varchar(240).)
303 =head2 SetTarget VALUE
307 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
308 (In the database, Target will be stored as a varchar(240).)
316 Returns the current value of Type.
317 (In the database, Type is stored as varchar(20).)
325 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
326 (In the database, Type will be stored as a varchar(20).)
334 Returns the current value of LocalTarget.
335 (In the database, LocalTarget is stored as int(11).)
339 =head2 SetLocalTarget VALUE
342 Set LocalTarget to VALUE.
343 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
344 (In the database, LocalTarget will be stored as a int(11).)
352 Returns the current value of LocalBase.
353 (In the database, LocalBase is stored as int(11).)
357 =head2 SetLocalBase VALUE
360 Set LocalBase to VALUE.
361 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
362 (In the database, LocalBase will be stored as a int(11).)
370 Returns the current value of LastUpdatedBy.
371 (In the database, LastUpdatedBy is stored as int(11).)
379 Returns the current value of LastUpdated.
380 (In the database, LastUpdated is stored as datetime.)
388 Returns the current value of Creator.
389 (In the database, Creator is stored as int(11).)
397 Returns the current value of Created.
398 (In the database, Created is stored as datetime.)
405 sub _CoreAccessible {
409 {read => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => ''},
411 {read => 1, write => 1, sql_type => 12, length => 240, is_blob => 0, is_numeric => 0, type => 'varchar(240)', default => ''},
413 {read => 1, write => 1, sql_type => 12, length => 240, is_blob => 0, is_numeric => 0, type => 'varchar(240)', default => ''},
415 {read => 1, write => 1, sql_type => 12, length => 20, is_blob => 0, is_numeric => 0, type => 'varchar(20)', default => ''},
417 {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
419 {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
421 {read => 1, auto => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
423 {read => 1, auto => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
425 {read => 1, auto => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
427 {read => 1, auto => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
432 RT::Base->_ImportOverlays();