[Rt-commit] rt branch 5.0/upgrade-web-path-in-saved-search-format created. rt-5.0.3-203-gfb02849e2b

BPS Git Server git at git.bestpractical.com
Tue Dec 13 21:12:21 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/upgrade-web-path-in-saved-search-format has been created
        at  fb02849e2b0630a017be5548958edb51d28b35a6 (commit)

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

    Add upgrade-web-path to update outdated URLs in saved searches

diff --git a/configure.ac b/configure.ac
index eeb333e8d3..0ec52d02bb 100755
--- a/configure.ac
+++ b/configure.ac
@@ -461,6 +461,7 @@ AC_CONFIG_FILES([
                  etc/upgrade/upgrade-assets
                  etc/upgrade/upgrade-authtokens
                  etc/upgrade/upgrade-configurations
+                 etc/upgrade/upgrade-web-path
                  etc/upgrade/vulnerable-passwords
                  etc/upgrade/upgrade-sla
                  sbin/rt-ldapimport
diff --git a/etc/upgrade/upgrade-web-path.in b/etc/upgrade/upgrade-web-path.in
new file mode 100644
index 0000000000..36313eeb8f
--- /dev/null
+++ b/etc/upgrade/upgrade-web-path.in
@@ -0,0 +1,135 @@
+#!@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, 'from=s', 'force');
+
+unless ( $opt{'from'} ) {
+    print STDERR "Missing 'from' argumnet\n";
+    RT::Interface::CLI->ShowHelp();
+    exit(1);
+}
+
+my $attrs = RT::Attributes->new(RT->SystemUser);
+$attrs->Limit( FIELD => 'Name', VALUE => 'SavedSearch' );
+
+while ( my $attr = $attrs->Next ) {
+    my $content = $attr->Content or next;
+    my $format = $content->{Format} or next;
+    if ( $format =~ s!(href=["'])$opt{from}!$1__WebPath__!g ) {
+        my $indent_old = $content->{Format};
+        my $indent_new = $format;
+        $indent_old =~ s!^!    !mg;
+        $indent_new =~ s!^!    !mg;
+        print "Update format\n$indent_old\nto\n$indent_new\n" unless $opt{force};
+        if ( $opt{force} || _yesno() ) {
+            $content->{Format} = $format;
+            my ($ret, $msg) = $attr->SetContent($content);
+            if ( $ret ) {
+                print "Updated format\n$indent_old\nto\n$indent_new\n";
+            }
+            else {
+                RT->Logger->error("Failed to update Format of SavedSearch #" . $attr->id . ": $msg");
+            }
+        }
+    }
+}
+
+sub _yesno {
+    print "Proceed [y/N]:";
+    my $x = scalar(<STDIN>);
+    $x =~ /^y/i;
+}
+
+__END__
+
+=head1 NAME
+
+upgrade-web-path - Upgrade WebPath in format of saved searches
+
+=head1 SYNOPSIS
+
+     upgrade-web-path --from /rt
+     upgrade-web-path --from /rt --force
+
+=head1 DESCRIPTION
+
+This script updates URLs with old L<RT_Config/$WebPath> in format of saved searches.
+
+=head1 OPTIONS
+
+=over 4
+
+=item C<--from>
+
+The old L<RT_Config/$WebPath> value, which will be replaced with C<__WebPath__>.
+
+=back
+
+=cut

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list