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