[Rt-commit] rt branch, 4.2/customfield-attributes, created. rt-4.2.6-69-ga1b0fe7

Alex Vandiver alexmv at bestpractical.com
Tue Sep 2 11:09:44 EDT 2014


The branch, 4.2/customfield-attributes has been created
        at  a1b0fe7a6da07a2412b5f324b7568eb86057d929 (commit)

- Log -----------------------------------------------------------------
commit a1b0fe7a6da07a2412b5f324b7568eb86057d929
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Tue Sep 2 11:05:27 2014 -0400

    Don't create empty LinkValueTo/IncludeContentForValue attributes
    
    dec257a 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

diff --git a/etc/upgrade/4.2.7/content b/etc/upgrade/4.2.7/content
new file mode 100644
index 0000000..96ff76b
--- /dev/null
+++ b/etc/upgrade/4.2.7/content
@@ -0,0 +1,15 @@
+use strict;
+use warnings;
+
+our @Initial = (
+    sub {
+        # We do the delete in pure SQL because Atribute collections
+        # otherwise attempt to hash rverything in memory.  As this may
+        # be a large list, do it directly.
+        $RT::Handle->dbh->do(<<EOSQL);
+            DELETE FROM Attributes
+             WHERE (Name = 'LinkValueTo' OR Name = 'IncludeContentForValue')
+               AND (Content = '' OR Content IS NULL);
+EOSQL
+    },
+);
diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 21427f7..91ffdc3 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -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;
     }
 }
 

-----------------------------------------------------------------------


More information about the rt-commit mailing list