[Rt-commit] rt branch, 3.8-trunk, updated. rt-3.8.8-93-g6e3a9d9
Ruslan Zakirov
ruz at bestpractical.com
Fri Jun 18 18:49:40 EDT 2010
The branch, 3.8-trunk has been updated
via 6e3a9d91fb91ebb2a043f5d66ecc8dbb717051cb (commit)
via 977e435b886e27a7316227ad91da4e7620525464 (commit)
via b0833b88848bd2abf1a95c492aceafffae05e7d2 (commit)
via 0d4ee78ffe180e15862b6b9c610c93d0f32be5fe (commit)
from 708a2ba21ea744bbb16c66cd7ff05664e8e97d0f (commit)
Summary of changes:
etc/upgrade/3.8.9/content | 40 +++++++++
lib/RT/URI/fsck_com_rt.pm | 50 ++++-------
lib/RT/URI/t.pm | 31 ++-----
t/api/link.t | 203 +++++++++++++++++++++++++++++++++++++++++++--
4 files changed, 261 insertions(+), 63 deletions(-)
create mode 100644 etc/upgrade/3.8.9/content
- Log -----------------------------------------------------------------
commit 0d4ee78ffe180e15862b6b9c610c93d0f32be5fe
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Fri Jun 18 13:46:37 2010 +0400
retab + minor refactoring
diff --git a/lib/RT/URI/fsck_com_rt.pm b/lib/RT/URI/fsck_com_rt.pm
index d6c194d..840a426 100755
--- a/lib/RT/URI/fsck_com_rt.pm
+++ b/lib/RT/URI/fsck_com_rt.pm
@@ -46,24 +46,16 @@
#
# END BPS TAGGED BLOCK }}}
-package RT::URI::fsck_com_rt;
-
-use RT::Ticket;
-
-use base 'RT::URI::base';
-
use strict;
+use warnings;
-
-
+package RT::URI::fsck_com_rt;
+use base 'RT::URI::base';
=head2 LocalURIPrefix
Returns the prefix for a local URI.
-
-
-
=cut
sub LocalURIPrefix {
@@ -84,20 +76,17 @@ sub ObjectType {
my $type = 'ticket';
if (ref($object) && (ref($object) ne 'RT::Ticket')) {
- $type = ref($object);
+ $type = ref($object);
}
return ($type);
}
-
-
=head2 URIForObject RT::Record
Returns the RT URI for a local RT::Record object
-
=cut
sub URIForObject {
@@ -119,6 +108,7 @@ sub ParseURI {
my $uri = shift;
if ( $uri =~ /^\d+$/ ) {
+ use RT::Ticket;
my $ticket = RT::Ticket->new( $self->CurrentUser );
$ticket->Load( $uri );
$self->{'uri'} = $ticket->URI;
@@ -160,23 +150,20 @@ sub ParseURI {
Returns true if this URI is for a local ticket.
Returns undef otherwise.
-
-
=cut
sub IsLocal {
- my $self = shift;
+ my $self = shift;
my $local_uri_prefix = $self->LocalURIPrefix;
if ( $self->{'uri'} =~ /^\Q$local_uri_prefix/i ) {
return 1;
}
- else {
- return undef;
- }
+ else {
+ return undef;
+ }
}
-
=head2 Object
Returns the object for this URI, if it's local. Otherwise returns undef.
@@ -186,7 +173,6 @@ Returns the object for this URI, if it's local. Otherwise returns undef.
sub Object {
my $self = shift;
return ($self->{'object'});
-
}
=head2 Scheme
@@ -198,7 +184,7 @@ Return the URI scheme for RT records
sub Scheme {
my $self = shift;
- return "fsck.com-rt";
+ return "fsck.com-rt";
}
=head2 HREF
@@ -211,12 +197,14 @@ Otherwise, return its URI
sub HREF {
my $self = shift;
- if ($self->IsLocal && $self->Object && ($self->ObjectType eq 'ticket')) {
- return ( RT->Config->Get('WebURL') . "Ticket/Display.html?id=".$self->Object->Id);
- }
- else {
- return ($self->URI);
+ return $self->URI unless $self->IsLocal;
+
+ my $obj = $self->Object;
+ if ( $obj && $self->ObjectType eq 'ticket' ) {
+ return RT->Config->Get('WebURL') ."Ticket/Display.html?id=". $obj->id;
}
+
+ return $self->URI;
}
=head2 AsString
@@ -228,10 +216,10 @@ Returns either a localized string 'ticket #23' or the full URI if the object is
sub AsString {
my $self = shift;
if ($self->IsLocal && $self->Object) {
- return $self->loc("[_1] #[_2]", $self->ObjectType, $self->Object->Id);
+ return $self->loc("[_1] #[_2]", $self->ObjectType, $self->Object->Id);
}
else {
- return $self->URI;
+ return $self->URI;
}
}
commit b0833b88848bd2abf1a95c492aceafffae05e7d2
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Fri Jun 18 13:48:24 2010 +0400
add links API tests
diff --git a/t/api/link.t b/t/api/link.t
index 1fd66bb..eac9ae2 100644
--- a/t/api/link.t
+++ b/t/api/link.t
@@ -1,24 +1,209 @@
use strict;
use warnings;
-use RT;
-use RT::Test tests => 5;
-
-
-{
+use RT::Test tests => 77;
+use RT::Test::Web;
use RT::Link;
my $link = RT::Link->new($RT::SystemUser);
ok (ref $link);
-ok (UNIVERSAL::isa($link, 'RT::Link'));
-ok (UNIVERSAL::isa($link, 'RT::Base'));
-ok (UNIVERSAL::isa($link, 'RT::Record'));
-ok (UNIVERSAL::isa($link, 'DBIx::SearchBuilder::Record'));
+isa_ok( $link, 'RT::Link');
+isa_ok( $link, 'RT::Base');
+isa_ok( $link, 'RT::Record');
+isa_ok( $link, 'DBIx::SearchBuilder::Record');
+
+my $queue = RT::Test->load_or_create_queue(Name => 'General');
+ok($queue->Id, "loaded the General queue");
+
+my $parent = RT::Ticket->new($RT::SystemUser);
+my ($pid, undef, $msg) = $parent->Create(
+ Queue => $queue->id,
+ Subject => 'parent',
+);
+ok $pid, 'created a ticket #'. $pid or diag "error: $msg";
+
+my $child = RT::Ticket->new($RT::SystemUser);
+my ($cid, undef, $msg) = $child->Create(
+ Queue => $queue->id,
+ Subject => 'child',
+);
+ok $cid, 'created a ticket #'. $cid or diag "error: $msg";
+
+{
+ clean_links();
+ my ($status, $msg) = $parent->AddLink;
+ ok(!$status, "didn't create a link: $msg");
+
+ ($status, $msg) = $parent->AddLink( Base => $parent->id );
+ ok(!$status, "didn't create a link: $msg");
+
+ ($status, $msg) = $parent->AddLink( Base => $parent->id, Type => 'HasMember' );
+ ok(!$status, "didn't create a link: $msg");
+}
+
+{
+ clean_links();
+ my ($status, $msg) = $parent->AddLink(
+ Type => 'MemberOf', Base => $child->id,
+ );
+ ok($status, "created a link: $msg");
+
+ my $children = $parent->Members;
+ $children->RedoSearch; $children->GotoFirstItem;
+ is $children->Count, 1, 'link is there';
+
+ my $link = $children->First;
+ ok $link->id, 'correct link';
+
+ is $link->Type, 'MemberOf', 'type';
+ is $link->LocalTarget, $parent->id, 'local target';
+ is $link->LocalBase, $child->id, 'local base';
+ is $link->Target, 'fsck.com-rt://example.com/ticket/'. $parent->id, 'local target';
+ is $link->Base, 'fsck.com-rt://example.com/ticket/'. $child->id, 'local base';
+
+ isa_ok $link->TargetObj, 'RT::Ticket';
+ is $link->TargetObj->id, $parent->id, 'correct ticket';
+
+ isa_ok $link->TargetURI, 'RT::URI';
+ is $link->TargetURI->Scheme, 'fsck.com-rt', 'correct scheme';
+ is $link->TargetURI->URI,
+ 'fsck.com-rt://example.com/ticket/'. $parent->id,
+ 'correct URI'
+ ;
+ ok $link->TargetURI->IsLocal, 'local object';
+ is $link->TargetURI->AsHREF,
+ RT::Test::Web->rt_base_url .'Ticket/Display.html?id='. $parent->id,
+ 'correct href'
+ ;
+
+ isa_ok $link->BaseObj, 'RT::Ticket';
+ is $link->BaseObj->id, $child->id, 'correct ticket';
+
+ isa_ok $link->BaseURI, 'RT::URI';
+ is $link->BaseURI->Scheme, 'fsck.com-rt', 'correct scheme';
+ is $link->BaseURI->URI,
+ 'fsck.com-rt://example.com/ticket/'. $child->id,
+ 'correct URI'
+ ;
+ ok $link->BaseURI->IsLocal, 'local object';
+ is $link->BaseURI->AsHREF,
+ RT::Test::Web->rt_base_url .'Ticket/Display.html?id='. $child->id,
+ 'correct href'
+ ;
+}
+
+{
+ clean_links();
+ my ($status, $msg) = $parent->AddLink(
+ Type => 'MemberOf', Base => $child->URI,
+ );
+ ok($status, "created a link: $msg");
+
+ my $children = $parent->Members;
+ $children->RedoSearch; $children->GotoFirstItem;
+ is $children->Count, 1, 'link is there';
+
+ my $link = $children->First;
+ ok $link->id, 'correct link';
+
+ is $link->Type, 'MemberOf', 'type';
+ is $link->LocalTarget, $parent->id, 'local target';
+ is $link->LocalBase, $child->id, 'local base';
+ is $link->Target, 'fsck.com-rt://example.com/ticket/'. $parent->id, 'local target';
+ is $link->Base, 'fsck.com-rt://example.com/ticket/'. $child->id, 'local base';
+
+ isa_ok $link->TargetObj, 'RT::Ticket';
+ is $link->TargetObj->id, $parent->id, 'correct ticket';
+
+ isa_ok $link->TargetURI, 'RT::URI';
+ is $link->TargetURI->Scheme, 'fsck.com-rt', 'correct scheme';
+ is $link->TargetURI->URI,
+ 'fsck.com-rt://example.com/ticket/'. $parent->id,
+ 'correct URI'
+ ;
+ ok $link->TargetURI->IsLocal, 'local object';
+ is $link->TargetURI->AsHREF,
+ RT::Test::Web->rt_base_url .'Ticket/Display.html?id='. $parent->id,
+ 'correct href'
+ ;
+
+ isa_ok $link->BaseObj, 'RT::Ticket';
+ is $link->BaseObj->id, $child->id, 'correct ticket';
+
+ isa_ok $link->BaseURI, 'RT::URI';
+ is $link->BaseURI->Scheme, 'fsck.com-rt', 'correct scheme';
+ is $link->BaseURI->URI,
+ 'fsck.com-rt://example.com/ticket/'. $child->id,
+ 'correct URI'
+ ;
+ ok $link->BaseURI->IsLocal, 'local object';
+ is $link->BaseURI->AsHREF,
+ RT::Test::Web->rt_base_url .'Ticket/Display.html?id='. $child->id,
+ 'correct href'
+ ;
+}
+
+{
+ clean_links();
+ my ($status, $msg) = $parent->AddLink(
+ Type => 'MemberOf', Base => 't:'. $child->id,
+ );
+ ok($status, "created a link: $msg");
+
+ my $children = $parent->Members;
+ $children->RedoSearch; $children->GotoFirstItem;
+ is $children->Count, 1, 'link is there';
+
+ my $link = $children->First;
+ ok $link->id, 'correct link';
+ is $link->Type, 'MemberOf', 'type';
+ is $link->LocalTarget, $parent->id, 'local target';
+ is $link->LocalBase, $child->id, 'local base';
+ is $link->Target, 'fsck.com-rt://example.com/ticket/'. $parent->id, 'local target';
+ is $link->Base, 'fsck.com-rt://example.com/ticket/'. $child->id, 'local base';
+
+ isa_ok $link->TargetObj, 'RT::Ticket';
+ is $link->TargetObj->id, $parent->id, 'correct ticket';
+
+ isa_ok $link->TargetURI, 'RT::URI';
+ is $link->TargetURI->Scheme, 'fsck.com-rt', 'correct scheme';
+ is $link->TargetURI->URI,
+ 'fsck.com-rt://example.com/ticket/'. $parent->id,
+ 'correct URI'
+ ;
+ ok $link->TargetURI->IsLocal, 'local object';
+ is $link->TargetURI->AsHREF,
+ RT::Test::Web->rt_base_url .'Ticket/Display.html?id='. $parent->id,
+ 'correct href'
+ ;
+
+ isa_ok $link->BaseObj, 'RT::Ticket';
+ is $link->BaseObj->id, $child->id, 'correct ticket';
+
+ isa_ok $link->BaseURI, 'RT::URI';
+ is $link->BaseURI->Scheme, 'fsck.com-rt', 'correct scheme';
+ is $link->BaseURI->URI,
+ 'fsck.com-rt://example.com/ticket/'. $child->id,
+ 'correct URI'
+ ;
+ ok $link->BaseURI->IsLocal, 'local object';
+ is $link->BaseURI->AsHREF,
+ RT::Test::Web->rt_base_url .'Ticket/Display.html?id='. $child->id,
+ 'correct href'
+ ;
+}
+sub clean_links {
+ my $links = RT::Links->new( $RT::SystemUser );
+ while ( my $link = $links->Next ) {
+ my ($status, $msg) = $link->Delete;
+ $RT::Logger->error("Couldn't delete a link: $msg")
+ unless $status;
+ }
}
1;
commit 977e435b886e27a7316227ad91da4e7620525464
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Fri Jun 18 13:49:40 2010 +0400
make t: links just an alias for fsck_com_rt:, fix local detection
diff --git a/lib/RT/URI/t.pm b/lib/RT/URI/t.pm
index 9b0dcbe..47805b8 100644
--- a/lib/RT/URI/t.pm
+++ b/lib/RT/URI/t.pm
@@ -69,48 +69,33 @@
#
#
# END LICENSE BLOCK
-package RT::URI::t;
-
-use RT::Ticket;
-use RT::URI::base;
use strict;
+use warnings;
+
+package RT::URI::t;
use base 'RT::URI::fsck_com_rt';
-my $scheme = "t";
+=head1 NAME
+
+RT::URI::t - aliad for RT::URI::fsck_com_rt that supports 't:12345' URIs
=head2 ParseURI URI
When handed an t: URI, figures out if it is an RT ticket. This is an
alternate short form of specifying a full ticket URI.
-
=cut
sub ParseURI {
my $self = shift;
my $uri = shift;
- # "t:<articlenum>"
# Pass this off to fsck_com_rt, which is equipped to deal with
# tickets after stripping off the t: prefix.
- if ($uri =~ /^$scheme:(\d+)/) {
- return $self->SUPER::ParseURI($1);
- } else {
- $self->{'uri'} = $uri;
- return undef;
- }
-}
-
-=head2 Scheme
-
-Return the URI scheme
-
-=cut
-
-sub Scheme {
- return $scheme;
+ $uri =~ s/^t://;
+ return $self->SUPER::ParseURI($uri);
}
1;
commit 6e3a9d91fb91ebb2a043f5d66ecc8dbb717051cb
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Sat Jun 19 02:49:27 2010 +0400
upgrade script that deals with local links that are not local
diff --git a/etc/upgrade/3.8.9/content b/etc/upgrade/3.8.9/content
new file mode 100644
index 0000000..5c42b78
--- /dev/null
+++ b/etc/upgrade/3.8.9/content
@@ -0,0 +1,40 @@
+ at Initial = (
+ sub {
+ use strict;
+ $RT::Logger->debug('Make sure local links are local');
+
+ use RT::URI::fsck_com_rt;
+ my $prefix = RT::URI::fsck_com_rt->LocalURIPrefix . '/ticket/';
+
+ foreach my $dir (qw(Target Base)) {
+ my $found;
+ do {
+ $found = 0;
+ my $links = RT::Links->new( $RT::SystemUser );
+ $links->Limit( FIELD => $dir, OPERATOR => 'STARTSWITH', VALUE => $prefix );
+ $links->Limit( FIELD => 'Local'.$dir, VALUE => 0 );
+ $links->Limit(
+ ENTRYAGGREGATOR => 'OR',
+ FIELD => 'Local'.$dir,
+ OPERATOR => 'IS',
+ VALUE => 'NULL',
+ );
+ $links->RowsPerPage( 1000 );
+ while ( my $link = $links->Next ) {
+ $found++;
+ my $uri = $link->$dir();
+ $uri =~ s/^\Q$prefix//;
+ if ( int($uri) eq $uri && $uri > 0 ) {
+ my $method = 'SetLocal'. $dir;
+ my ($status, $msg) = $link->$method( $uri );
+ unless ( $status ) {
+ die "Couldn't change local $dir: $msg";
+ }
+ } else {
+ die "$dir URI looks like local, but is not parseable";
+ }
+ }
+ } while $found == 1000;
+ }
+ },
+);
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list