[Rt-commit] rt branch 5.0/rest2-serialize-txns created. rt-5.0.3-77-g2f5447019d

BPS Git Server git at git.bestpractical.com
Fri Aug 5 18:17:33 UTC 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/rest2-serialize-txns has been created
        at  2f5447019d648fd803d10464c9b6e1fa1808d5e3 (commit)

- Log -----------------------------------------------------------------
commit 2f5447019d648fd803d10464c9b6e1fa1808d5e3
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Aug 6 01:50:03 2022 +0800

    Tweak Serialize methods for REST2 where no serializer arg is passed
    
    Without this, link/queue txn endpoints like /REST/2.0/transaction/123
    would error out:
    
        Can't call method "Observe" on an undefined value at lib/RT/Transaction.pm line 2202.
    
    Note that there are no direct RT::Link endpoints in REST2 yet, but it's
    good to handle the absence of serializer arg there too, for both
    consistency and future development.

diff --git a/lib/RT/Link.pm b/lib/RT/Link.pm
index 1505fe817a..c35494b2e5 100644
--- a/lib/RT/Link.pm
+++ b/lib/RT/Link.pm
@@ -564,17 +564,19 @@ sub Serialize {
         my $object = $self->${\($dir.'Obj')};
 
         if ($uri->IsLocal) {
-            if ($args{serializer}->Observe(object => $object)) {
-                # no action needed; the object is being migrated
-            }
-            elsif ($args{serializer}{HyperlinkUnmigrated}) {
-                # object is not being migrated; hyperlinkify
-                $store{$dir} = $uri->AsHREF;
-            }
-            else {
-                # object is not being migrated and hyperlinks not desired,
-                # so drop this RT::Link altogether
-                return;
+            if ( $args{serializer} ) {
+                if ( $args{serializer}->Observe( object => $object ) ) {
+                    # no action needed; the object is being migrated
+                }
+                elsif ( $args{serializer}{HyperlinkUnmigrated} ) {
+                    # object is not being migrated; hyperlinkify
+                    $store{$dir} = $uri->AsHREF;
+                }
+                else {
+                    # object is not being migrated and hyperlinks not desired,
+                    # so drop this RT::Link altogether
+                    return;
+                }
             }
         }
     }
diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index 4f1286bf1b..92090c8cca 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -2183,14 +2183,19 @@ sub Serialize {
             my $base = RT::URI->new( $self->CurrentUser );
             $base->FromURI( $store{OldValue} );
             if ($base->Resolver && (my $object = $base->Object)) {
-                if ($args{serializer}->Observe(object => $object)) {
-                    $store{OldValue} = \($object->UID);
-                }
-                elsif ($args{serializer}{HyperlinkUnmigrated}) {
-                    $store{OldValue} = $base->AsHREF;
+                if ( $args{serializer} ) {
+                    if ( $args{serializer}->Observe( object => $object ) ) {
+                        $store{OldValue} = \( $object->UID );
+                    }
+                    elsif ( $args{serializer}{HyperlinkUnmigrated} ) {
+                        $store{OldValue} = $base->AsHREF;
+                    }
+                    else {
+                        $store{OldValue} = "(not migrated)";
+                    }
                 }
                 else {
-                    $store{OldValue} = "(not migrated)";
+                    $store{OldValue} = \( $object->UID );
                 }
             }
         }
@@ -2199,14 +2204,19 @@ sub Serialize {
             my $base = RT::URI->new( $self->CurrentUser );
             $base->FromURI( $store{NewValue} );
             if ($base->Resolver && (my $object = $base->Object)) {
-                if ($args{serializer}->Observe(object => $object)) {
-                    $store{NewValue} = \($object->UID);
-                }
-                elsif ($args{serializer}{HyperlinkUnmigrated}) {
-                    $store{NewValue} = $base->AsHREF;
+                if ( $args{serializer} ) {
+                    if ( $args{serializer}->Observe( object => $object ) ) {
+                        $store{NewValue} = \( $object->UID );
+                    }
+                    elsif ( $args{serializer}{HyperlinkUnmigrated} ) {
+                        $store{NewValue} = $base->AsHREF;
+                    }
+                    else {
+                        $store{NewValue} = "(not migrated)";
+                    }
                 }
                 else {
-                    $store{NewValue} = "(not migrated)";
+                    $store{NewValue} = \( $object->UID );
                 }
             }
         }
@@ -2214,12 +2224,16 @@ sub Serialize {
         for my $field (qw/OldValue NewValue/) {
             my $queue = RT::Queue->new( RT->SystemUser );
             $queue->Load( $store{$field} );
-            if ($args{serializer}->Observe(object => $queue)) {
-                $store{$field} = \($queue->UID);
+            if ( $args{serializer} ) {
+                if ( $args{serializer}->Observe( object => $queue ) ) {
+                    $store{$field} = \( $queue->UID );
+                }
+                else {
+                    $store{$field} = "$RT::Organization: " . $queue->Name . " (not migrated)";
+                }
             }
             else {
-                $store{$field} = "$RT::Organization: " . $queue->Name . " (not migrated)";
-
+                $store{$field} = \( $queue->UID );
             }
         }
     } elsif ($type =~ /^(Add|Open|Resolve)Reminder$/) {

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list