On Wed, Nov 12, 2008 at 05:56:12PM +0000, Dominic Hargreaves wrote: > I'm working on upgrading an RT3.4 instance to RT3.8. One of the > extensions already in use is the above mentioned patch/extension. > > The most recent version of this appears to be > > http://page.mi.fu-berlin.de/pape/rt3/patches/rt/deactivate_scrip-3.6.patch > > and I had a quick go applying the patch to 3.8, but unsurprisingly this > doesn't work straight off. Before I dive into porting this, has anyone > already done it?
I've completed this port without too much hassle. Patch against RT 3.8.1, and schema files, here: http://users.ox.ac.uk/~dom/patches/rt/3.8/deactivate_scrip/ It could probably be cleaned up to be more consistent with modern RT standards (especially share/html/Admin/Elements/EditScrips) but is functional. Cheers, Dominic. -- Dominic Hargreaves, Systems Development and Support Team Computing Services, University of Oxford
diff -urN request-tracker3.8-3.8.1.orig/lib/RT/QueueDeactivatedScrip_Overlay.pm request-tracker3.8-3.8.1/lib/RT/QueueDeactivatedScrip_Overlay.pm --- request-tracker3.8-3.8.1.orig/lib/RT/QueueDeactivatedScrip_Overlay.pm 1970-01-01 01:00:00.000000000 +0100 +++ request-tracker3.8-3.8.1/lib/RT/QueueDeactivatedScrip_Overlay.pm 2008-11-12 16:56:18.000000000 +0000 @@ -0,0 +1,49 @@ +=head1 SYNOPSIS + +=head1 DESCRIPTION + +=head1 METHODS + +=cut + +use strict; +no warnings qw(redefine); + +sub GlobalScripStatus { + my $self = shift; + my $ScripId = shift; + + $self->LoadByCols( QueueId => 0, ScripId => $ScripId ); + + return ( $self->Status || 'active' ); +} + +sub QueueScripLocalStatus { + my $self = shift; + my $QueueId = shift; + my $ScripId = shift; + + $self->LoadByCols( QueueId => $QueueId, ScripId => $ScripId ); + + return ( $self->Status || 'inherited' ); +} + +sub QueueScripStatus { + my $self = shift; + my $QueueId = shift; + my $ScripId = shift; + + $self->LoadByCols( QueueId => $QueueId, ScripId => $ScripId ); + + return ( $self->Status || $self->GlobalScripStatus($ScripId) ); +} + +sub ScripIsDeactivatedForQueue { + my $self = shift; + my $QueueId = shift; + my $ScripId = shift; + + return ( $self->QueueScripStatus($QueueId, $ScripId) =~ /^(deactivated|inactive)$/ ); +} + +1; diff -urN request-tracker3.8-3.8.1.orig/lib/RT/QueueDeactivatedScrip.pm request-tracker3.8-3.8.1/lib/RT/QueueDeactivatedScrip.pm --- request-tracker3.8-3.8.1.orig/lib/RT/QueueDeactivatedScrip.pm 1970-01-01 01:00:00.000000000 +0100 +++ request-tracker3.8-3.8.1/lib/RT/QueueDeactivatedScrip.pm 2007-05-16 16:10:21.000000000 +0100 @@ -0,0 +1,236 @@ +# BEGIN LICENSE BLOCK +# +# Copyright (c) 1996-2003 Jesse Vincent <[EMAIL PROTECTED]> +# +# (Except where explictly superceded by other copyright notices) +# +# 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. +# +# Unless otherwise specified, all modifications, corrections or +# extensions to this work which alter its source code become the +# property of Best Practical Solutions, LLC when submitted for +# inclusion in the work. +# +# +# END LICENSE BLOCK + +# Autogenerated by DBIx::SearchBuilder factory (by <[EMAIL PROTECTED]>) +# WARNING: THIS FILE IS AUTOGENERATED. ALL CHANGES TO THIS FILE WILL BE LOST. +# +# !! DO NOT EDIT THIS FILE !! +# + +use strict; + + +=head1 NAME + +RT::QueueDeactivatedScrip + + +=head1 SYNOPSIS + +=head1 DESCRIPTION + +=head1 METHODS + +=cut + +package RT::QueueDeactivatedScrip; +use RT::Record; + + +use vars qw( @ISA ); [EMAIL PROTECTED] qw( RT::Record ); + +sub _Init { + my $self = shift; + + $self->Table('QueueDeactivatedScrips'); + $self->SUPER::_Init(@_); +} + + + + + +=head2 Create PARAMHASH + +Create takes a hash of values and creates a row in the database: + + int(11) 'QueueId'. + int(11) 'ScripId'. + varchar(15) 'Status' defaults to 'deactivated'. + varchar(255) 'Description'. + +=cut + + + + +sub Create { + my $self = shift; + my %args = ( + QueueId => '0', + ScripId => '0', + Status => 'deactivated', + Description => '', + + @_); + $self->SUPER::Create( + QueueId => $args{'QueueId'}, + ScripId => $args{'ScripId'}, + Status => $args{'Status'}, + Description => $args{'Description'}, +); + +} + + + +=head2 id + +Returns the current value of id. +(In the database, id is stored as int(11).) + + +=cut + + +=head2 QueueId + +Returns the current value of QueueId. +(In the database, QueueId is stored as int(11).) + + + +=head2 SetQueueId VALUE + + +Set QueueId to VALUE. +Returns (1, 'Status message') on success and (0, 'Error Message') on failure. +(In the database, QueueId will be stored as a int(11).) + + +=cut + + +=head2 ScripId + +Returns the current value of ScripId. +(In the database, ScripId is stored as int(11).) + + + +=head2 SetScripId VALUE + + +Set ScripId to VALUE. +Returns (1, 'Status message') on success and (0, 'Error Message') on failure. +(In the database, ScripId will be stored as a int(11).) + + +=cut + + +=head2 Status + +Returns the current value of Status. +(In the database, Status is stored as varchar(15).) + + + +=head2 SetStatus VALUE + + +Set Status to VALUE. +Returns (1, 'Status message') on success and (0, 'Error Message') on failure. +(In the database, Status will be stored as a varchar(15).) + + +=cut + + +=head2 Description + +Returns the current value of Description. +(In the database, Description is stored as varchar(255).) + + + +=head2 SetDescription VALUE + + +Set Description to VALUE. +Returns (1, 'Status message') on success and (0, 'Error Message') on failure. +(In the database, Description will be stored as a varchar(255).) + + +=cut + + + +sub _ClassAccessible { + { + + id => + {read => 1, type => 'int(11)', default => ''}, + QueueId => + {read => 1, write => 1, type => 'int(11)', default => '0'}, + ScripId => + {read => 1, write => 1, type => 'int(11)', default => '0'}, + Status => + {read => 1, write => 1, type => 'varchar(15)', default => 'deactivated'}, + Description => + {read => 1, write => 1, type => 'varchar(255)', default => ''}, + + } +}; + + + eval "require RT::QueueDeactivatedScrip_Overlay"; + if ($@ && $@ !~ qr{^Can't locate RT/QueueDeactivatedScrip_Overlay.pm}) { + die $@; + }; + + eval "require RT::QueueDeactivatedScrip_Vendor"; + if ($@ && $@ !~ qr{^Can't locate RT/QueueDeactivatedScrip_Vendor.pm}) { + die $@; + }; + + eval "require RT::QueueDeactivatedScrip_Local"; + if ($@ && $@ !~ qr{^Can't locate RT/QueueDeactivatedScrip_Local.pm}) { + die $@; + }; + + + + +=head1 SEE ALSO + +This class allows "overlay" methods to be placed +into the following files _Overlay is for a System overlay by the original author, +_Vendor is for 3rd-party vendor add-ons, while _Local is for site-local customizations. + +These overlay files can contain new subs or subs to replace existing subs in this module. + +If you'll be working with perl 5.6.0 or greater, each of these files should begin with the line + + no warnings qw(redefine); + +so that perl does not kick and scream when you redefine a subroutine or variable in your overlay. + +RT::QueueDeactivatedScrip_Overlay, RT::QueueDeactivatedScrip_Vendor, RT::QueueDeactivatedScrip_Local + +=cut + + +1; diff -urN request-tracker3.8-3.8.1.orig/lib/RT/QueueDeactivatedScrips.pm request-tracker3.8-3.8.1/lib/RT/QueueDeactivatedScrips.pm --- request-tracker3.8-3.8.1.orig/lib/RT/QueueDeactivatedScrips.pm 1970-01-01 01:00:00.000000000 +0100 +++ request-tracker3.8-3.8.1/lib/RT/QueueDeactivatedScrips.pm 2007-05-16 16:10:21.000000000 +0100 @@ -0,0 +1,116 @@ +# BEGIN LICENSE BLOCK +# +# Copyright (c) 1996-2003 Jesse Vincent <[EMAIL PROTECTED]> +# +# (Except where explictly superceded by other copyright notices) +# +# 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. +# +# Unless otherwise specified, all modifications, corrections or +# extensions to this work which alter its source code become the +# property of Best Practical Solutions, LLC when submitted for +# inclusion in the work. +# +# +# END LICENSE BLOCK + +# Autogenerated by DBIx::SearchBuilder factory (by <[EMAIL PROTECTED]>) +# WARNING: THIS FILE IS AUTOGENERATED. ALL CHANGES TO THIS FILE WILL BE LOST. +# +# !! DO NOT EDIT THIS FILE !! +# + +use strict; + + +=head1 NAME + + RT::QueueDeactivatedScrips -- Class Description + +=head1 SYNOPSIS + + use RT::QueueDeactivatedScrips + +=head1 DESCRIPTION + + +=head1 METHODS + +=cut + +package RT::QueueDeactivatedScrips; + +use RT::SearchBuilder; +use RT::QueueDeactivatedScrip; + +use vars qw( @ISA ); [EMAIL PROTECTED] qw(RT::SearchBuilder); + + +sub _Init { + my $self = shift; + $self->{'table'} = 'QueueDeactivatedScrips'; + $self->{'primary_key'} = 'id'; + + + return ( $self->SUPER::_Init(@_) ); +} + + +=head2 NewItem + +Returns an empty new RT::QueueDeactivatedScrip item + +=cut + +sub NewItem { + my $self = shift; + return(RT::QueueDeactivatedScrip->new($self->CurrentUser)); +} + + eval "require RT::QueueDeactivatedScrips_Overlay"; + if ($@ && $@ !~ qr{^Can't locate RT/QueueDeactivatedScrips_Overlay.pm}) { + die $@; + }; + + eval "require RT::QueueDeactivatedScrips_Vendor"; + if ($@ && $@ !~ qr{^Can't locate RT/QueueDeactivatedScrips_Vendor.pm}) { + die $@; + }; + + eval "require RT::QueueDeactivatedScrips_Local"; + if ($@ && $@ !~ qr{^Can't locate RT/QueueDeactivatedScrips_Local.pm}) { + die $@; + }; + + + + +=head1 SEE ALSO + +This class allows "overlay" methods to be placed +into the following files _Overlay is for a System overlay by the original author, +_Vendor is for 3rd-party vendor add-ons, while _Local is for site-local customizations. + +These overlay files can contain new subs or subs to replace existing subs in this module. + +If you'll be working with perl 5.6.0 or greater, each of these files should begin with the line + + no warnings qw(redefine); + +so that perl does not kick and scream when you redefine a subroutine or variable in your overlay. + +RT::QueueDeactivatedScrips_Overlay, RT::QueueDeactivatedScrips_Vendor, RT::QueueDeactivatedScrips_Local + +=cut + + +1; diff -urN request-tracker3.8-3.8.1.orig/lib/RT/Scrip_Overlay.pm request-tracker3.8-3.8.1/lib/RT/Scrip_Overlay.pm --- request-tracker3.8-3.8.1.orig/lib/RT/Scrip_Overlay.pm 2008-08-18 16:14:11.000000000 +0100 +++ request-tracker3.8-3.8.1/lib/RT/Scrip_Overlay.pm 2008-11-13 12:52:52.000000000 +0000 @@ -364,6 +364,19 @@ @_ ); my $return; + + require RT::QueueDeactivatedScrip; + my $info = new RT::QueueDeactivatedScrip( $self->CurrentUser ); + my $ticket = $args{'TicketObj'}; + if ( $ticket && $ticket->QueueObj && + $info->ScripIsDeactivatedForQueue( $ticket->QueueObj->Id, $self->Id ) ) { + $RT::Logger->info( "Scrip ".$self->Id." has NOT been applied, since it is deactivated for Queue ".$ticket->QueueObj->Name ); + $self->ConditionObj->DESTROY; + return (undef); + } else { + $RT::Logger->debug( "Scrip ".$self->Id." has been applied, since it is not deactivated for Queue ".$ticket->QueueObj->Name ); + } + eval { my @Transactions; diff -urN request-tracker3.8-3.8.1.orig/share/html/Admin/Elements/DeactivateGlobalScrips request-tracker3.8-3.8.1/share/html/Admin/Elements/DeactivateGlobalScrips --- request-tracker3.8-3.8.1.orig/share/html/Admin/Elements/DeactivateGlobalScrips 1970-01-01 01:00:00.000000000 +0100 +++ request-tracker3.8-3.8.1/share/html/Admin/Elements/DeactivateGlobalScrips 2008-11-13 13:24:11.000000000 +0000 @@ -0,0 +1,109 @@ +%# BEGIN LICENSE BLOCK +%# +%# Copyright (c) 1996-2003 Jesse Vincent <[EMAIL PROTECTED]> +%# +%# (Except where explictly superceded by other copyright notices) +%# +%# 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. +%# +%# Unless otherwise specified, all modifications, corrections or +%# extensions to this work which alter its source code become the +%# property of Best Practical Solutions, LLC when submitted for +%# inclusion in the work. +%# +%# +%# END LICENSE BLOCK +<& /Elements/ListActions, actions => [EMAIL PROTECTED] &> +<form action="Scrips.html" method="post"> +<input type="hidden" name="id" value="<%$id%>" /> +<p><&|/l&>Scrips which apply to all queues</&>:</p> +% if ($Scrips->Count == 0 ) { +<p><i><&|/l&>(No scrips)</&></i></p> +% } else { +<table width="100%"> +% if ($QueueId) { +<tr> +<td align="center"><i><&|/l&>inherit</&></i></td> +<td align="center"><i><&|/l&>on</&></i></td> +<td align="center"><i><&|/l&>off</&></i></td> +<td><i><&|/l&>(select status for queue: inherited, activated, deactivated)</&></i></td> +</tr> +% } +% while (my $scrip = $Scrips->Next ) { +<tr> +% if ($QueueId) { +% my $status=$info->QueueScripLocalStatus( $QueueId, $scrip->Id); +<td> +<input type="radio" name="Status-<%$scrip->Id%>" value="inherited" <% $status eq 'inherited' && "checked"%> /> <i>(<%loc( $info->GlobalScripStatus( $scrip->Id))%>)</i> +</td> +<td align="center"> +<input type="radio" name="Status-<%$scrip->Id%>" value="activated" <% $status eq 'activated' && "checked"%> /> +</td> +<td align="center"> +<input type="radio" name="Status-<%$scrip->Id%>" value="deactivated" <% $status eq 'deactivated' && "checked"%> /> +</td> +% } +<td> +<% $scrip->Description || "<i>(".loc('no value').")</i>" |n %><br /> +<small><&|/l, loc($scrip->ConditionObj->Name), loc($scrip->ActionObj->Name), loc($scrip->TemplateObj->Name) &>[_1] [_2] with template [_3]</&></small> +</td> +</tr> +% } +</table> +% } +<& /Elements/Submit, + Caption => loc("Update scrips status for this queue"), + Label => loc("Update status") &> +</form> +<%init> +my (@actions); +my $Scrips = RT::Scrips->new($session{'CurrentUser'}); +$Scrips->LimitToGlobal(); +$Scrips->OrderBy( FIELD => 'description' ); +my $QueueObj = RT::Queue->new($session{'CurrentUser'}); +if ($id) { + $QueueObj->Load($id); +} +my $QueueId = $QueueObj->id; + +require RT::QueueDeactivatedScrip; +my $info = new RT::QueueDeactivatedScrip($session{'CurrentUser'}); +while (my $scrip = $Scrips->Next ) { + my $ScripId = $scrip->Id; + my $oldstatus = $info->QueueScripLocalStatus( $QueueId, $ScripId ); + my $status=$ARGS{"Status-$ScripId"}; + + if ($status && $status ne $oldstatus) { + my ($retval, $msg) = (1,undef); + if ($status eq 'inherited') { + ($retval, $msg) = $info->Delete(); + } else { + if (! $info->Id) { + ($retval, $msg) = $info->Create( QueueId => $QueueId, + ScripId => $ScripId, + Description => 'by admininterface' ); + } + if ($retval) { + ($retval, $msg) = $info->SetStatus( $status ); + } + } + if ($retval) { + push @actions, loc("Scrip status set to [_1]", loc($status)); + } else { + push @actions, $msg; + } + } +} + +</%INIT> +<%ARGS> +$id => undef +</%ARGS> diff -urN request-tracker3.8-3.8.1.orig/share/html/Admin/Elements/EditScrips request-tracker3.8-3.8.1/share/html/Admin/Elements/EditScrips --- request-tracker3.8-3.8.1.orig/share/html/Admin/Elements/EditScrips 2008-08-18 16:13:59.000000000 +0100 +++ request-tracker3.8-3.8.1/share/html/Admin/Elements/EditScrips 2008-11-13 13:19:14.000000000 +0000 @@ -51,26 +51,42 @@ <input type="hidden" class="hidden" name="id" value="<% $id %>" /> <h2><&|/l&>Current Scrips</&></h2> -<& /Elements/CollectionList, - OrderBy => 'Description', - Order => 'ASC', - Rows => 100, - %ARGS, - Format => $Format, - DisplayFormat => "__CheckBox.{DeleteScrip}__, $Format", - Collection => $Scrips, - AllowSorting => 1, - PassArguments => [ qw(Query Format Rows Page Order OrderBy id) ], -&> - -% if ( $Scrips->Count ) { -<p><i><&|/l&>(Check box to delete)</&></i></p> -% } else { +% if ( $Scrips->Count == 0 ) { <p><i><&|/l&>(No scrips)</&></i></p> +% } else { +<table width="100%"> +<p><i><&|/l&>(Check box to delete)</&></i></p> +<tr> +<td align="center"><&|/l&>delete</&></td> +<td align="center"><i><&|/l&>on</&></i></td> +<td align="center"><i><&|/l&>off</&></i></td> +<td><i><&|/l&>(delete or select status for queue: active, inactive)</&></i></td> +</tr> +% while (my $scrip = $Scrips->Next ) { +% my $status=$info->GlobalScripStatus( $scrip->Id); +<tr> +<td> +<input type="checkbox" class="checkbox" name="DeleteScrip-<%$scrip->Id%>" value="1" /> +</td> +<td align="center"> +<input type="radio" class=radio name="Status-<%$scrip->Id%>" value="active" <% $status eq 'active' && "checked"%> /> +</td> +<td align="center"> +<input type="radio" class=radio name="Status-<%$scrip->Id%>" value="inactive" <% $status eq 'inactive' && "checked"%> /> +</td> +<td> +<a href="Scrip.html?id=<%$scrip->Id%>&Queue=<%$id%>"><% $scrip->Description || "<i>(".loc('no value').")</i>" |n %></a><br /> +<small><&|/l, loc($scrip->ConditionObj->Name), loc($scrip->ActionObj->Name), loc($scrip->TemplateObj->Name) &>[_1] [_2] with template [_3]</&></small> +</td> +</tr> +% } + +</table> + % } <& /Elements/Submit, - Caption => loc("Delete selected scrips"), - Label => loc("Delete") + Caption => loc("Update status and delete selected scrips"), + Label => loc("Update/Delete") &> </form> @@ -94,6 +110,8 @@ $Scrips->LimitToGlobal(); } +$Scrips->OrderBy( FIELD => 'description' ); + # {{{ deal with modifying and deleting existing scrips # we still support DeleteScrip-id format but array is preferred foreach my $id ( grep $_, @DeleteScrip, map /^DeleteScrip-(\d+)/, keys %ARGS ) { @@ -109,6 +127,36 @@ } # }}} +require RT::QueueDeactivatedScrip; +my $info = new RT::QueueDeactivatedScrip($session{'CurrentUser'}); +while (my $scrip = $Scrips->Next ) { + my $ScripId = $scrip->Id; + my $oldstatus = $info->GlobalScripStatus( $ScripId ); + my $status=$ARGS{"Status-$ScripId"}; + + if ($status && $status ne $oldstatus) { + my ($retval, $msg) = (1,undef); + if ($status eq 'active') { + ($retval, $msg) = $info->Delete(); + } else { + if (! $info->Id) { + ($retval, $msg) = $info->Create( QueueId => 0, + ScripId => $ScripId, + Description => 'by admininterface' ); + } + if ($retval) { + ($retval, $msg) = $info->SetStatus( $status ); + } + } + if ($retval) { + push @actions, loc("Scrip status set to [_1]", loc($status)); + } else { + push @actions, $msg; + } + } +} + + my $dir_path = $m->request_comp->dir_path; $Format ||= qq{'<a href="__WebPath__$dir_path/Scrip.html?id=__id__&Queue=$id">__id__</a>/TITLE:#'} .qq{,'<a href="__WebPath__$dir_path/Scrip.html?id=__id__&Queue=$id">__Description__</a>/TITLE:Description'} diff -urN request-tracker3.8-3.8.1.orig/share/html/Admin/Queues/Scrips.html request-tracker3.8-3.8.1/share/html/Admin/Queues/Scrips.html --- request-tracker3.8-3.8.1.orig/share/html/Admin/Queues/Scrips.html 2008-08-18 16:13:59.000000000 +0100 +++ request-tracker3.8-3.8.1/share/html/Admin/Queues/Scrips.html 2008-11-13 13:06:01.000000000 +0000 @@ -54,9 +54,7 @@ Title => $title &> % unless ( $QueueObj->Disabled ) { # Global scrips does not apply to disabled queues -<h2><&|/l&>Scrips which apply to all queues</&></h2> -<& /Admin/Elements/ListGlobalScrips &> -<br /> +<& /Admin/Elements/DeactivateGlobalScrips, %ARGS &> % } <& /Admin/Elements/EditScrips, title => $title, %ARGS &> <%init>
_______________________________________________ http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users Community help: http://wiki.bestpractical.com Commercial support: [EMAIL PROTECTED] Discover RT's hidden secrets with RT Essentials from O'Reilly Media. Buy a copy at http://rtbook.bestpractical.com