Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
best-practical
rt-extension-sla
Commits
79e24268
Commit
79e24268
authored
Apr 20, 2012
by
Ruslan Zakirov
Browse files
support per queue timezones
parent
6c7862c1
Changes
5
Hide whitespace changes
Inline
Side-by-side
MANIFEST
View file @
79e24268
...
...
@@ -33,3 +33,4 @@ t/business_hours.t
t/due.t
t/queue.t
t/starts.t
t/timezone.t
lib/RT/Action/SLA_SetDue.pm
View file @
79e24268
...
...
@@ -44,12 +44,14 @@ sub Commit {
);
my
$response_due
=
$self
->
Due
(
Ticket
=>
$ticket
,
Level
=>
$level
,
Type
=>
$is_requestor
?
'
Response
':
'
KeepInLoop
',
Time
=>
$last_reply
->
CreatedObj
->
Unix
,
);
my
$resolve_due
=
$self
->
Due
(
Ticket
=>
$ticket
,
Level
=>
$level
,
Type
=>
'
Resolve
',
Time
=>
$ticket
->
CreatedObj
->
Unix
,
...
...
lib/RT/Action/SLA_SetStarts.pm
View file @
79e24268
...
...
@@ -34,6 +34,7 @@ sub Commit {
}
my
$starts
=
$self
->
Starts
(
Ticket
=>
$ticket
,
Level
=>
$level
,
Time
=>
$ticket
->
CreatedObj
->
Unix
,
);
...
...
lib/RT/Extension/SLA.pm
View file @
79e24268
...
...
@@ -342,14 +342,6 @@ sub BusinessHours {
return
$res
;
}
sub
CalcBusinessHours
{
my
$self
=
shift
;
my
$meta
=
shift
;
my
$method
=
shift
;
my
$bhours
=
$self
->
BusinessHours
(
$meta
->
{'
BusinessHours
'}
);
return
$bhours
->
$method
(
@
_
);
}
sub
Agreement
{
my
$self
=
shift
;
my
%args
=
(
...
...
@@ -385,15 +377,7 @@ sub Agreement {
return
undef
;
}
if
(
$args
{'
Time
'}
and
my
$tmp
=
$meta
->
{'
OutOfHours
'}{
$args
{'
Type
'}
}
)
{
if
(
$self
->
CalcBusinessHours
(
$meta
,
first_after
=>
$args
{'
Time
'}
)
!=
$args
{'
Time
'}
)
{
foreach
(
qw(RealMinutes BusinessMinutes)
)
{
next
unless
$tmp
->
{
$_
};
$res
{
$_
}
||=
0
;
$res
{
$_
}
+=
$tmp
->
{
$_
};
}
}
}
$res
{'
OutOfHours
'}
=
$meta
->
{'
OutOfHours
'}{
$args
{'
Type
'}
};
$args
{'
Queue
'}
||=
$args
{'
Ticket
'}
->
QueueObj
if
$args
{'
Ticket
'};
if
(
$args
{'
Queue
'}
&&
ref
$
RT::
ServiceAgreements
{'
QueueDefault
'}{
$args
{'
Queue
'}
->
Name
}
)
{
...
...
@@ -408,22 +392,42 @@ sub Agreement {
sub
Due
{
my
$self
=
shift
;
my
%args
=
(
Level
=>
undef
,
Type
=>
undef
,
Time
=>
undef
,
@
_
);
return
$self
->
CalculateTime
(
@
_
);
}
my
$agreement
=
$self
->
Agreement
(
%args
);
sub
Starts
{
my
$self
=
shift
;
return
$self
->
CalculateTime
(
@
_
,
Type
=>
'
Starts
'
);
}
sub
CalculateTime
{
my
$self
=
shift
;
my
%args
=
(
@
_
);
my
$agreement
=
$self
->
Agreement
(
@
_
);
return
undef
unless
$agreement
;
local
$ENV
{'
TZ
'}
=
$ENV
{'
TZ
'};
$ENV
{'
TZ
'}
=
$agreement
->
{'
Timezone
'}
if
$agreement
->
{'
Timezone
'};
my
$bhours
=
$self
->
BusinessHours
(
$agreement
->
{'
BusinessHours
'}
);
my
$res
=
$args
{'
Time
'};
if
(
$agreement
->
{'
OutOfHours
'}
&&
$bhours
->
first_after
(
$res
)
!=
$res
)
{
foreach
(
qw(RealMinutes BusinessMinutes)
)
{
next
unless
my
$mod
=
$agreement
->
{'
OutOfHours
'}{
$_
};
(
$agreement
->
{
$_
}
||=
0
)
+=
$mod
;
}
}
if
(
defined
$agreement
->
{'
BusinessMinutes
'}
)
{
if
(
$agreement
->
{'
BusinessMinutes
'}
)
{
$res
=
$self
->
CalcBusinessHours
(
$agreement
,
add_seconds
=>
$res
,
60
*
$agreement
->
{'
BusinessMinutes
'},
$res
=
$bhours
->
add_seconds
(
$res
,
60
*
$agreement
->
{'
BusinessMinutes
'},
);
}
else
{
$res
=
$
self
->
CalcBusinessHours
(
$agreement
,
first_after
=>
$res
);
$res
=
$
bhours
->
first_after
(
$res
);
}
}
$res
+=
60
*
$agreement
->
{'
RealMinutes
'}
...
...
@@ -432,11 +436,6 @@ sub Due {
return
$res
;
}
sub
Starts
{
my
$self
=
shift
;
return
$self
->
Due
(
@
_
,
Type
=>
'
Starts
'
);
}
sub
GetCustomField
{
my
$self
=
shift
;
my
%args
=
(
Ticket
=>
undef
,
CustomField
=>
'
SLA
',
@
_
);
...
...
@@ -472,7 +471,7 @@ sub GetDefaultServiceLevel {
if
(
my
$info
=
$
RT::
ServiceAgreements
{'
QueueDefault
'}{
$args
{'
Queue
'}
->
Name
}
)
{
return
$info
unless
ref
$info
;
return
$info
->
{'
Level
'};
return
$info
->
{'
Level
'}
||
$
RT::
ServiceAgreements
{'
Default
'}
;
}
}
return
$
RT::
ServiceAgreements
{'
Default
'};
...
...
t/timezone.t
0 → 100644
View file @
79e24268
#!/usr/bin/perl
use
strict
;
use
warnings
;
use
Test::
MockTime
qw( :all )
;
use
RT::Extension::SLA::
Test
tests
=>
11
;
my
$test
=
'
RT::Extension::SLA::Test
';
my
$ru_queue
=
$test
->
load_or_create_queue
(
Name
=>
'
RU
'
);
ok
$ru_queue
&&
$ru_queue
->
id
,
'
created RU queue
';
my
$us_queue
=
$test
->
load_or_create_queue
(
Name
=>
'
US
'
);
ok
$us_queue
&&
$ru_queue
->
id
,
'
created US queue
';
no
warnings
'
once
';
%
RT::
ServiceAgreements
=
(
Default
=>
2
,
QueueDefault
=>
{
RU
=>
{
Timezone
=>
'
Europe/Moscow
'
},
US
=>
{
Timezone
=>
'
America/New_York
'
},
},
Levels
=>
{
'
2
'
=>
{
Resolve
=>
{
BusinessMinutes
=>
60
*
2
}
},
},
);
set_absolute_time
('
2007-01-01T22:00:00Z
');
note
'
check dates in US queue
';
{
my
$ticket
=
RT::
Ticket
->
new
(
$
RT::
SystemUser
);
my
(
$id
)
=
$ticket
->
Create
(
Queue
=>
'
US
',
Subject
=>
'
xxx
'
);
ok
(
$id
,
"
created ticket #
$id
"
);
my
$start
=
$ticket
->
StartsObj
->
ISO
(
Timezone
=>
'
utc
'
);
is
(
$start
,
'
2007-01-01 22:00:00
',
'
Start date is right
'
);
my
$due
=
$ticket
->
DueObj
->
ISO
(
Timezone
=>
'
utc
'
);
is
(
$due
,
'
2007-01-02 15:00:00
',
'
Due date is right
'
);
}
note
'
check dates in RU queue
';
{
my
$ticket
=
RT::
Ticket
->
new
(
$
RT::
SystemUser
);
my
(
$id
)
=
$ticket
->
Create
(
Queue
=>
'
RU
',
Subject
=>
'
xxx
'
);
ok
(
$id
,
"
created ticket #
$id
"
);
my
$start
=
$ticket
->
StartsObj
->
ISO
(
Timezone
=>
'
utc
'
);
is
(
$start
,
'
2007-01-02 06:00:00
',
'
Start date is right
'
);
my
$due
=
$ticket
->
DueObj
->
ISO
(
Timezone
=>
'
utc
'
);
is
(
$due
,
'
2007-01-02 08:00:00
',
'
Due date is right
'
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment