1# -- 2# Copyright (C) 2001-2020 OTRS AG, https://otrs.com/ 3# -- 4# This software comes with ABSOLUTELY NO WARRANTY. For details, see 5# the enclosed file COPYING for license information (GPL). If you 6# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt. 7# -- 8 9package Kernel::System::Console::Command::Admin::Queue::Add; 10 11use strict; 12use warnings; 13 14use parent qw(Kernel::System::Console::BaseCommand); 15 16our @ObjectDependencies = ( 17 'Kernel::System::Group', 18 'Kernel::System::Queue', 19 'Kernel::System::SystemAddress', 20); 21 22sub Configure { 23 my ( $Self, %Param ) = @_; 24 25 $Self->Description('Create a new queue.'); 26 $Self->AddOption( 27 Name => 'name', 28 Description => 'Queue name for the new queue.', 29 Required => 1, 30 HasValue => 1, 31 ValueRegex => qr/.*/smx, 32 ); 33 $Self->AddOption( 34 Name => 'group', 35 Description => 'Group which should be assigned to the new queue.', 36 Required => 1, 37 HasValue => 1, 38 ValueRegex => qr/.*/smx, 39 ); 40 $Self->AddOption( 41 Name => 'system-address-id', 42 Description => 'ID of the system address which should be assigned to the new queue.', 43 Required => 0, 44 HasValue => 1, 45 ValueRegex => qr/\d/smx, 46 ); 47 $Self->AddOption( 48 Name => 'system-address-name', 49 Description => 'System email address which should be assigned to the new queue.', 50 Required => 0, 51 HasValue => 1, 52 ValueRegex => qr/.*/smx, 53 ); 54 $Self->AddOption( 55 Name => 'comment', 56 Description => 'Comment for the new queue.', 57 Required => 0, 58 HasValue => 1, 59 ValueRegex => qr/.*/smx, 60 ); 61 $Self->AddOption( 62 Name => 'unlock-timeout', 63 Description => 'Unlock timeout in minutes for the new queue.', 64 Required => 0, 65 HasValue => 1, 66 ValueRegex => qr/\d/smx, 67 ); 68 $Self->AddOption( 69 Name => 'first-response-time', 70 Description => 'Ticket first response time in minutes for the new queue.', 71 Required => 0, 72 HasValue => 1, 73 ValueRegex => qr/\d/smx, 74 ); 75 $Self->AddOption( 76 Name => 'update-time', 77 Description => 'Ticket update time in minutes for the new queue.', 78 Required => 0, 79 HasValue => 1, 80 ValueRegex => qr/\d/smx, 81 ); 82 $Self->AddOption( 83 Name => 'solution-time', 84 Description => 'Ticket solution time in minutes for the new queue.', 85 Required => 0, 86 HasValue => 1, 87 ValueRegex => qr/\d/smx, 88 ); 89 $Self->AddOption( 90 Name => 'calendar', 91 Description => 'Calendar order number for the new queue.', 92 Required => 0, 93 HasValue => 1, 94 ValueRegex => qr/.*/smx, 95 ); 96 97 return; 98} 99 100sub Run { 101 my ( $Self, %Param ) = @_; 102 103 $Self->Print("<yellow>Adding a new queue...</yellow>\n"); 104 105 # check group 106 my $Group = $Self->GetOption('group'); 107 my $GroupID = $Kernel::OM->Get('Kernel::System::Group')->GroupLookup( Group => $Group ); 108 if ( !$GroupID ) { 109 $Self->PrintError("Found no GroupID for $Group\n"); 110 return $Self->ExitCodeError(); 111 } 112 113 my $SystemAddressID = $Self->GetOption('system-address-id'); 114 my $SystemAddressName = $Self->GetOption('system-address-name'); 115 116 # check System Address 117 if ($SystemAddressName) { 118 my %SystemAddressList = $Kernel::OM->Get('Kernel::System::SystemAddress')->SystemAddressList( 119 Valid => 1 120 ); 121 ADDRESS: 122 for my $ID ( sort keys %SystemAddressList ) { 123 my %SystemAddressInfo = $Kernel::OM->Get('Kernel::System::SystemAddress')->SystemAddressGet( 124 ID => $ID 125 ); 126 if ( $SystemAddressInfo{Name} eq $SystemAddressName ) { 127 $SystemAddressID = $ID; 128 last ADDRESS; 129 } 130 } 131 if ( !$SystemAddressID ) { 132 $Self->PrintError("Address $SystemAddressName not found\n"); 133 return $Self->ExitCodeError(); 134 } 135 } 136 137 # add queue 138 my $Success = $Kernel::OM->Get('Kernel::System::Queue')->QueueAdd( 139 Name => $Self->GetOption('name'), 140 GroupID => $GroupID, 141 SystemAddressID => $SystemAddressID || $Self->GetOption('system-address-id') || undef, 142 Comment => $Self->GetOption('comment'), 143 UnlockTimeout => $Self->GetOption('unlock-timeout'), 144 FirstResponseTime => $Self->GetOption('first-response-time'), 145 UpdateTime => $Self->GetOption('update-time'), 146 SolutionTime => $Self->GetOption('solution-time'), 147 Calendar => $Self->GetOption('calendar'), 148 ValidID => 1, 149 UserID => 1, 150 ); 151 152 # error handling 153 if ( !$Success ) { 154 $Self->PrintError("Can't create queue.\n"); 155 return $Self->ExitCodeError(); 156 } 157 158 $Self->Print("<green>Done.</green>\n"); 159 160 return $Self->ExitCodeOk(); 161} 162 1631; 164