[Bps-public-commit] rt-extension-assets branch, load-by-name, created. 1.04-1-g9d5dea3
Alex Vandiver
alexmv at bestpractical.com
Tue Mar 17 18:35:21 EDT 2015
The branch, load-by-name has been created
at 9d5dea36119a3eefa6b7f13331eebd4fc9d85b1e (commit)
- Log -----------------------------------------------------------------
commit 9d5dea36119a3eefa6b7f13331eebd4fc9d85b1e
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Thu Oct 2 18:17:04 2014 -0400
Simplify by using the more recent and correct LoadByName in RT 4.2.5
This increases the RT dependency to RT 4.2.5, from 4.2.1 previously.
diff --git a/Makefile.PL b/Makefile.PL
index 7424108..f70b290 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -11,7 +11,7 @@ no_index package => "RT::Transaction";
no_index package => "RT::CustomField";
no_index package => "RT::CustomFields";
-requires_rt("4.2.1");
+requires_rt("4.2.5");
test_requires "Test::Warn";
my ($loaded) = ($INC{'RT.pm'} =~ /^(.*)[\\\/]/);
diff --git a/lib/RT/Asset.pm b/lib/RT/Asset.pm
index ddd1fde..7122c3a 100644
--- a/lib/RT/Asset.pm
+++ b/lib/RT/Asset.pm
@@ -561,8 +561,13 @@ sub LoadCustomFieldByIdentifier {
my $cf = RT::CustomField->new( $self->CurrentUser );
$cf->SetContextObject( $self );
- $cf->LoadByNameAndCatalog( Name => $field, Catalog => $self->Catalog );
- $cf->LoadByNameAndCatalog( Name => $field, Catalog => 0 ) unless $cf->id;
+ $cf->LoadByName(
+ Name => $field,
+ LookupType => $self->CustomFieldLookupType,
+ ObjectId => $self->Catalog,
+ IncludeGlobal => 1,
+ IncludeDisabled => 0,
+ );
return $cf;
}
diff --git a/lib/RT/Extension/Assets.pm b/lib/RT/Extension/Assets.pm
index 74898bb..5394455 100644
--- a/lib/RT/Extension/Assets.pm
+++ b/lib/RT/Extension/Assets.pm
@@ -334,22 +334,16 @@ RT->AddJavaScript("RTx-Assets.js");
{
package RT::CustomField;
- # To someday be merged into RT::CustomField::LoadByName
sub LoadByNameAndCatalog {
my $self = shift;
my %args = (
- Catalog => undef,
- Name => undef,
- @_,
- );
-
- unless ( defined $args{'Name'} && length $args{'Name'} ) {
- $RT::Logger->error("Couldn't load Custom Field without Name");
- return wantarray ? (0, $self->loc("No name provided")) : 0;
- }
+ Catalog => undef,
+ Name => undef,
+ @_,
+ );
# if we're looking for a catalog by name, make it a number
- if ( defined $args{'Catalog'} && ($args{'Catalog'} =~ /\D/ || !$self->ContextObject) ) {
+ if ( defined $args{'Catalog'} && $args{'Catalog'} =~ /\D/ ) {
my $CatalogObj = RT::Catalog->new( $self->CurrentUser );
my ($ok, $msg) = $CatalogObj->Load( $args{'Catalog'} );
if ( $ok ){
@@ -359,31 +353,15 @@ RT->AddJavaScript("RTx-Assets.js");
RT::Logger->error("Unable to load catalog " . $args{'Catalog'} . $msg);
return (0, $msg);
}
- $self->SetContextObject( $CatalogObj )
- unless $self->ContextObject;
}
- my $CFs = RT::CustomFields->new( $self->CurrentUser );
- $CFs->SetContextObject( $self->ContextObject );
- my $field = $args{'Name'} =~ /\D/? 'Name' : 'id';
- $CFs->Limit( FIELD => $field, VALUE => $args{'Name'}, CASESENSITIVE => 0);
-
- # Limit to catalog, if provided. This will also limit to RT::Asset types.
- $CFs->LimitToCatalog( $args{'Catalog'} );
-
- # When loading by name, we _can_ load disabled fields, but prefer
- # non-disabled fields.
- $CFs->FindAllRows;
- $CFs->OrderByCols(
- {
- FIELD => "Disabled", ORDER => 'ASC' },
- );
-
- # We only want one entry.
- $CFs->RowsPerPage(1);
-
- return (0, $self->loc("Not found")) unless my $first = $CFs->First;
- return $self->LoadById( $first->id );
+ return $self->LoadByName(
+ Name => $args{Name},
+ LookupType => RT::Asset->CustomFieldLookupType,
+ ObjectId => $args{Catalog},
+ IncludeGlobal => 1,
+ IncludeDisabled => 0,
+ );
}
}
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list