[Rt-commit] rt branch, 3.9-trunk, updated. rt-3.8.8-221-g8a2725a

Shawn Moore sartak at bestpractical.com
Thu Aug 5 18:55:16 EDT 2010


The branch, 3.9-trunk has been updated
       via  8a2725a1031352ee57b28e21b496ce329bb31f17 (commit)
      from  15286cbd5a708759bff1fa0b1ecada2d11bdd390 (commit)

Summary of changes:
 lib/RT/Record.pm |   27 +++++++++++++++++++++++++--
 1 files changed, 25 insertions(+), 2 deletions(-)

- Log -----------------------------------------------------------------
commit 8a2725a1031352ee57b28e21b496ce329bb31f17
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Thu Aug 5 18:55:18 2010 -0400

    Factor out an _UpdateAttributes method from Update
    
        This way we can implement better validation on new values without
        having to deal with prefixes and whatnot
    
        I would have preferred to not factor out the method and pass
        \%new_values to each Set$Field method, but some fields have
        additional arguments, such as SetStatus (which adds a Force
        argument) and SetOwner (which adds a change-ownership-type argument)
        So unfortunately we're not consistent enough to add the new argument

diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
index 82646d8..8363246 100755
--- a/lib/RT/Record.pm
+++ b/lib/RT/Record.pm
@@ -853,8 +853,9 @@ sub Update {
 
     my $attributes = $args{'AttributesRef'};
     my $ARGSRef    = $args{'ARGSRef'};
-    my @results;
+    my %new_values;
 
+    # gather all new values
     foreach my $attribute (@$attributes) {
         my $value;
         if ( defined $ARGSRef->{$attribute} ) {
@@ -875,7 +876,6 @@ sub Update {
 
         $value =~ s/\r\n/\n/gs;
 
-
         # If Queue is 'General', we want to resolve the queue name for
         # the object.
 
@@ -894,6 +894,29 @@ sub Update {
             next if ($value || 0) eq $self->$attribute();
         };
 
+        $new_values{$attribute} = $value;
+    }
+
+    return $self->_UpdateAttributes(
+        Attributes => $attributes,
+        NewValues  => \%new_values,
+    );
+}
+
+sub _UpdateAttributes {
+    my $self = shift;
+    my %args = (
+        Attributes => [],
+        NewValues  => {},
+        @_,
+    );
+
+    my @results;
+
+    foreach my $attribute (@{ $args{Attributes} }) {
+        next if !exists($args{NewValues}{$attribute});
+
+        my $value = $args{NewValues}{$attribute};
         my $method = "Set$attribute";
         my ( $code, $msg ) = $self->$method($value);
         my ($prefix) = ref($self) =~ /RT(?:.*)::(\w+)/;

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


More information about the Rt-commit mailing list