+=head2 Create PARAMHASH
+
+Create a new link object. Takes 'Base', 'Target' and 'Type'.
+Returns undef on failure or a Link Id on success.
+
+=cut
+
+sub Create {
+ my $self = shift;
+ my %args = ( Base => undef,
+ Target => undef,
+ Type => undef,
+ @_ );
+
+ my $base = RT::URI->new( $self->CurrentUser );
+ unless ($base->FromURI( $args{'Base'} )) {
+ my $msg = $self->loc("Couldn't resolve base '[_1]' into a URI.", $args{'Base'});
+ $RT::Logger->warning( "$self $msg" );
+ return wantarray ? (undef, $msg) : undef;
+ }
+
+ my $target = RT::URI->new( $self->CurrentUser );
+ unless ($target->FromURI( $args{'Target'} )) {
+ my $msg = $self->loc("Couldn't resolve target '[_1]' into a URI.", $args{'Target'});
+ $RT::Logger->warning( "$self $msg" );
+ return wantarray ? (undef, $msg) : undef;
+ }
+
+ my $base_id = 0;
+ my $target_id = 0;
+
+
+
+
+ if ( $base->IsLocal ) {
+ my $object = $base->Object;
+ unless (UNIVERSAL::can($object, 'Id')) {
+ return (undef, $self->loc("[_1] appears to be a local object, but can't be found in the database", $args{'Base'}));
+
+ }
+ $base_id = $object->Id if UNIVERSAL::isa($object, 'RT::Ticket');
+ }
+ if ( $target->IsLocal ) {
+ my $object = $target->Object;
+ unless (UNIVERSAL::can($object, 'Id')) {
+ return (undef, $self->loc("[_1] appears to be a local object, but can't be found in the database", $args{'Target'}));
+
+ }
+ $target_id = $object->Id if UNIVERSAL::isa($object, 'RT::Ticket');
+ }
+
+ # We don't want references to ourself
+ if ( $base->URI eq $target->URI ) {
+ return ( 0, $self->loc("Can't link a ticket to itself") );
+ }
+
+ # }}}
+
+ my ( $id, $msg ) = $self->SUPER::Create( Base => $base->URI,
+ Target => $target->URI,
+ LocalBase => $base_id,
+ LocalTarget => $target_id,
+ Type => $args{'Type'} );
+ return ( $id, $msg );