summaryrefslogtreecommitdiff
path: root/rt/lib/RT/Links.pm
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2012-06-07 00:56:06 -0700
committerIvan Kohler <ivan@freeside.biz>2012-06-07 00:56:06 -0700
commit43a06151e47d2c59b833cbd8c26d97865ee850b6 (patch)
tree42c51d94e7fa265461b508d061562be204ccc2c1 /rt/lib/RT/Links.pm
parent6587f6ba7d047ddc1686c080090afe7d53365bd4 (diff)
starting to work...
Diffstat (limited to 'rt/lib/RT/Links.pm')
-rw-r--r--rt/lib/RT/Links.pm125
1 files changed, 94 insertions, 31 deletions
diff --git a/rt/lib/RT/Links.pm b/rt/lib/RT/Links.pm
index d8b602587..0d8ed2f11 100644
--- a/rt/lib/RT/Links.pm
+++ b/rt/lib/RT/Links.pm
@@ -2,7 +2,7 @@
#
# COPYRIGHT:
#
-# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
+# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
# <sales@bestpractical.com>
#
# (Except where explicitly superseded by other copyright notices)
@@ -46,48 +46,97 @@
#
# END BPS TAGGED BLOCK }}}
-# Autogenerated by DBIx::SearchBuilder factory (by <jesse@bestpractical.com>)
-# WARNING: THIS FILE IS AUTOGENERATED. ALL CHANGES TO THIS FILE WILL BE LOST.
-#
-# !! DO NOT EDIT THIS FILE !!
-#
-
-use strict;
-
-
=head1 NAME
- RT::Links -- Class Description
-
+ RT::Links - A collection of Link objects
+
=head1 SYNOPSIS
- use RT::Links
+ use RT::Links;
+ my $links = RT::Links->new($CurrentUser);
=head1 DESCRIPTION
=head1 METHODS
+
+
=cut
+
package RT::Links;
-use RT::SearchBuilder;
+use strict;
+use warnings;
+
+
use RT::Link;
-use vars qw( @ISA );
-@ISA= qw(RT::SearchBuilder);
+use base 'RT::SearchBuilder';
+
+sub Table { 'Links'}
-sub _Init {
+use RT::URI;
+
+sub Limit {
my $self = shift;
- $self->{'table'} = 'Links';
- $self->{'primary_key'} = 'id';
+ my %args = ( ENTRYAGGREGATOR => 'AND',
+ OPERATOR => '=',
+ @_);
+
+ # If we're limiting by target, order by base
+ # (Order by the thing that's changing)
+
+ if ( ($args{'FIELD'} eq 'Target') or
+ ($args{'FIELD'} eq 'LocalTarget') ) {
+ $self->OrderBy (ALIAS => 'main',
+ FIELD => 'Base',
+ ORDER => 'ASC');
+ }
+ elsif ( ($args{'FIELD'} eq 'Base') or
+ ($args{'FIELD'} eq 'LocalBase') ) {
+ $self->OrderBy (ALIAS => 'main',
+ FIELD => 'Target',
+ ORDER => 'ASC');
+ }
+
+
+ $self->SUPER::Limit(%args);
+}
- return ( $self->SUPER::_Init(@_) );
+=head2 LimitRefersTo URI
+
+find all things that refer to URI
+
+=cut
+
+sub LimitRefersTo {
+ my $self = shift;
+ my $URI = shift;
+
+ $self->Limit(FIELD => 'Type', VALUE => 'RefersTo');
+ $self->Limit(FIELD => 'Target', VALUE => $URI);
+}
+
+
+=head2 LimitReferredToBy URI
+
+find all things that URI refers to
+
+=cut
+
+sub LimitReferredToBy {
+ my $self = shift;
+ my $URI = shift;
+
+ $self->Limit(FIELD => 'Type', VALUE => 'RefersTo');
+ $self->Limit(FIELD => 'Base', VALUE => $URI);
}
+# }}}
=head2 NewItem
@@ -99,25 +148,39 @@ sub NewItem {
my $self = shift;
return(RT::Link->new($self->CurrentUser));
}
-RT::Base->_ImportOverlays();
-=head1 SEE ALSO
+sub AddRecord {
+ my $self = shift;
+ my $record = shift;
+ return unless $self->IsValidLink($record);
-This class allows "overlay" methods to be placed
-into the following files _Overlay is for a System overlay by the original author,
-_Vendor is for 3rd-party vendor add-ons, while _Local is for site-local customizations.
+ push @{$self->{'items'}}, $record;
+ $self->{'rows'}++;
+}
-These overlay files can contain new subs or subs to replace existing subs in this module.
+=head2 IsValidLink
-Each of these files should begin with the line
+if linked to a local ticket and is deleted, then the link is invalid.
- no warnings qw(redefine);
+=cut
-so that perl does not kick and scream when you redefine a subroutine or variable in your overlay.
+sub IsValidLink {
+ my $self = shift;
+ my $link = shift;
-RT::Links_Overlay, RT::Links_Vendor, RT::Links_Local
+ return unless $link && ref $link && $link->Target && $link->Base;
-=cut
+ # Skip links to local objects thast are deleted
+ return
+ if $link->TargetURI->IsLocal
+ && ( UNIVERSAL::isa( $link->TargetObj, "RT::Ticket" )
+ && $link->TargetObj->__Value('status') eq "deleted"
+ || UNIVERSAL::isa( $link->BaseObj, "RT::Ticket" )
+ && $link->BaseObj->__Value('status') eq "deleted" );
+
+ return 1;
+}
+RT::Base->_ImportOverlays();
1;