[Rt-commit] rt branch, 4.4/clear-mason-cache-button, created. rt-4.4.2-105-g10b55ed00

? sunnavy sunnavy at bestpractical.com
Wed Apr 4 15:17:04 EDT 2018


The branch, 4.4/clear-mason-cache-button has been created
        at  10b55ed008aa336a056f71a2f3a11566329af191 (commit)

- Log -----------------------------------------------------------------
commit 10b55ed008aa336a056f71a2f3a11566329af191
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Apr 5 02:18:07 2018 +0800

    Add support to clear mason cache via web interface

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index aff0f4801..e6ba8cbc5 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -265,6 +265,14 @@ sub HandleRequest {
         require Module::Refresh;
         Module::Refresh->refresh;
     }
+    else {
+        require File::Spec;
+        my $mason_cache_created = ( stat File::Spec->catdir( $RT::MasonDataDir, 'obj' ) )[ 9 ] // '';
+        if ( ( $HTML::Mason::Commands::m->{rt_mason_cache_created} // '' ) ne $mason_cache_created ) {
+            $HTML::Mason::Commands::m->interp->flush_code_cache;
+            $HTML::Mason::Commands::m->{rt_mason_cache_created} = $mason_cache_created;
+        }
+    }
 
     $HTML::Mason::Commands::r->content_type("text/html; charset=utf-8");
 
diff --git a/share/html/Admin/Helpers/ClearMasonCache b/share/html/Admin/Helpers/ClearMasonCache
new file mode 100644
index 000000000..dbba57a11
--- /dev/null
+++ b/share/html/Admin/Helpers/ClearMasonCache
@@ -0,0 +1,82 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2017 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 }}}
+<%init>
+use File::Path 'remove_tree';
+use File::Spec;
+my $mason_obj_dir = File::Spec->catdir( $RT::MasonDataDir, 'obj' );
+
+my $error;
+
+# There is a race condition that other processes add new cache items while
+# remove_tree is running, which could prevent it from deleting the whole "obj"
+# directory with errors like "Directory not empty". Let's try for a few times
+# here to get around it.
+
+for ( 1 .. 10 ) {
+    last unless -e $mason_obj_dir;
+    remove_tree( $mason_obj_dir, { safe => 1, error => \$error } );
+}
+
+my %ret;
+if ( $error && @$error ) {
+    $ret{status} = 'error';
+
+    # Only one dir is specified, so there will be only one error if any
+    my ( $file, $message ) = %{ $error->[ 0 ] };
+    RT->Logger->error( "Failed to clear mason cache: $file => $message" );
+    $ret{message} = loc( "Failed to clear mason cache: [_1] => [_2]", $file, $message );
+}
+else {
+    $ret{status}  = 'success';
+    $ret{message} = loc( 'Cache cleared' );
+}
+
+$r->content_type( 'application/json; charset=utf-8' );
+$m->out( JSON( \%ret ) );
+$m->abort;
+</%init>
diff --git a/share/html/Admin/Tools/Configuration.html b/share/html/Admin/Tools/Configuration.html
index 9643b7bfc..33f9f6c13 100644
--- a/share/html/Admin/Tools/Configuration.html
+++ b/share/html/Admin/Tools/Configuration.html
@@ -173,6 +173,26 @@ for my $type (qw/Tickets Queues Transactions Groups PrivilegedUsers Unprivileged
 <td valign="top" class="boxcontainer">
 
 <&|/Widgets/TitleBox, title => loc("Mason template search order") &>
+
+% if ( $m->{rt_mason_cache_created} ) {
+% my $mason_obj_date = RT::Date->new( $session{CurrentUser} );
+% $mason_obj_date->Set( Format => 'Unix', Value => $m->{rt_mason_cache_created} );
+
+<div class="mason-cache">
+    <div class="mason-cache-info"><&|/l&>Cache created</&>: <% $mason_obj_date->AsString %></div>
+    <a class="button clear-mason-cache" href="javascript:;"><&|/l&>Clear Mason Cache</&></a>
+</div>
+<script type="text/javascript">
+jQuery('a.clear-mason-cache').click( function() {
+    jQuery.post(RT.Config.WebHomePath + '/Admin/Helpers/ClearMasonCache', function(data) {
+        jQuery('div.mason-cache div.mason-cache-info').text(data.message);
+    }, 'json');
+    return false;
+});
+</script>
+
+% }
+
 <ol>
 % foreach my $path ( RT::Interface::Web->ComponentRoots ) {
 <li><% $path %></li>
diff --git a/share/static/css/base/admin.css b/share/static/css/base/admin.css
index 95c587803..751c8dcc5 100644
--- a/share/static/css/base/admin.css
+++ b/share/static/css/base/admin.css
@@ -82,3 +82,16 @@ table.upgrade-history .upgrade-history-parent .widget a {
 table.upgrade-history .upgrade-history-parent .widget a.rolled-up {
     background-image: url(../../../static/images/css/rolldown-arrow.gif);
 }
+
+div.mason-cache {
+    min-height: 2em;
+}
+
+div.mason-cache div.mason-cache-info {
+    display: inline-block;
+    padding: 0.5em;
+}
+
+div.mason-cache a.clear-mason-cache {
+    float: right;
+}

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


More information about the rt-commit mailing list