%# BEGIN BPS TAGGED BLOCK {{{ %# %# COPYRIGHT: %# %# This software is Copyright (c) 1996-2025 Best Practical Solutions, LLC %# %# %# (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 }}} <& /Admin/Elements/Header, Title => loc("Admin Lifecycles") &> <& /Elements/Tabs &> <& /Elements/ListActions, actions => \@results &>
/>
% my $i = 0; % for my $key ( sort keys %lifecycles ) { % next if grep { $key eq $_ } qw/approvals __maps__/; % next if $lifecycles{$key}{'disabled'} and !$FindDisabledLifecycles; % ++$i; % }
<&|/l&>Name <&|/l&>Type <&|/l&>Enabled <&|/l&>Applied
<% $key %> <% $lifecycles{$key}{'type'} ? loc($lifecycles{$key}{'type'}) : loc('ticket') %>
/>
% my ($appliedref, $show_more_link) = $get_applied->($key); % if ( $appliedref ) { % my $j = 0; % while( my $applied = $appliedref->Next ) { % $j++; <% $applied->Name() %><% (($j < $appliedref->CountAll())||$show_more_link) ? ', ' : '' %> % } % if ( $show_more_link ) { <&|/l&>More... % } % }
<%INIT> my @results; my $applied_list_limit = 15; my %lifecycles = %{RT::Config->Get('Lifecycles')}; $m->callback( CallbackName => 'Initial', LifecycleConfig => \%lifecycles, AppliedListLimit => \$applied_list_limit, ARGSRef => \%ARGS ); my %AppliedClass = ( 'ticket' => { 'URI' => 'Queues', 'SearchFieldParam' => 'QueueField', 'SearchValueParam' => 'QueueString', }, 'asset' => { 'URI' => 'Assets/Catalogs', 'SearchFieldParam' => 'Field', 'SearchValueParam' => 'String', } ); my $get_applied = sub { my $key = shift; my $lifecycle = RT::Lifecycle->Load( Name => $key, Type => $lifecycles{$key}{'type'} // 'ticket' ); unless ($lifecycle) { RT::Logger->error( 'Unable to load lifecycle ' . $key ); return; } # No applied objects if lifecycle is not a subclass, in case of invalid data return if ref $lifecycle eq 'RT::Lifecycle'; my $list_method = $lifecycle->Type() eq 'asset' ? 'Catalogs' : 'Queues'; my $appliedobjs = $lifecycle->$list_method(); $appliedobjs->RowsPerPage($applied_list_limit); if ( $appliedobjs->CountAll() ) { my $show_more_link = $appliedobjs->CountAll() > $applied_list_limit ? 1 : 0; return ( $appliedobjs, $show_more_link ); } return; }; if ($Submit) { my $changed; foreach my $lifecycle ( keys %lifecycles ) { next if grep { $lifecycle eq $_ } qw/approvals __maps__/; if ( $ARGS{"enable-lifecycle-$lifecycle"} ) { if ( $lifecycles{$lifecycle}{'disabled'} ) { $lifecycles{$lifecycle}{'disabled'} = 0; $changed ||= 1; } } elsif ( !$lifecycles{$lifecycle}{'disabled'} ) { my $class = ( $lifecycles{$lifecycle}{'type'} // '' ) eq 'asset' ? 'RT::Catalogs' : 'RT::Queues'; my $objects = $class->new($session{CurrentUser}); $objects->Limit( FIELD => 'Lifecycle', VALUE => $lifecycle ); my $names = join ', ', map { $_->Name } @{ $objects->ItemsArrayRef }; if ( $names ) { push @results, loc( "Could not disable active lifecycle [_1]: it is used by [_2] [_3]", $lifecycle, lc $class->Table, $names ); } else { $lifecycles{$lifecycle}{'disabled'} = 1; $changed ||= 1; } } } if ($changed) { my ( $ret, $msg ) = RT::Lifecycle->_SaveLifecycles( \%lifecycles, $session{CurrentUser}, ); if ($ret) { push @results, loc("Updated lifecycle configuration"); } else { RT::Logger->error("Could not set lifeycle configuration content: $msg"); push @results, $msg; } } } # This code does automatic redirection if any updates happen. MaybeRedirectForResults( Actions => \@results, Arguments => { FindDisabledLifecycles => $FindDisabledLifecycles }, ); <%ARGS> $Submit => undef $FindDisabledLifecycles => undef