Commit 0b4296db authored by Alex Vandiver's avatar Alex Vandiver
Browse files

Don't create empty LinkValueTo/IncludeContentForValue attributes

dec257a4 fixed RT::CustomField->Create() to accept LinkValueTo and
IncludeContentForValue, which are stored in attributes.  However, it
also ensured that those attributes are created even if they're empty.
This means every CF in the system, regardless of if it uses them, adds
two attributes.

Adjust _URLTemplate to remove attributes that are now empty, and more
explicitly return undef when the attribute does not exist.

Fixes: #22191
parent 8c84e38b
use strict;
use warnings;
our @Initial = (
sub {
# We do the delete in pure SQL because Attribute collections
# otherwise attempt to hash everything in memory. As this may
# be a large list, do it directly.
RT->DatabaseHandle->dbh->do(<<EOSQL);
DELETE FROM Attributes
WHERE (Name = 'LinkValueTo' OR Name = 'IncludeContentForValue')
AND (Content = '' OR Content IS NULL);
EOSQL
},
);
......@@ -1968,18 +1968,20 @@ sub _URLTemplate {
unless ( $self->CurrentUserHasRight('AdminCustomField') ) {
return ( 0, $self->loc('Permission Denied') );
}
$self->SetAttribute( Name => $template_name, Content => $value );
if (length $value and defined $value) {
$self->SetAttribute( Name => $template_name, Content => $value );
} else {
$self->DeleteAttribute( $template_name );
}
return ( 1, $self->loc('Updated') );
} else {
unless ( $self->id && $self->CurrentUserHasRight('SeeCustomField') ) {
return (undef);
}
my @attr = $self->Attributes->Named($template_name);
my $attr = shift @attr;
if ($attr) { return $attr->Content }
my ($attr) = $self->Attributes->Named($template_name);
return undef unless $attr;
return $attr->Content;
}
}
......
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