1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2012 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 $base->FromURI( $args{'Base'} );
101 unless ( $base->Resolver && $base->Scheme ) {
102 my $msg = $self->loc("Couldn't resolve base '[_1]' into a URI.",
104 $RT::Logger->warning( "$self $msg" );
113 my $target = RT::URI->new( $self->CurrentUser );
114 $target->FromURI( $args{'Target'} );
116 unless ( $target->Resolver ) {
117 my $msg = $self->loc("Couldn't resolve target '[_1]' into a URI.",
119 $RT::Logger->warning( "$self $msg" );
134 if ( $base->IsLocal ) {
135 my $object = $base->Object;
136 unless (UNIVERSAL::can($object, 'Id')) {
137 return (undef, $self->loc("[_1] appears to be a local object, but can't be found in the database", $args{'Base'}));
140 $base_id = $object->Id if UNIVERSAL::isa($object, 'RT::Ticket');
142 if ( $target->IsLocal ) {
143 my $object = $target->Object;
144 unless (UNIVERSAL::can($object, 'Id')) {
145 return (undef, $self->loc("[_1] appears to be a local object, but can't be found in the database", $args{'Target'}));
148 $target_id = $object->Id if UNIVERSAL::isa($object, 'RT::Ticket');
151 # We don't want references to ourself
152 if ( $base->URI eq $target->URI ) {
153 return ( 0, $self->loc("Can't link a ticket to itself") );
158 my ( $id, $msg ) = $self->SUPER::Create( Base => $base->URI,
159 Target => $target->URI,
160 LocalBase => $base_id,
161 LocalTarget => $target_id,
162 Type => $args{'Type'} );
163 return ( $id, $msg );
170 Load an RT::Link object from the database. Takes three parameters
176 Base and Target are expected to be integers which refer to Tickets or URIs
177 Type is the link type
183 my %args = ( Base => undef,
188 my $base = RT::URI->new($self->CurrentUser);
189 $base->FromURI( $args{'Base'} );
191 my $target = RT::URI->new($self->CurrentUser);
192 $target->FromURI( $args{'Target'} );
194 unless ($base->Resolver && $target->Resolver) {
195 return ( 0, $self->loc("Couldn't load link") );
199 my ( $id, $msg ) = $self->LoadByCols( Base => $base->URI,
200 Type => $args{'Type'},
201 Target => $target->URI );
204 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 );
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);
258 return $self->TargetURI->Object;
264 returns an RT::URI object for the "Base" of this link.
270 my $URI = RT::URI->new($self->CurrentUser);
271 $URI->FromURI($self->Base);
282 return $self->BaseURI->Object;
288 Returns the current value of id.
289 (In the database, id is stored as int(11).)
297 Returns the current value of Base.
298 (In the database, Base is stored as varchar(240).)
306 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
307 (In the database, Base will be stored as a varchar(240).)
315 Returns the current value of Target.
316 (In the database, Target is stored as varchar(240).)
320 =head2 SetTarget VALUE
324 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
325 (In the database, Target will be stored as a varchar(240).)
333 Returns the current value of Type.
334 (In the database, Type is stored as varchar(20).)
342 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
343 (In the database, Type will be stored as a varchar(20).)
351 Returns the current value of LocalTarget.
352 (In the database, LocalTarget is stored as int(11).)
356 =head2 SetLocalTarget VALUE
359 Set LocalTarget to VALUE.
360 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
361 (In the database, LocalTarget will be stored as a int(11).)
369 Returns the current value of LocalBase.
370 (In the database, LocalBase is stored as int(11).)
374 =head2 SetLocalBase VALUE
377 Set LocalBase to VALUE.
378 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
379 (In the database, LocalBase will be stored as a int(11).)
387 Returns the current value of LastUpdatedBy.
388 (In the database, LastUpdatedBy is stored as int(11).)
396 Returns the current value of LastUpdated.
397 (In the database, LastUpdated is stored as datetime.)
405 Returns the current value of Creator.
406 (In the database, Creator is stored as int(11).)
414 Returns the current value of Created.
415 (In the database, Created is stored as datetime.)
422 sub _CoreAccessible {
426 {read => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => ''},
428 {read => 1, write => 1, sql_type => 12, length => 240, is_blob => 0, is_numeric => 0, type => 'varchar(240)', default => ''},
430 {read => 1, write => 1, sql_type => 12, length => 240, is_blob => 0, is_numeric => 0, type => 'varchar(240)', default => ''},
432 {read => 1, write => 1, sql_type => 12, length => 20, is_blob => 0, is_numeric => 0, type => 'varchar(20)', default => ''},
434 {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
436 {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
438 {read => 1, auto => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
440 {read => 1, auto => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
442 {read => 1, auto => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
444 {read => 1, auto => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
449 RT::Base->_ImportOverlays();