[Rt-commit] rt branch, 4.4/external-storage, updated. rt-4.2.11-27-g2ae713c

Shawn Moore shawn at bestpractical.com
Thu May 21 18:45:17 EDT 2015


The branch, 4.4/external-storage has been updated
       via  2ae713c13dd89831c3f4240cb29fefae9cf39efa (commit)
       via  43b49b2bb6a8a7e4f6eefaa628b0f83b43b661d4 (commit)
      from  0d74b223e223d43e2f3f0e32debc7b35e4a99e58 (commit)

Summary of changes:
 lib/RT/Attachment.pm               | 23 ++++++++++++++++++++++
 lib/RT/ExternalStorage.pm          | 40 --------------------------------------
 lib/RT/ObjectCustomFieldValue.pm   | 14 +++++++++++++
 sbin/rt-externalize-attachments.in |  2 +-
 t/externalstorage/basic.t          |  8 ++++----
 5 files changed, 42 insertions(+), 45 deletions(-)

- Log -----------------------------------------------------------------
commit 43b49b2bb6a8a7e4f6eefaa628b0f83b43b661d4
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Thu May 21 22:25:53 2015 +0000

    Move StoreExternally monkeypatches right into their classes

diff --git a/lib/RT/Attachment.pm b/lib/RT/Attachment.pm
index 154d161..52bd99c 100644
--- a/lib/RT/Attachment.pm
+++ b/lib/RT/Attachment.pm
@@ -1178,6 +1178,29 @@ sub __DependsOn {
     return $self->SUPER::__DependsOn( %args );
 }
 
+sub StoreExternally {
+    my $self = shift;
+    my $type = $self->ContentType;
+    my $length = $self->ContentLength;
+
+    return 0 if $length == 0;
+
+    if ($type =~ m{^multipart/}) {
+        return 0;
+    } elsif ($type =~ m{^(text|message)/}) {
+        # If textual, we only store externally if it's _large_ (> 10M)
+        return 1 if $length > 10 * 1024 * 1024;
+        return 0;
+    } elsif ($type =~ m{^image/}) {
+        # Ditto images, which may be displayed inline
+        return 1 if $length > 10 * 1024 * 1024;
+        return 0;
+    } else {
+        return 1;
+    }
+}
+
+
 RT::Base->_ImportOverlays();
 
 1;
diff --git a/lib/RT/ExternalStorage.pm b/lib/RT/ExternalStorage.pm
index cdaf35f..79919f6 100644
--- a/lib/RT/ExternalStorage.pm
+++ b/lib/RT/ExternalStorage.pm
@@ -184,44 +184,4 @@ my $__DecodeLOB = __PACKAGE__->can('_DecodeLOB');
     return $__DecodeLOB->($self, $ContentType, 'none', $ok, $Filename);
 };
 
-package RT::ObjectCustomFieldValue;
-
-sub StoreExternally {
-    my $self = shift;
-    my $type = $self->CustomFieldObj->Type;
-    my $length = length($self->LargeContent || '');
-
-    return 0 if $length == 0;
-
-    return 1 if $type eq "Binary";
-
-    return 1 if $type eq "Image" and $length > 10 * 1024 * 1024;
-
-    return 0;
-}
-
-package RT::Attachment;
-
-sub StoreExternally {
-    my $self = shift;
-    my $type = $self->ContentType;
-    my $length = $self->ContentLength;
-
-    return 0 if $length == 0;
-
-    if ($type =~ m{^multipart/}) {
-        return 0;
-    } elsif ($type =~ m{^(text|message)/}) {
-        # If textual, we only store externally if it's _large_ (> 10M)
-        return 1 if $length > 10 * 1024 * 1024;
-        return 0;
-    } elsif ($type =~ m{^image/}) {
-        # Ditto images, which may be displayed inline
-        return 1 if $length > 10 * 1024 * 1024;
-        return 0;
-    } else {
-        return 1;
-    }
-}
-
 1;
diff --git a/lib/RT/ObjectCustomFieldValue.pm b/lib/RT/ObjectCustomFieldValue.pm
index 2434d6c..0225daa 100644
--- a/lib/RT/ObjectCustomFieldValue.pm
+++ b/lib/RT/ObjectCustomFieldValue.pm
@@ -733,6 +733,20 @@ sub FindDependencies {
     $deps->Add( out => $self->Object );
 }
 
