CloningQueues: Difference between revisions

From Request Tracker Wiki
Jump to navigation Jump to search
m (2 revisions imported)
 
(No difference)

Latest revision as of 15:03, 6 April 2016

This provides the functionality of cloning existing queues including templates, scrips, privileges and custom fields during queue creation. It requires the modification Admin/Queues/Modify.html to include 2 callback points and 2 callbacks in local/html/Callbacks/. I can be contacted at ccelhf@nus.edu.sg to answer any queries regarding this customization.

NOTE: this customization was only tested on RT3.6.7, please let me know if it works on other releases.

OK -- This doesn't work in 3.8.8 :) -- TomL

Admin/Queues/Modify.html

Place the following code after the "Description" input field.

<& /Elements/Callback, %ARGS, _CallbackName => 'CloneFrom' &>

and this before the "'Process'Links" Callback.

$m->comp('/Elements/Callback', %ARGS, _CallbackName => 'Clone', newqueue => $QueueObj->Id, clonequeue => $CloneQueue);


You will need the following 2 callbacks in your local/html/Callbacks/

'Admin/Queues/Modify.html/Clone'From

% if ( $ARGS{Create} == 1 ) {
<tr>
<td align="right">Clone from: </td>
<td colspan="3">
<& /Elements/SelectNewTicketQueue, Name=>'CloneQueue', ShowNullOption=>1 &>
</td>
</tr>
% }

and

Admin/Queues/Modify.html/Clone

<%init>
 return if ($clonequeue !~ /\d+/);
 
 my $NewQueueObj = new RT::Queue($session{'CurrentUser'});
 $NewQueueObj->Load($newqueue);
 
 my $CloneQueueObj = new RT::Queue($session{'CurrentUser'});
 $CloneQueueObj->Load($clonequeue);
 
 #### attach all custom fields from clone queue to the new queue
 
 my $objCFs = RT::ObjectCustomFields->new($RT::SystemUser);
 $objCFs->LimitToObjectId($clonequeue);
 
 my $objNewCF = RT::ObjectCustomField->new($session{'CurrentUser'});
 while (my $cf = $objCFs->Next) {
     $objNewCF->Create(ObjectId=>$newqueue,SortOrder=>$cf->SortOrder,CustomField=>$cf->CustomField);
 }
 
 
 #### assign group and user privileges from clone queue to the new queue
 
 my $objACL = RT::ACL->new($RT::SystemUser);
 $objACL->LimitToObject($CloneQueueObj);
 
 my $objACE = RT::ACE->new($session{'CurrentUser'});
 my $objGroup = RT::Group->new($session{'CurrentUser'});
 
 while (my $acl = $objACL->Next) {
     $objGroup->LoadQueueRoleGroup(Queue=>$newqueue, Type=>$acl->PrincipalType);
     $objACE->Create(Object=>$NewQueueObj,
                     PrincipalId=>$objGroup->id || $acl->PrincipalId,
                     PrincipalType=>$acl->PrincipalType,
                     RightName=>$acl->RightName);
 }
 
 
 #### create templates for the new queue
 my $objTemplates = RT::Templates->new($RT::SystemUser);
 $objTemplates->LimitToQueue($clonequeue);
 
 my $objTemplate = RT::Template->new($session{'CurrentUser'});
 
 while (my $t = $objTemplates->Next) {
     $objTemplate->Create(Content=>$t->Content,Queue=>$newqueue,Description=>$t->Description,Type=>$t->Type,Name=>$t->Name);
 }
 
 
 #### create scrips for the new queue
 
 my $objScrips = RT::Scrips->new($RT::SystemUser);
 $objScrips->LimitToQueue($clonequeue);
 
 my $objScrip = RT::Scrip->new($session{'CurrentUser'});
 
 while (my $s = $objScrips->Next) {
     my $template;
     $objTemplate->Load($s->Template);
     if ($objTemplate->Queue == 0) { ### global template
             $template = $s->Template;
     }
     else { ### local template, go find out which one
             my $objLocalTemplate = RT::Template->new($session{'CurrentUser'});
             $objLocalTemplate->LoadQueueTemplate(Queue=>$newqueue,Name=>$objTemplate->Name);
             $template = $objLocalTemplate->id;
     }
     $objScrip->Create(
             Queue=>$newqueue,
             Description=>$s->Description,
             ScripAction=>$s->ScripAction,
             ScripCondition=>$s->ScripCondition,
             CustomPrepareCode=>$s->CustomPrepareCode,
             CustomCommitCode=>$s->CustomCommitCode,
             CustomIsApplicableCode=>$s->CustomIsApplicableCode,
             Stage=>$s->Stage,
             Template=>$template);
 
 }
 
 </%init>
 
 <%args>
 $newqueue => undef
 $clonequeue => undef
 </%args>