Commit 6e84e727 authored by Ruslan Zakirov's avatar Ruslan Zakirov
Browse files

minor

git-svn-id: svn+ssh://svn.bestpractical.com/svn/bps-public/rt/branches/3.7-EXPERIMENTAL@5685 e417ac7c-1bcc-0310-8ffa-8f5827389a85
parent f68a37a0
......@@ -15,24 +15,27 @@ from being integers.
sub Create {
my $self = shift;
my %args = @_;
(defined $args{$_} or delete $args{$_}) for keys %args;
%args = ((CustomField => '0',
Name => '',
Description => '',
SortOrder => '0',
Category => ''), %args);
my %args = (
CustomField => 0,
Name => '',
Description => '',
SortOrder => 0,
Category => '',
@_,
);
my ($id, $msg) = $self->SUPER::Create(
map {$_ => $args{$_}} qw(CustomField Name Description SortOrder)
map { $_ => $args{$_} } qw(CustomField Name Description SortOrder)
);
if ($id and length $args{Category}) {
if ( $id && length $args{Category} ) {
# $self would be loaded at this stage
my ($status, $msg) = $self->SetCategory( $args{Category} );
unless ( $status ) {
$RT::Logger->error("Couldn't set category: $msg");
}
}
return ($id, $msg);
}
......
......@@ -46,6 +46,7 @@
package RT::CustomFieldValues;
use strict;
use warnings;
no warnings qw(redefine);
# {{{ sub LimitToCustomField
......@@ -59,13 +60,13 @@ Limits the returned set to values for the custom field with Id FIELD
sub LimitToCustomField {
my $self = shift;
my $cf = shift;
return ($self->Limit( FIELD => 'CustomField',
VALUE => $cf,
OPERATOR => '='));
return $self->Limit(
FIELD => 'CustomField',
VALUE => $cf,
OPERATOR => '=',
);
}
# }}}
1;
......@@ -46,9 +46,9 @@
package RT::ObjectCustomFieldValue;
use strict;
use warnings;
no warnings qw(redefine);
sub Create {
my $self = shift;
my %args = (
......@@ -75,35 +75,31 @@ sub Create {
}
( $args{'ContentEncoding'}, $args{'LargeContent'} ) =
$self->_EncodeLOB( $args{'LargeContent'}, $args{'ContentType'} )
if ( $args{'LargeContent'} );
$self->SUPER::Create(
CustomField => $args{'CustomField'},
ObjectType => $args{'ObjectType'},
ObjectId => $args{'ObjectId'},
Disabled => $args{'Disabled'},
Content => $args{'Content'},
LargeContent => $args{'LargeContent'},
ContentType => $args{'ContentType'},
ContentEncoding => $args{'ContentEncoding'},
);
$self->_EncodeLOB( $args{'LargeContent'}, $args{'ContentType'} )
if defined $args{'LargeContent'};
return $self->SUPER::Create(
CustomField => $args{'CustomField'},
ObjectType => $args{'ObjectType'},
ObjectId => $args{'ObjectId'},
Disabled => $args{'Disabled'},
Content => $args{'Content'},
LargeContent => $args{'LargeContent'},
ContentType => $args{'ContentType'},
ContentEncoding => $args{'ContentEncoding'},
);
}
sub LargeContent {
my $self = shift;
$self->_DecodeLOB( $self->ContentType, $self->ContentEncoding,
$self->_Value( 'LargeContent', decode_utf8 => 0 ) );
return $self->_DecodeLOB(
$self->ContentType,
$self->ContentEncoding,
$self->_Value( 'LargeContent', decode_utf8 => 0 )
);
}
=head2 LoadByTicketContentAndCustomField { Ticket => TICKET, CustomField => CUSTOMFIELD, Content => CONTENT }
Loads a custom field value by Ticket, Content and which CustomField it's tied to
......@@ -113,40 +109,40 @@ Loads a custom field value by Ticket, Content and which CustomField it's tied to
sub LoadByTicketContentAndCustomField {
my $self = shift;
my %args = ( Ticket => undef,
CustomField => undef,
Content => undef,
@_
);
$self->LoadByCols( Content => $args{'Content'},
CustomField => $args{'CustomField'},
ObjectType => 'RT::Ticket',
ObjectId => $args{'Ticket'},
Disabled => 0
);
my %args = (
Ticket => undef,
CustomField => undef,
Content => undef,
@_
);
return $self->LoadByCols(
Content => $args{'Content'},
CustomField => $args{'CustomField'},
ObjectType => 'RT::Ticket',
ObjectId => $args{'Ticket'},
Disabled => 0
);
}
sub LoadByObjectContentAndCustomField {
my $self = shift;
my %args = ( Object => undef,
CustomField => undef,
Content => undef,
@_
);
my %args = (
Object => undef,
CustomField => undef,
Content => undef,
@_
);
my $obj = $args{'Object'} or return;
$self->LoadByCols( Content => $args{'Content'},
CustomField => $args{'CustomField'},
ObjectType => ref($obj),
ObjectId => $obj->Id,
Disabled => 0
);
return $self->LoadByCols(
Content => $args{'Content'},
CustomField => $args{'CustomField'},
ObjectType => ref($obj),
ObjectId => $obj->Id,
Disabled => 0
);
}
......@@ -157,18 +153,16 @@ content, try "LargeContent"
=cut
sub Content {
my $self = shift;
my $content = $self->SUPER::Content;
if (!$content && $self->ContentType eq 'text/plain') {
return $self->LargeContent();
if ( !$content && $self->ContentType eq 'text/plain' ) {
return $self->LargeContent;
} else {
return $content;
}
}
=head2 Object
Returns the object this value applies to
......@@ -177,9 +171,9 @@ Returns the object this value applies to
sub Object {
my $self = shift;
my $Object = $self->__Value('ObjectType')->new($self->CurrentUser);
$Object->Load($self->__Value('ObjectId'));
return($Object);
my $Object = $self->__Value('ObjectType')->new( $self->CurrentUser );
$Object->LoadById( $self->__Value('ObjectId') );
return $Object;
}
......@@ -192,7 +186,7 @@ Disable this value. Used to remove "current" values from records while leaving t
sub Delete {
my $self = shift;
$self->SetDisabled(1);
return $self->SetDisabled(1);
}
=head2 _FillInTemplateURL URL
......@@ -257,7 +251,4 @@ sub IncludeContentForValue {
return $self->_FillInTemplateURL($self->CustomFieldObj->IncludeContentForValue);
}
1;
......@@ -59,10 +59,10 @@ Limits the returned set to values for the custom field with Id FIELD
sub LimitToCustomField {
my $self = shift;
my $cf = shift;
return ($self->Limit( FIELD => 'CustomField',
VALUE => $cf,
OPERATOR => '='));
return $self->Limit(
FIELD => 'CustomField',
VALUE => $cf,
);
}
# }}}
......@@ -78,12 +78,14 @@ Limits the returned set to values for the given OBJECT
sub LimitToObject {
my $self = shift;
my $object = shift;
$self->Limit( FIELD => 'ObjectType',
VALUE => ref($object),
OPERATOR => '=');
return ($self->Limit( FIELD => 'ObjectId',
VALUE => $object->Id,
OPERATOR => '='));
$self->Limit(
FIELD => 'ObjectType',
VALUE => ref($object),
);
return $self->Limit(
FIELD => 'ObjectId',
VALUE => $object->Id,
);
}
......@@ -91,7 +93,8 @@ sub LimitToObject {
=sub HasEntry VALUE
Returns true if this CustomFieldValues collection has an entry with content that eq VALUE
Returns true if this CustomFieldValues collection
has an entry with content that eq VALUE
=cut
......@@ -101,35 +104,34 @@ sub HasEntry {
my $value = shift;
#TODO: this could cache and optimize a fair bit.
foreach my $item (@{$self->ItemsArrayRef}) {
return(1) if ($item->Content eq $value);
foreach my $item ( @{$self->ItemsArrayRef} ) {
return 1 if $item->Content eq $value;
}
return undef;
}
sub _DoSearch {
my $self = shift;
#unless we really want to find disabled rows, make sure we\'re only finding enabled ones.
unless($self->{'find_expired_rows'}) {
# unless we really want to find disabled rows,
# make sure we\'re only finding enabled ones.
unless ( $self->{'find_expired_rows'} ) {
$self->LimitToEnabled();
}
return($self->SUPER::_DoSearch(@_));
return $self->SUPER::_DoSearch(@_);
}
sub _DoCount {
my $self = shift;
#unless we really want to find disabled rows, make sure we\'re only finding enabled ones.
unless($self->{'find_expired_rows'}) {
# unless we really want to find disabled rows,
# make sure we\'re only finding enabled ones.
unless ( $self->{'find_expired_rows'} ) {
$self->LimitToEnabled();
}
return($self->SUPER::_DoCount(@_));
return $self->SUPER::_DoCount(@_);
}
1;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment