[Rt-commit] rt branch, 4.4/improve-rt-externalize-attachments, created. rt-4.4.2-59-gb8fcb24

Craig Kaiser craig at bestpractical.com
Tue Jan 2 13:12:35 EST 2018


The branch, 4.4/improve-rt-externalize-attachments has been created
        at  b8fcb2496297ed70361c8754f502f8d6f14a62fa (commit)

- Log -----------------------------------------------------------------
commit b8fcb2496297ed70361c8754f502f8d6f14a62fa
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Tue Dec 26 14:09:44 2017 -0500

    Improve rt-externalize-attachments
    
    Support for 'attachments' flag that allows the number of attachments that will be
    processed to be specified. Add 'attachment_id' flag to submit a start ID, where
    attachments prior to the specified ID will be limited.

diff --git a/sbin/rt-externalize-attachments.in b/sbin/rt-externalize-attachments
old mode 100644
new mode 100755
similarity index 89%
copy from sbin/rt-externalize-attachments.in
copy to sbin/rt-externalize-attachments
index 18b2513..5c58275
--- a/sbin/rt-externalize-attachments.in
+++ b/sbin/rt-externalize-attachments
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/Users/craigkaiser/perl5/perlbrew/perls/perl-5.24.3/bin/perl
 # BEGIN BPS TAGGED BLOCK {{{
 #
 # COPYRIGHT:
@@ -54,7 +54,7 @@ use POSIX qw(strftime);
 BEGIN { # BEGIN RT CMD BOILERPLATE
     require File::Spec;
     require Cwd;
-    my @libs = ("@RT_LIB_PATH@", "@LOCAL_LIB_PATH@");
+    my @libs = ("./lib", "./local/lib");
     my $bin_path;
 
     for my $lib (@libs) {
@@ -76,6 +76,8 @@ GetOptions( \%opts,
     "age=s",
     "batchsize=s",
     "dry-run",
+    "attachments=s",
+    "attachment_id=s",
 );
 
 if ($opts{'help'}) {
@@ -116,6 +118,8 @@ for my $class (qw/RT::Attachments RT::ObjectCustomFieldValues/) {
     my $column = $class eq 'RT::Attachments' ? "Content" : "LargeContent";
     my $id = $last->{$class} || 0;
     my $batchsize = $opts{'batchsize'} || 1;
+    my $attachments = $opts{'attachments'} || 9999;
+    my $attachment_id = $opts{'attachment_id'};
 
     while (1) {
         my $attach = $class->new($RT::SystemUser);
@@ -130,7 +134,6 @@ for my $class (qw/RT::Attachments RT::ObjectCustomFieldValues/) {
             VALUE           => 'external',
             ENTRYAGGREGATOR => 'AND',
         );
-
         if ($opts{'age'}) {
             my $agelimit = strftime "%F", localtime(time()-$opts{'age'}*24*60*60);
             $attach->Limit(
@@ -140,6 +143,14 @@ for my $class (qw/RT::Attachments RT::ObjectCustomFieldValues/) {
                 ENTRYAGGREGATOR => 'AND',
             );
         }
+        if ($opts{'attachment_id'}) {
+            $attach->Limit(
+                FIELD           => 'ID',
+                OPERATOR        => '>=',
+                VALUE           => $attachment_id,
+                ENTRYAGGREGATOR => 'AND',
+            );
+        }
 
         if ($class eq "RT::ObjectCustomFieldValues") {
             $attach->{'find_disabled_rows'} = 1;
@@ -205,9 +216,12 @@ for my $class (qw/RT::Attachments RT::ObjectCustomFieldValues/) {
             if ($opts{verbose}) {
                 RT->Logger->info("Stored $class $id as $key");
             }
+            if ( $attach->Count >= $attachments ) {
+                RT->Logger->info("Reached attachment limit.");
+                exit 2;
+            }
         }
-
-        last unless $attach->Count and $batchsize > 0;
+        last unless ( $attach->Count and $batchsize > 0 );
     }
     $last->{$class} = $id;
 }
@@ -270,6 +284,14 @@ upload begins and after it completes.
 Make a trial run and do no changes (mostly the same output as a real run is
 produced). C<dry-run> implies verbose output.
 
+=item --attachments
+
+Profide the number of attachments you would like to process.
+
+=item --attachment_id
+
+Provide a attachment ID to have as the starting point of the externalize.
+
 =back
 
 =head1 SEE ALSO
diff --git a/sbin/rt-externalize-attachments.in b/sbin/rt-externalize-attachments.in
index 18b2513..d9c667b 100644
--- a/sbin/rt-externalize-attachments.in
+++ b/sbin/rt-externalize-attachments.in
@@ -76,6 +76,8 @@ GetOptions( \%opts,
     "age=s",
     "batchsize=s",
     "dry-run",
+    "attachments=s",
+    "attachment_id=s",
 );
 
 if ($opts{'help'}) {
@@ -116,6 +118,8 @@ for my $class (qw/RT::Attachments RT::ObjectCustomFieldValues/) {
     my $column = $class eq 'RT::Attachments' ? "Content" : "LargeContent";
     my $id = $last->{$class} || 0;
     my $batchsize = $opts{'batchsize'} || 1;
+    my $attachments = $opts{'attachments'} || 9999;
+    my $attachment_id = $opts{'attachment_id'};
 
     while (1) {
         my $attach = $class->new($RT::SystemUser);
@@ -130,7 +134,14 @@ for my $class (qw/RT::Attachments RT::ObjectCustomFieldValues/) {
             VALUE           => 'external',
             ENTRYAGGREGATOR => 'AND',
         );
-
+        if ($opts{'attachment_id'}) {
+            $attach->Limit(
+                FIELD           => 'ID',
+                OPERATOR        => '>=',
+                VALUE           => $attachment_id,
+                ENTRYAGGREGATOR => 'AND',
+            );
+        }
         if ($opts{'age'}) {
             my $agelimit = strftime "%F", localtime(time()-$opts{'age'}*24*60*60);
             $attach->Limit(
@@ -206,7 +217,11 @@ for my $class (qw/RT::Attachments RT::ObjectCustomFieldValues/) {
                 RT->Logger->info("Stored $class $id as $key");
             }
         }
-
+            if ( $attach->Count >= $attachments ) {
+                RT->Logger->info("Reached attachment limit.");
+                exit 2;
+            }
+        }
         last unless $attach->Count and $batchsize > 0;
     }
     $last->{$class} = $id;
@@ -271,6 +286,21 @@ Make a trial run and do no changes (mostly the same output as a real run is
 produced). C<dry-run> implies verbose output.
 
 =back
+=item --attachments
+
+Provide the number of attachments you would like to process.
+
+=item --attachments
+
+Provide the number of attachments you would like to process.
+
+=item --attachment_id
+
+Provide a attachment ID to have as the starting point of the externalize.
+
+=item --attachment_id
+
+Provide a attachment ID to have as the starting point of the externalize.
 
 =head1 SEE ALSO
 

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


More information about the rt-commit mailing list