lib/Kernel/System/Escalation.pm

filter: Statementstmt 19.6% 11 / 56 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 3 / 6 Podpod 0.0% 0 / 3 totaltotal 15.7% 14 / 89 CC 15 SCAR 41.1
CC
15
Cov
14%
ESCLAdd
110.0
ESCLGet
20.0
new
12.0
CRAP 61.0
↑ Summary script/otrs.Escalation.pl »
1 # --
2 # Kernel/System/Escalation.pm - all sla function
3 # Copyright (C) 2001-2013 OTRS AG, http://otrs.org/
4 # --
5 # $Id: Escalation.pm, v 1.0 2013/02/04 14:38:57 en Exp $
6 # --
7 # This software comes with ABSOLUTELY NO WARRANTY. For details, see
8 # the enclosed file COPYING for license information (AGPL). If you
9 # did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
10 # --
11  
12 package Kernel::System::Escalation;
13  
14 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17  
18  
19 1 ▶use vars qw(@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 $VERSION = qw($Revision: 1.0 $) [1];
21  
22  
23 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
24 0 my ( $Type, %Param ) = @_;
25
26 # allocate new hash for object
27 0 my $Self = {};
28 0 bless( $Self, $Type );
29
30 # check needed objects
31 0 for my $Object (qw(DBObject ConfigObject EncodeObject LogObject MainObject)) {
32 0 ▶ $Self->{$Object} = $Param{$Object} || die "Got no $Object!";
Condition0%0/2
$Param{$Object} || die("Got no $Object!")
l!l
00
MC/DC0%0/1
$Param{$Object} || die("Got no $Object!")
$Param{$Object}
Truth table0%0/2
A
A= $Param{$Object}
Aresult
11
00
33 }
34
35 0 return $Self;
36 }
37  
38  
39 0 ▶sub ESCLGet {
Subroutine ESCLGet: not called CC=4 SCAR=30.0
Pod undocumented
40 0 my ( $Self, %Param ) = @_;
41
42 # check needed stuff
43 0 for my $Argument (qw(SLAID UserID)) {
44 0 ▶ if ( !$Param{$Argument} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Param{$Argument}) 0 0 0
45 0 $Self->{LogObject}->Log( Priority => 'error', Message => "Need $Argument!" );
46 0 return;
47 }
48 }
49
50 # check if valid sla and update escalation
51 #update escalation set valid_id = 2 where sla_id in (select id from sla where valid_id = 2);
52 $Self->{DBObject}->Prepare(
53 0 SQL => 'update escalation set valid_id = 2 where sla_id in (select id from sla where valid_id = 2)',
54 );
55
56 $Self->{DBObject}->Prepare(
57 0 SQL => 'update escalation set valid_id = 3 where sla_id in (select id from sla where valid_id = 3)',
58 );
59
60 $Self->{DBObject}->Prepare(
61 0 SQL => 'update escalation set valid_id = 1 where sla_id in (select id from sla where valid_id = 1)',
62 );
63
64 # get escalation from db
65 $Self->{DBObject}->Prepare(
66 SQL => 'SELECT sla_id, notify_type, level, notify_to, notify_perc, valid_id FROM escalation WHERE valid_id = 1 and sla_id = ?',
67 0 Bind => [ \$Param{SLAID} ],
68 );
69
70 # fetch the result
71 0 my %ESCLData;
72 my @Row;
73 0 ▶ while ( @Row = $Self->{DBObject}->FetchrowArray() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@Row = $Self->{"DBObject"}->FetchrowArray) 0 0 0
74 0 $ESCLData{$Row[0]}{$Row[1]}{$Row[2]}{Notify_To} = $Row[3];
75 0 $ESCLData{$Row[0]}{$Row[1]}{$Row[2]}{Notify_Perc} = $Row[4];
76 0 $ESCLData{$Row[0]}{$Row[1]}{$Row[2]}{ValidID} = $Row[5];
77 }
78
79 0 return %ESCLData;
80 }
81  
82  
83 0 ▶sub ESCLAdd {
Subroutine ESCLAdd: not called CC=10 SCAR=47.0
Pod undocumented
84 0 my ( $Self, %Param ) = @_;
85
86 # check needed stuff
87 0 for my $Argument (qw(SLAID Type Level ValidID)) {
88 0 ▶ if ( !$Param{$Argument} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Param{$Argument}) 0 0 0
89 $Self->{LogObject}->Log(
90 0 Priority => 'error',
91 Message => "Need $Argument!",
92 );
93 0 return;
94 }
95 }
96
97 # set default values
98 0 ▶ $Param{Notify_To} ||= '';
Condition0%0/2
$Param{"Notify_To"} ||= ""
l!l
00
MC/DC0%0/1
$Param{"Notify_To"} ||= ""
$Param{"Notify_To"}
Truth table0%0/2
A
A= $Param{"Notify_To"}
Aresult
11
00
99
100 # find exiting esclation's with the same name
101 $Self->{DBObject}->Prepare(
102 SQL => 'SELECT sla_id FROM escalation WHERE sla_id = ? and notify_type = ? and level = ?',
103 0 Bind => [ \$Param{SLAID}, \$Param{Type}, \$Param{Level} ],
104 Limit => 1,
105 );
106
107
108 # fetch the result
109 0 my $NoAdd;
110 0 ▶ while ( $Self->{DBObject}->FetchrowArray() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Self->{"DBObject"}->FetchrowArray) 0 0 0
111 0 $NoAdd = 1;
112 }
113
114 # abort insert of new sla, if name already exists
115 0 ▶ if ($NoAdd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($NoAdd) 0 0 0
116
117 $Self->{DBObject}->Prepare(
118 SQL => 'DELETE FROM escalation WHERE sla_id = ? and notify_type = ? and level = ?',
119 0 Bind => [ \$Param{SLAID}, \$Param{Type}, \$Param{Level} ],
120 );
121
122 }
123 0 undef $NoAdd;
124
125 # add escalation to database
126 return if !$Self->{DBObject}->Do(
127
128 SQL => 'INSERT INTO escalation '
129 . '(sla_id, notify_type, level, notify_to, '
130 . 'notify_perc, valid_id) VALUES '
131 . '(?, ?, ?, ?, ?, ?)',
132 Bind => [
133 \$Param{SLAID}, \$Param{Type}, \$Param{Level}, \$Param{Notify_To}, \$Param{Notify_Perc}, \$Param{ValidID},
134 0 ▶ ],
Branch: 1 branch
BranchTrueFalseTotal
unless $Self->{"DBObject"}->Do("SQL", "INSERT INTO escalation (sla_id, notify_type, level, notify_to, notify_perc, valid_id) VALUES (?, ?, ?, ?, ?, ?)", "Bind", [\$Param{"SLAID"}, \$Param{"Type"}, \$Param{"Level"}, \$Param{"Notify_To"}, \$Param{"Notify_Perc"}, \$Param{"ValidID"}]) 0 0 0
135 );
136
137 # get inserted data
138 return if !$Self->{DBObject}->Prepare(
139 SQL => 'SELECT sla_id FROM escalation WHERE sla_id = ? and notify_type = ? and level = ?',
140 0 ▶ Bind => [ \$Param{SLAID}, \$Param{Type}, \$Param{Level} ],
Branch: 1 branch
BranchTrueFalseTotal
unless $Self->{"DBObject"}->Prepare("SQL", "SELECT sla_id FROM escalation WHERE sla_id = ? and notify_type = ? and level = ?", "Bind", [\$Param{"SLAID"}, \$Param{"Type"}, \$Param{"Level"}], "Limit", 1) 0 0 0
141 Limit => 1,
142 );
143
144 # fetch the result
145 0 my $SLAID;
146 0 ▶ while ( my @Row = $Self->{DBObject}->FetchrowArray() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@Row) = $Self->{"DBObject"}->FetchrowArray) 0 0 0
147 0 $SLAID = $Row[0];
148 }
149
150 # check escalation sla_id
151 0 ▶ if ( !$SLAID ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($SLAID) 0 0 0
152 $Self->{LogObject}->Log(
153 0 Priority => 'error',
154 Message => "Can't find SLAID for '$Param{SLAID}'!",
155 );
156 0 return;
157 }
158
159 #update escalation set valid_id = 2 where sla_id in (select id from sla where valid_id = 2);
160 $Self->{DBObject}->Prepare(
161 0 SQL => 'update escalation set valid_id = 2 where sla_id in (select id from sla where valid_id = 2)',
162 );
163
164 $Self->{DBObject}->Prepare(
165 0 SQL => 'update escalation set valid_id = 3 where sla_id in (select id from sla where valid_id = 3)',
166 );
167
168 0 return $SLAID;
169 }
170  
171 1 1;
172  
173  
174 __END__
↑ Summary script/otrs.Escalation.pl »