[Rt-commit] rt branch 5.0/clean-attributes created. rt-5.0.3-179-gb9aa6a92d6

BPS Git Server git at git.bestpractical.com
Mon Dec 5 20:49:16 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/clean-attributes has been created
        at  b9aa6a92d6f3e241e827d652e0c4d0d4deae8ae7 (commit)

- Log -----------------------------------------------------------------
commit b9aa6a92d6f3e241e827d652e0c4d0d4deae8ae7
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Dec 6 04:26:09 2022 +0800

    Add rt-clean-attributes to delete obsolete DeferredRecipients attributes

diff --git a/Makefile.in b/Makefile.in
index cd53197528..e61b4c12f2 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -140,6 +140,7 @@ BINARIES		=	$(RT_MAILGATE_BIN) \
 
 SYSTEM_BINARIES		=	rt-attributes-viewer \
 				rt-munge-attachments \
+				rt-clean-attributes \
 				rt-clean-sessions \
 				rt-dump-initialdata \
 				rt-dump-metadata \
diff --git a/configure.ac b/configure.ac
index eeb333e8d3..d3f3bb6ba3 100755
--- a/configure.ac
+++ b/configure.ac
@@ -474,6 +474,7 @@ AC_CONFIG_FILES([
                  sbin/rt-email-digest
                  sbin/rt-email-dashboards
                  sbin/rt-externalize-attachments
+                 sbin/rt-clean-attributes
                  sbin/rt-clean-sessions
                  sbin/rt-shredder
                  sbin/rt-validator
diff --git a/sbin/rt-clean-attributes.in b/sbin/rt-clean-attributes.in
new file mode 100644
index 0000000000..34b8b139fe
--- /dev/null
+++ b/sbin/rt-clean-attributes.in
@@ -0,0 +1,131 @@
+#!@PERL@
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2022 Best Practical Solutions, LLC
+#                                          <sales at bestpractical.com>
+#
+# (Except where explicitly superseded by other copyright notices)
+#
+#
+# LICENSE:
+#
+# This work is made available to you under the terms of Version 2 of
+# the GNU General Public License. A copy of that license should have
+# been provided with this software, but in any event can be snarfed
+# from www.gnu.org.
+#
+# This work is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 or visit their web page on the internet at
+# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+#
+#
+# CONTRIBUTION SUBMISSION POLICY:
+#
+# (The following paragraph is not intended to limit the rights granted
+# to you to modify and distribute this software under the terms of
+# the GNU General Public License and is only of importance to you if
+# you choose to contribute your changes and enhancements to the
+# community by submitting them to Best Practical Solutions, LLC.)
+#
+# By intentionally submitting any modifications, corrections or
+# derivatives to this work, or any other work intended for use with
+# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+# you are the copyright holder for those contributions and you grant
+# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+# royalty-free, perpetual, license to use, copy, create derivative
+# works based on those contributions, and sublicense and distribute
+# those contributions and any derivatives thereof.
+#
+# END BPS TAGGED BLOCK }}}
+use strict;
+use warnings;
+
+# fix lib paths, some may be relative
+BEGIN { # BEGIN RT CMD BOILERPLATE
+    require File::Spec;
+    require Cwd;
+    my @libs = ("@RT_LIB_PATH@", "@LOCAL_LIB_PATH@");
+    my $bin_path;
+
+    for my $lib (@libs) {
+        unless ( File::Spec->file_name_is_absolute($lib) ) {
+            $bin_path ||= ( File::Spec->splitpath(Cwd::abs_path(__FILE__)) )[1];
+            $lib = File::Spec->catfile( $bin_path, File::Spec->updir, $lib );
+        }
+        unshift @INC, $lib;
+    }
+
+}
+
+use RT::Interface::CLI qw(Init);
+my %opt;
+Init(\%opt, 'older=s');
+
+$opt{'older'} ||= '1M';
+unless ( $opt{'older'} =~ /^\s*([0-9]+)\s*(H|D|M|Y)?$/i ) {
+    print STDERR "Wrong format of the 'older' argumnet\n";
+    exit(1);
+}
+my ( $num, $unit ) = ( $1, uc( $2 || 'D' ) );
+my %factor = ( H => 60 * 60 );
+$factor{'D'}  = $factor{'H'} * 24;
+$factor{'M'}  = $factor{'D'} * 31;
+$factor{'Y'}  = $factor{'D'} * 365;
+$opt{'older'} = $num * $factor{$unit};
+
+if ( $opt{'older'} < 7*3600*24 ) {
+    print STDERR "Value of the 'older' argumnet should be at least 7 days long\n";
+    exit(1);
+}
+
+require POSIX;
+my $date = POSIX::strftime("%Y-%m-%d %H:%M", gmtime( time - $opt{'older'} ) );
+
+my $dbh = RT->DatabaseHandle->dbh;
+my $sth = $dbh->prepare("DELETE FROM Attributes WHERE Name='DeferredRecipients' AND Created < ?");
+die "couldn't prepare query: ". $dbh->errstr unless $sth;
+my $rows = $sth->execute( $date );
+die "couldn't execute query: ". $dbh->errstr unless defined $rows;
+
+$RT::Logger->info("successfully deleted $rows attributes") if $rows > 0;
+
+__END__
+
+=head1 NAME
+
+rt-clean-attributes - clean obsolete RT attributes
+
+=head1 SYNOPSIS
+
+     rt-clean-attributes
+     rt-clean-attributes --older 1M
+
+=head1 DESCRIPTION
+
+This script deletes obsolete C<DeferredRecipients> attributes.
+
+C<DeferredRecipients> attributes are used by L<rt-email-digest>. As
+L<rt-email-digest> only processes transactions created in a week, it's safe
+to delete old corresponding C<DeferredRecipients> attributes.
+
+=head1 OPTIONS
+
+=over 4
+
+=item C<--older>
+
+Date interval in the C<< <NUM>[<unit>] >> format. Default unit is D(ays),
+H(our), M(onth) and Y(ear) are also supported.
+
+=back
+
+=cut

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list