+sub StoreExternally {
+    my $self = shift;
+    my $type = $self->CustomFieldObj->Type;
+    my $length = length($self->LargeContent || '');
+
+    return 0 if $length == 0;
+
+    return 1 if $type eq "Binary";
+
+    return 1 if $type eq "Image" and $length > 10 * 1024 * 1024;
+
+    return 0;
+}
+
 RT::Base->_ImportOverlays();
 
 1;

commit 2ae713c13dd89831c3f4240cb29fefae9cf39efa
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Thu May 21 22:44:36 2015 +0000

    Rename StoreExternally to ShouldStoreExternally
    
        This helps reinforce that this method merely answers the question,
        rather than uploading a file.

diff --git a/lib/RT/Attachment.pm b/lib/RT/Attachment.pm
index 52bd99c..9570447 100644
--- a/lib/RT/Attachment.pm
+++ b/lib/RT/Attachment.pm
@@ -1178,7 +1178,7 @@ sub __DependsOn {
     return $self->SUPER::__DependsOn( %args );
 }
 
-sub StoreExternally {
+sub ShouldStoreExternally {
     my $self = shift;
     my $type = $self->ContentType;
     my $length = $self->ContentLength;
diff --git a/lib/RT/ObjectCustomFieldValue.pm b/lib/RT/ObjectCustomFieldValue.pm
index 0225daa..66a096d 100644
--- a/lib/RT/ObjectCustomFieldValue.pm
+++ b/lib/RT/ObjectCustomFieldValue.pm
@@ -733,7 +733,7 @@ sub FindDependencies {
     $deps->Add( out => $self->Object );
 }
 
-sub StoreExternally {
+sub ShouldStoreExternally {
     my $self = shift;
     my $type = $self->CustomFieldObj->Type;
     my $length = length($self->LargeContent || '');
diff --git a/sbin/rt-externalize-attachments.in b/sbin/rt-externalize-attachments.in
index f201437..27f544d 100755
--- a/sbin/rt-externalize-attachments.in
+++ b/sbin/rt-externalize-attachments.in
@@ -136,7 +136,7 @@ for my $class (qw/RT::Attachments RT::ObjectCustomFieldValues/) {
         $RT::Handle->dbh->begin_work;
         while ( my $a = $attach->Next ) {
             $id = $a->id;
-            next unless $a->StoreExternally;
+            next unless $a->ShouldStoreExternally;
 
             # Explicitly get bytes (not characters, which ->$column would do)
             my $content = $a->_DecodeLOB(
diff --git a/t/externalstorage/basic.t b/t/externalstorage/basic.t
index 473151d..578c6e2 100644
--- a/t/externalstorage/basic.t
+++ b/t/externalstorage/basic.t
@@ -34,22 +34,22 @@ my @attachs = @{ $ticket->Transactions->First->Attachments->ItemsArrayRef };
 is scalar @attachs, 4, "Contains a multipart and two sub-parts";
 
 is $attachs[0]->ContentType, "multipart/mixed", "Found the top multipart";
-ok !$attachs[0]->StoreExternally, "Shouldn't store multipart part on disk";
+ok !$attachs[0]->ShouldStoreExternally, "Shouldn't store multipart part on disk";
 
 is $attachs[1]->ContentType, "text/plain", "Found the text part";
 is $attachs[1]->Content, 'test', "Can get the text part content";
 is $attachs[1]->ContentEncoding, "none", "Content is not encoded";
-ok !$attachs[1]->StoreExternally, "Won't store text part on disk";
+ok !$attachs[1]->ShouldStoreExternally, "Won't store text part on disk";
 
 is $attachs[2]->ContentType, "image/special", "Found the image part";
 is $attachs[2]->Content, 'boo',  "Can get the image content";
 is $attachs[2]->ContentEncoding, "none", "Content is not encoded";
-ok !$attachs[2]->StoreExternally, "Won't store images on disk";
+ok !$attachs[2]->ShouldStoreExternally, "Won't store images on disk";
 
 is $attachs[3]->ContentType, "application/octet-stream", "Found the binary part";
 is $attachs[3]->Content, 'thing',  "Can get the binary content";
 is $attachs[3]->ContentEncoding, "none", "Content is not encoded";
-ok $attachs[3]->StoreExternally, "Will store binary data on disk";
+ok $attachs[3]->ShouldStoreExternally, "Will store binary data on disk";
 
 my $dir = RT::ExternalStorage::Test->attachments_dir;
 ok !<$dir/*>, "Attachments directory is empty";

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


More information about the rt-commit mailing list