[Rt-commit] rt branch, 4.2/record-class-on-collection, created. rt-4.1.13-30-gc72b8b6
Thomas Sibley
trs at bestpractical.com
Tue Jul 2 13:02:37 EDT 2013
The branch, 4.2/record-class-on-collection has been created
at c72b8b6d6242023bc02c2e2486d0204560055e05 (commit)
- Log -----------------------------------------------------------------
commit 0c23acb1a6bfcb795d9560f46e99dd521d82bb71
Author: Thomas Sibley <trs at bestpractical.com>
Date: Thu Jun 27 16:37:30 2013 -0700
Refactor and move RecordClass into RT::SearchBuilder
_SingularClass provides the same functionality, but we use the term
RecordClass elsewhere (RT::SharedSetting and subclasses and
RT::SearchBuilder::AddAndSort).
RecordClass is easier to remember and not private.
diff --git a/lib/RT/SearchBuilder.pm b/lib/RT/SearchBuilder.pm
index f9894e9..400f0ba 100644
--- a/lib/RT/SearchBuilder.pm
+++ b/lib/RT/SearchBuilder.pm
@@ -253,6 +253,17 @@ sub _SingularClass {
return $class;
}
+=head2 RecordClass
+
+Returns class name of records in this collection. This generic implementation
+just strips trailing 's'.
+
+=cut
+
+sub RecordClass {
+ $_[0]->_SingularClass
+}
+
=head2 _CustomFieldJoin
Factor out the Join of custom fields so we can use it for sorting too
diff --git a/lib/RT/SearchBuilder/AddAndSort.pm b/lib/RT/SearchBuilder/AddAndSort.pm
index 3d8ef11..2743ee8 100644
--- a/lib/RT/SearchBuilder/AddAndSort.pm
+++ b/lib/RT/SearchBuilder/AddAndSort.pm
@@ -84,19 +84,6 @@ sub _Init {
return $self->SUPER::_Init(@_);
}
-=head2 RecordClass
-
-Returns class name of records in this collection. This generic implementation
-just strips trailing 's'.
-
-=cut
-
-sub RecordClass {
- my $class = ref($_[0]) || $_[0];
- $class =~ s/s$// or return undef;
- return $class;
-}
-
=head2 LimitToObjectId
Takes id of an object and limits collection.
commit 491107d212818f65efeea2f3ecb81b45e8f05bb0
Author: Thomas Sibley <trs at bestpractical.com>
Date: Mon Jul 1 15:59:05 2013 -0700
Add _SingularClasses for those collections which can't be s/s$//
diff --git a/lib/RT/ACL.pm b/lib/RT/ACL.pm
index 97c7d0e..8274c93 100644
--- a/lib/RT/ACL.pm
+++ b/lib/RT/ACL.pm
@@ -228,6 +228,10 @@ sub NewItem {
my $self = shift;
return(RT::ACE->new($self->CurrentUser));
}
+
+# The singular of ACL is ACE.
+sub _SingularClass { "RT::ACE" }
+
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/ObjectClasses.pm b/lib/RT/ObjectClasses.pm
index 01cf77f..5d48b6a 100644
--- a/lib/RT/ObjectClasses.pm
+++ b/lib/RT/ObjectClasses.pm
@@ -81,6 +81,8 @@ sub NewItem {
return(RT::ObjectClass->new($self->CurrentUser));
}
+sub _SingularClass { "RT::ObjectClass" }
+
RT::Base->_ImportOverlays();
diff --git a/lib/RT/Report/Tickets.pm b/lib/RT/Report/Tickets.pm
index 43e7fba..02217f3 100644
--- a/lib/RT/Report/Tickets.pm
+++ b/lib/RT/Report/Tickets.pm
@@ -292,6 +292,8 @@ sub NewItem {
return RT::Report::Tickets::Entry->new(RT->SystemUser); # $self->CurrentUser);
}
+sub _SingularClass { "RT::Report::Tickets::Entry" }
+
# This is necessary since normally NewItem (above) is used to intuit the
# correct class. However, since we're abusing a subclass, it's incorrect.
sub _RoleGroupClass { "RT::Ticket" }
commit 62a293e09c4f762f8d37dc272d98ee4ed894841d
Author: Thomas Sibley <trs at bestpractical.com>
Date: Mon Jul 1 16:19:33 2013 -0700
Use ->RecordClass where possible in favor of ->NewItem
diff --git a/lib/RT/SearchBuilder.pm b/lib/RT/SearchBuilder.pm
index 400f0ba..76b2ab5 100644
--- a/lib/RT/SearchBuilder.pm
+++ b/lib/RT/SearchBuilder.pm
@@ -122,6 +122,7 @@ sub JoinTransactions {
FIELD2 => 'ObjectId',
);
+ # NewItem is necessary here because of RT::Report::Tickets and RT::Report::Tickets::Entry
my $item = $self->NewItem;
my $object_type = $item->can('ObjectType') ? $item->ObjectType : ref $item;
@@ -340,7 +341,7 @@ sub _CustomFieldJoinByName {
LEFTJOIN => $CFs,
ENTRYAGGREGATOR => 'AND',
FIELD => 'LookupType',
- VALUE => $self->NewItem->CustomFieldLookupType,
+ VALUE => $self->RecordClass->CustomFieldLookupType,
);
$self->Limit(
LEFTJOIN => $CFs,
@@ -858,10 +859,10 @@ sub ItemsOrderBy {
my $self = shift;
my $items = shift;
- if ($self->NewItem()->_Accessible('SortOrder','read')) {
+ if ($self->RecordClass->_Accessible('SortOrder','read')) {
$items = [ sort { $a->SortOrder <=> $b->SortOrder } @{$items} ];
}
- elsif ($self->NewItem()->_Accessible('Name','read')) {
+ elsif ($self->RecordClass->_Accessible('Name','read')) {
$items = [ sort { lc($a->Name) cmp lc($b->Name) } @{$items} ];
}
diff --git a/lib/RT/SearchBuilder/Role/Roles.pm b/lib/RT/SearchBuilder/Role/Roles.pm
index 4a1d02b..63bbcb4 100644
--- a/lib/RT/SearchBuilder/Role/Roles.pm
+++ b/lib/RT/SearchBuilder/Role/Roles.pm
@@ -83,7 +83,7 @@ limiting on L<RT::Queue> roles while searching for L<RT::Ticket>s.
The default implementation is:
- blessed($self->NewItem)
+ $self->RecordClass
which is the class that this collection object searches and instatiates objects
for. If you're doing something hinky, you may need to override this method.
@@ -92,7 +92,7 @@ for. If you're doing something hinky, you may need to override this method.
sub _RoleGroupClass {
my $self = shift;
- return blessed($self->NewItem);
+ return $self->RecordClass;
}
sub _RoleGroupsJoin {
diff --git a/lib/RT/Shredder/User.pm b/lib/RT/Shredder/User.pm
index eb5b3d6..1bf1a69 100644
--- a/lib/RT/Shredder/User.pm
+++ b/lib/RT/Shredder/User.pm
@@ -122,7 +122,7 @@ sub __DependsOn
my $class = "RT::$_";
foreach my $method ( qw(Creator LastUpdatedBy) ) {
my $objs = $class->new( $self->CurrentUser );
- next unless $objs->NewItem->_Accessible( $method => 'read' );
+ next unless $objs->RecordClass->_Accessible( $method => 'read' );
$objs->Limit( FIELD => $method, VALUE => $self->id );
push @var_objs, $objs;
}
diff --git a/t/api/searchbuilder.t b/t/api/searchbuilder.t
index 8456871..9237dcd 100644
--- a/t/api/searchbuilder.t
+++ b/t/api/searchbuilder.t
@@ -20,7 +20,7 @@ ok( $queues->UnLimit(),'Unlimited the result set of the queues object');
my $items = $queues->ItemsArrayRef();
my @items = @{$items};
-ok($queues->NewItem->_Accessible('Name','read'));
+ok($queues->RecordClass->_Accessible('Name','read'));
my @sorted = sort {lc($a->Name) cmp lc($b->Name)} @items;
ok (@sorted, "We have an array of queues, sorted". join(',',map {$_->Name} @sorted));
commit c72b8b6d6242023bc02c2e2486d0204560055e05
Author: Thomas Sibley <trs at bestpractical.com>
Date: Mon Jul 1 16:28:14 2013 -0700
Replace almost all boilerplate NewItem methods with a generic superclass implementation
diff --git a/lib/RT/ACL.pm b/lib/RT/ACL.pm
index 8274c93..9995b80 100644
--- a/lib/RT/ACL.pm
+++ b/lib/RT/ACL.pm
@@ -218,17 +218,6 @@ sub Next {
}
-=head2 NewItem
-
-Returns an empty new RT::ACE item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return(RT::ACE->new($self->CurrentUser));
-}
-
# The singular of ACL is ACE.
sub _SingularClass { "RT::ACE" }
diff --git a/lib/RT/Articles.pm b/lib/RT/Articles.pm
index defed2a..e0aeeb2 100644
--- a/lib/RT/Articles.pm
+++ b/lib/RT/Articles.pm
@@ -908,22 +908,6 @@ sub Search {
return 1;
}
-
-=head2 NewItem
-
-Returns an empty new RT::Article item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return(RT::Article->new($self->CurrentUser));
-}
-
-
-
RT::Base->_ImportOverlays();
1;
-
-1;
diff --git a/lib/RT/Attachments.pm b/lib/RT/Attachments.pm
index 4e2f195..60fda95 100644
--- a/lib/RT/Attachments.pm
+++ b/lib/RT/Attachments.pm
@@ -230,18 +230,6 @@ sub Next {
}
}
-
-=head2 NewItem
-
-Returns an empty new RT::Attachment item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return(RT::Attachment->new($self->CurrentUser));
-}
-
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/Attributes.pm b/lib/RT/Attributes.pm
index 647beb3..10b3250 100644
--- a/lib/RT/Attributes.pm
+++ b/lib/RT/Attributes.pm
@@ -197,18 +197,6 @@ sub LimitToObject {
}
-
-
-=head2 NewItem
-
-Returns an empty new RT::Attribute item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return(RT::Attribute->new($self->CurrentUser));
-}
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/CachedGroupMembers.pm b/lib/RT/CachedGroupMembers.pm
index 3f8c39a..072f489 100644
--- a/lib/RT/CachedGroupMembers.pm
+++ b/lib/RT/CachedGroupMembers.pm
@@ -175,16 +175,6 @@ sub LimitToGroupsWithMember {
# }}}
-=head2 NewItem
-
-Returns an empty new RT::CachedGroupMember item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return(RT::CachedGroupMember->new($self->CurrentUser));
-}
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/Classes.pm b/lib/RT/Classes.pm
index 606479c..112ab98 100644
--- a/lib/RT/Classes.pm
+++ b/lib/RT/Classes.pm
@@ -94,18 +94,6 @@ sub Next {
sub _SingularClass { "RT::Class" }
-=head2 NewItem
-
-Returns an empty new RT::Class item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return(RT::Class->new($self->CurrentUser));
-}
-
-
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/CustomFieldValues.pm b/lib/RT/CustomFieldValues.pm
index f7e380e..37d1594 100644
--- a/lib/RT/CustomFieldValues.pm
+++ b/lib/RT/CustomFieldValues.pm
@@ -93,19 +93,6 @@ sub LimitToCustomField {
);
}
-
-
-
-=head2 NewItem
-
-Returns an empty new RT::CustomFieldValue item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return(RT::CustomFieldValue->new($self->CurrentUser));
-}
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/CustomFieldValues/External.pm b/lib/RT/CustomFieldValues/External.pm
index e6bf2f8..4e58388 100644
--- a/lib/RT/CustomFieldValues/External.pm
+++ b/lib/RT/CustomFieldValues/External.pm
@@ -214,6 +214,10 @@ sub LimitToCustomField {
return $self->SUPER::LimitToCustomField( @_ );
}
+sub _SingularClass {
+ "RT::CustomFieldValue"
+}
+
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/GroupMembers.pm b/lib/RT/GroupMembers.pm
index 5a7aed2..55861e5 100644
--- a/lib/RT/GroupMembers.pm
+++ b/lib/RT/GroupMembers.pm
@@ -149,18 +149,6 @@ sub LimitToMembersOfGroup {
}
-
-
-=head2 NewItem
-
-Returns an empty new RT::GroupMember item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return(RT::GroupMember->new($self->CurrentUser));
-}
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/Groups.pm b/lib/RT/Groups.pm
index 7d5671e..813726d 100644
--- a/lib/RT/Groups.pm
+++ b/lib/RT/Groups.pm
@@ -491,18 +491,6 @@ sub _DoSearch {
}
-
-
-=head2 NewItem
-
-Returns an empty new RT::Group item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return(RT::Group->new($self->CurrentUser));
-}
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/Links.pm b/lib/RT/Links.pm
index c88e74e..292bd94 100644
--- a/lib/RT/Links.pm
+++ b/lib/RT/Links.pm
@@ -139,17 +139,6 @@ sub LimitReferredToBy {
# }}}
-=head2 NewItem
-
-Returns an empty new RT::Link item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return(RT::Link->new($self->CurrentUser));
-}
-
sub AddRecord {
my $self = shift;
my $record = shift;
diff --git a/lib/RT/ObjectClasses.pm b/lib/RT/ObjectClasses.pm
index 5d48b6a..267cf71 100644
--- a/lib/RT/ObjectClasses.pm
+++ b/lib/RT/ObjectClasses.pm
@@ -70,20 +70,8 @@ sub LimitToClass {
}
-=head2 NewItem
-
-Returns an empty new RT::ObjectClass item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return(RT::ObjectClass->new($self->CurrentUser));
-}
-
sub _SingularClass { "RT::ObjectClass" }
-
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/ObjectCustomFieldValues.pm b/lib/RT/ObjectCustomFieldValues.pm
index 235c95e..547708c 100644
--- a/lib/RT/ObjectCustomFieldValues.pm
+++ b/lib/RT/ObjectCustomFieldValues.pm
@@ -158,17 +158,6 @@ sub _DoCount {
return $self->SUPER::_DoCount(@_);
}
-
-=head2 NewItem
-
-Returns an empty new RT::ObjectCustomFieldValue item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return(RT::ObjectCustomFieldValue->new($self->CurrentUser));
-}
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/ObjectTopics.pm b/lib/RT/ObjectTopics.pm
index 04357b6..ca83c11 100644
--- a/lib/RT/ObjectTopics.pm
+++ b/lib/RT/ObjectTopics.pm
@@ -98,18 +98,6 @@ sub LimitToObject {
# }}}
-=head2 NewItem
-
-Returns an empty new RT::ObjectTopic item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return(RT::ObjectTopic->new($self->CurrentUser));
-}
-
-
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/Principals.pm b/lib/RT/Principals.pm
index 064b2e6..3ef1bdc 100644
--- a/lib/RT/Principals.pm
+++ b/lib/RT/Principals.pm
@@ -82,17 +82,6 @@ sub _Init {
return ( $self->SUPER::_Init(@_) );
}
-
-=head2 NewItem
-
-Returns an empty new RT::Principal item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return(RT::Principal->new($self->CurrentUser));
-}
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/Queues.pm b/lib/RT/Queues.pm
index ff89300..c143e20 100644
--- a/lib/RT/Queues.pm
+++ b/lib/RT/Queues.pm
@@ -112,19 +112,6 @@ sub AddRecord {
$self->{'rows'}++;
}
-
-
-
-=head2 NewItem
-
-Returns an empty new RT::Queue item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return(RT::Queue->new($self->CurrentUser));
-}
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/ScripActions.pm b/lib/RT/ScripActions.pm
index 259a20d..c1fcd6f 100644
--- a/lib/RT/ScripActions.pm
+++ b/lib/RT/ScripActions.pm
@@ -97,16 +97,6 @@ sub LimitToType {
}
-=head2 NewItem
-
-Returns an empty new RT::ScripAction item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return(RT::ScripAction->new($self->CurrentUser));
-}
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/ScripConditions.pm b/lib/RT/ScripConditions.pm
index 617616e..7452822 100644
--- a/lib/RT/ScripConditions.pm
+++ b/lib/RT/ScripConditions.pm
@@ -93,17 +93,6 @@ sub LimitToType {
}
-
-=head2 NewItem
-
-Returns an empty new RT::ScripCondition item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return(RT::ScripCondition->new($self->CurrentUser));
-}
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/Scrips.pm b/lib/RT/Scrips.pm
index 2f78b5c..9faf525 100644
--- a/lib/RT/Scrips.pm
+++ b/lib/RT/Scrips.pm
@@ -500,19 +500,6 @@ sub _FindScrips {
);
}
-
-
-
-=head2 NewItem
-
-Returns an empty new RT::Scrip item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return(RT::Scrip->new($self->CurrentUser));
-}
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/SearchBuilder.pm b/lib/RT/SearchBuilder.pm
index 76b2ab5..75e3ed7 100644
--- a/lib/RT/SearchBuilder.pm
+++ b/lib/RT/SearchBuilder.pm
@@ -922,6 +922,17 @@ sub ColumnMapClassName {
return $Class;
}
+=head2 NewItem
+
+Returns a new item based on L</RecordClass> using the current user.
+
+=cut
+
+sub NewItem {
+ my $self = shift;
+ return $self->RecordClass->new($self->CurrentUser);
+}
+
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/SearchBuilder/AddAndSort.pm b/lib/RT/SearchBuilder/AddAndSort.pm
index 2743ee8..76e79bf 100644
--- a/lib/RT/SearchBuilder/AddAndSort.pm
+++ b/lib/RT/SearchBuilder/AddAndSort.pm
@@ -96,17 +96,6 @@ sub LimitToObjectId {
$self->Limit( FIELD => 'ObjectId', VALUE => $id );
}
-=head2 NewItem
-
-Returns an empty new collection's item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return $self->RecordClass->new( $self->CurrentUser );
-}
-
=head1 METHODS FOR TARGETS
Rather than implementing a base class for targets (L<RT::Scrip>,
diff --git a/lib/RT/Templates.pm b/lib/RT/Templates.pm
index 44c0b9a..551d3ea 100644
--- a/lib/RT/Templates.pm
+++ b/lib/RT/Templates.pm
@@ -158,18 +158,6 @@ sub Next {
}
-=head2 NewItem
-
-Returns an empty new RT::Template item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return(RT::Template->new($self->CurrentUser));
-}
-
-
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/Tickets.pm b/lib/RT/Tickets.pm
index 57aa68e..8ac6d70 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -2975,17 +2975,6 @@ sub _check_bundling_possibility {
return undef;
}
-
-=head2 NewItem
-
-Returns an empty new RT::Ticket item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return(RT::Ticket->new($self->CurrentUser));
-}
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/Topics.pm b/lib/RT/Topics.pm
index 01674fb..53218f6 100644
--- a/lib/RT/Topics.pm
+++ b/lib/RT/Topics.pm
@@ -103,18 +103,6 @@ sub LimitToKids {
# }}}
-=head2 NewItem
-
-Returns an empty new RT::Topic item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return(RT::Topic->new($self->CurrentUser));
-}
-
-
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/Transactions.pm b/lib/RT/Transactions.pm
index f0e75ca..e603997 100644
--- a/lib/RT/Transactions.pm
+++ b/lib/RT/Transactions.pm
@@ -153,20 +153,6 @@ sub Next {
}
}
-
-
-
-
-=head2 NewItem
-
-Returns an empty new RT::Transaction item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return(RT::Transaction->new($self->CurrentUser));
-}
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/Users.pm b/lib/RT/Users.pm
index d7c2b81..b405e61 100644
--- a/lib/RT/Users.pm
+++ b/lib/RT/Users.pm
@@ -656,17 +656,6 @@ sub SimpleSearch {
return $self;
}
-
-=head2 NewItem
-
-Returns an empty new RT::User item
-
-=cut
-
-sub NewItem {
- my $self = shift;
- return(RT::User->new($self->CurrentUser));
-}
RT::Base->_ImportOverlays();
1;
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list