init III
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 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::ITSMChange::ITSMWorkOrder::Event::ToolBarMyWorkOrdersCacheDelete;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Cache',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Data Event Config UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# set the cache type prefix
|
||||
my $CacheTypePrefix = 'ITSMChangeManagementToolBarMyWorkOrders';
|
||||
|
||||
# handle adding of a workorder
|
||||
if ( $Param{Event} eq 'WorkOrderAddPost' ) {
|
||||
|
||||
# do nothing if the WorkOrderAgentID was not set
|
||||
return 1 if !$Param{Data}->{WorkOrderAgentID};
|
||||
|
||||
# set the cache type
|
||||
my $CacheType = $CacheTypePrefix . $Param{Data}->{WorkOrderAgentID};
|
||||
|
||||
# delete the cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
|
||||
Type => $CacheType,
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
# handle update of a workorder
|
||||
elsif ( $Param{Event} eq 'WorkOrderUpdatePost' ) {
|
||||
|
||||
# make sure the data is initialized
|
||||
$Param{Data}->{WorkOrderAgentID} ||= '';
|
||||
$Param{Data}->{OldWorkOrderData}->{WorkOrderAgentID} ||= '';
|
||||
|
||||
# do nothing if the WorkOrderAgentID did not change
|
||||
return 1
|
||||
if $Param{Data}->{WorkOrderAgentID} eq
|
||||
$Param{Data}->{OldWorkOrderData}->{WorkOrderAgentID};
|
||||
|
||||
# set the cache type postfix
|
||||
my @CacheTypePostfixes = (
|
||||
$Param{Data}->{WorkOrderAgentID},
|
||||
$Param{Data}->{OldWorkOrderData}->{WorkOrderAgentID},
|
||||
);
|
||||
|
||||
# delete the cache for the old and the current workorder agent
|
||||
CACHETYPEPOSTFIX:
|
||||
for my $CacheTypePostfix (@CacheTypePostfixes) {
|
||||
|
||||
# do nothing if the WorkOrderAgentID was not set
|
||||
next CACHETYPEPOSTFIX if !$CacheTypePostfix;
|
||||
|
||||
# set the cache type
|
||||
my $CacheType = $CacheTypePrefix . $CacheTypePostfix;
|
||||
|
||||
# delete the cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
|
||||
Type => $CacheType,
|
||||
);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
# handle deleting a workorder
|
||||
elsif ( $Param{Event} eq 'WorkOrderDeletePost' ) {
|
||||
|
||||
# do nothing if the WorkOrderAgentID was not set
|
||||
return 1 if !$Param{Data}->{OldWorkOrderData}->{WorkOrderAgentID};
|
||||
|
||||
# set the cache type
|
||||
my $CacheType = $CacheTypePrefix . $Param{Data}->{OldWorkOrderData}->{WorkOrderAgentID};
|
||||
|
||||
# delete the cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
|
||||
Type => $CacheType,
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,165 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 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::ITSMChange::ITSMWorkOrder::Event::WorkOrderActualTimesSet;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::DateTime',
|
||||
'Kernel::System::ITSMChange::ITSMStateMachine',
|
||||
'Kernel::System::ITSMChange::ITSMWorkOrder',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Needed (qw(Data Event Config UserID)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# handle WorkOrderUpdate event
|
||||
if ( $Param{Event} eq 'WorkOrderUpdatePost' ) {
|
||||
|
||||
# get WorkOrder
|
||||
my $WorkOrder = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderGet(
|
||||
WorkOrderID => $Param{Data}->{WorkOrderID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check error
|
||||
return if !$WorkOrder;
|
||||
|
||||
# get actual start time from workorder
|
||||
my $ActualStartTime = $WorkOrder->{ActualStartTime};
|
||||
|
||||
# get configured workorder states when to set actual start time
|
||||
my $ConfiguredWorkOrderStartStates
|
||||
= $Kernel::OM->Get('Kernel::Config')->Get('ITSMWorkOrder::ActualStartTimeSet::States');
|
||||
|
||||
# convert into hash for easier lookup
|
||||
my %ActualStartTimeSetStates = map { $_ => 1 } @{$ConfiguredWorkOrderStartStates};
|
||||
|
||||
# get current time stamp
|
||||
my $CurrentTimeStamp = $Kernel::OM->Create('Kernel::System::DateTime')->ToString();
|
||||
|
||||
# check if ActualStartTime is empty,
|
||||
# and WorkOrderState is in an ActualStartTimeSetState
|
||||
if ( !$ActualStartTime && $ActualStartTimeSetStates{ $WorkOrder->{WorkOrderState} } ) {
|
||||
|
||||
# set the actual start time
|
||||
my $Success = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderUpdate(
|
||||
WorkOrderID => $Param{Data}->{WorkOrderID},
|
||||
ActualStartTime => $CurrentTimeStamp,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check error
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message =>
|
||||
"Could not set ActualStartTime for WorkOrderID '$Param{Data}->{WorkOrderID}'!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# remember the just set actual start time
|
||||
$ActualStartTime = $CurrentTimeStamp;
|
||||
}
|
||||
|
||||
# check if the ActualEndTime is empty
|
||||
# and the current workorder state is an end state
|
||||
if ( !$WorkOrder->{ActualEndTime} ) {
|
||||
|
||||
# get the possible next state ids
|
||||
my $NextStateIDsRef = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMStateMachine')->StateTransitionGet(
|
||||
StateID => $WorkOrder->{WorkOrderStateID},
|
||||
Class => 'ITSM::ChangeManagement::WorkOrder::State',
|
||||
) || [];
|
||||
|
||||
# if there is only one next state, which is also 0,
|
||||
# which means that this is an end state
|
||||
if ( ( scalar @{$NextStateIDsRef} == 1 ) && ( !$NextStateIDsRef->[0] ) ) {
|
||||
|
||||
# if no actual start time is set, use the current time
|
||||
if ( !$ActualStartTime ) {
|
||||
$ActualStartTime = $CurrentTimeStamp;
|
||||
}
|
||||
|
||||
# increase the current time stamp by one second to avoid the case that
|
||||
# actual start and end times are the same
|
||||
my $ActualEndTime = $Kernel::OM->Create(
|
||||
'Kernel::System::DateTime',
|
||||
ObjectParams => {
|
||||
String => $CurrentTimeStamp,
|
||||
},
|
||||
);
|
||||
$ActualEndTime->Add(
|
||||
Seconds => 1,
|
||||
);
|
||||
$ActualEndTime = $ActualEndTime->ToString();
|
||||
|
||||
# set the actual end time,
|
||||
# and if the actual start time was not set, set it also
|
||||
my $Success = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderUpdate(
|
||||
WorkOrderID => $Param{Data}->{WorkOrderID},
|
||||
ActualStartTime => $ActualStartTime,
|
||||
ActualEndTime => $ActualEndTime,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check error
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message =>
|
||||
"Could not set ActualStartTime for WorkOrderID '$Param{Data}->{WorkOrderID}'!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# error
|
||||
else {
|
||||
|
||||
# an unknown event
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "$Param{Event} is an unknown event for this eventhandler!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,168 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 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::ITSMChange::ITSMWorkOrder::Event::WorkOrderNumberCalc;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::ITSMChange::ITSMWorkOrder',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Needed (qw(Data Event Config UserID)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check if recalculation of workorder numbers is needed
|
||||
return 1 if $Param{Data}->{NoNumberCalc};
|
||||
|
||||
# handle WorkOrderUpdate and WorkOrderDeletePost events
|
||||
if ( $Param{Event} =~ m{ \A ( WorkOrderUpdatePost | WorkOrderDeletePost ) \z }xms ) {
|
||||
|
||||
# recalculate WorkOrder numbers
|
||||
# the ChangeID is in the OldWorkOrderData so we do not need to make a WorkOrderGet() here
|
||||
return if !$Self->_WorkOrderNumberCalc(
|
||||
ChangeID => $Param{Data}->{OldWorkOrderData}->{ChangeID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
|
||||
# error
|
||||
else {
|
||||
|
||||
# an unknown event
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "$Param{Event} is an unknown event for this eventhandler!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head1 PRIVATE INTERFACE
|
||||
|
||||
=head2 _WorkOrderNumberCalc()
|
||||
|
||||
This method actually recalculates the WorkOrderNumbers for the C<workorders> of
|
||||
the given change.
|
||||
It returns 1 on success, C<undef> otherwise.
|
||||
|
||||
my $Success = $EventObject->_WorkOrderNumberCalc(
|
||||
ChangeID => 123,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub _WorkOrderNumberCalc {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check for needed stuff - ChangeID and UserID
|
||||
for my $Needed (qw(ChangeID UserID)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# define the order direction for each attribute
|
||||
my %OrderDirection = (
|
||||
PlannedStartTime => 'Up',
|
||||
PlannedEndTime => 'Down',
|
||||
WorkOrderID => 'Up',
|
||||
);
|
||||
|
||||
# define the OrderBy array
|
||||
my @OrderBy = (
|
||||
'PlannedStartTime',
|
||||
'PlannedEndTime',
|
||||
'WorkOrderID',
|
||||
);
|
||||
|
||||
# define the OrderByDirection array
|
||||
my @OrderByDirection = map { $OrderDirection{$_} } @OrderBy;
|
||||
|
||||
# use WorkOrderSearch: Search for given IDs, ordered by:
|
||||
# PlannedStartTime, PlannedEndTime, WorOrderID
|
||||
my $SortedWorkOrderIDs = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderSearch(
|
||||
ChangeIDs => [ $Param{ChangeID} ],
|
||||
OrderBy => \@OrderBy,
|
||||
OrderByDirection => \@OrderByDirection,
|
||||
UserID => $Param{UserID},
|
||||
) || [];
|
||||
|
||||
# counter - used as WorkOrderNumber
|
||||
my $Counter = 0;
|
||||
|
||||
# to store the WorkOrderIDs and their new WorkOrderNumbers
|
||||
my %NewWorkOrderNumber;
|
||||
|
||||
# set new WorkOrderNumber
|
||||
WORKORDERID:
|
||||
for my $WorkOrderID ( @{$SortedWorkOrderIDs} ) {
|
||||
|
||||
# increment Counter to get new WorkOrderNumber
|
||||
$Counter++;
|
||||
|
||||
# get WorkOrder
|
||||
my $WorkOrder = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderGet(
|
||||
WorkOrderID => $WorkOrderID,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# update only when Number changed - to avoid infinit loops
|
||||
next WORKORDERID if $Counter == $WorkOrder->{WorkOrderNumber};
|
||||
|
||||
# store the new WorkOrderNumber for this WorkOrderID
|
||||
$NewWorkOrderNumber{$WorkOrderID} = $Counter;
|
||||
}
|
||||
|
||||
# update the workorders that need a new WorkOrderNumber
|
||||
for my $WorkOrderID ( sort keys %NewWorkOrderNumber ) {
|
||||
|
||||
# update each workorder, prevent recalculation of the WorkOrderNumber again
|
||||
my $CouldUpdateWorkOrder = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderUpdate(
|
||||
WorkOrderID => $WorkOrderID,
|
||||
WorkOrderNumber => $NewWorkOrderNumber{$WorkOrderID},
|
||||
NoNumberCalc => 1,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user