-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMergeTicket.pm
More file actions
179 lines (152 loc) · 5.91 KB
/
Copy pathMergeTicket.pm
File metadata and controls
179 lines (152 loc) · 5.91 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# --
# Kernel/System::ProcessManagement::TransitionAction::MergeTicket.pm - to merge tickets from a Process
# Copyright (C) 2013 Nomadic Solutions , http://gridshield.net/
# -- alvaro@gridshield.net
# $Id: MergeTicket.pm,v 1.00 2013/04/001 11:27:42 ub Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
package Kernel::System::ProcessManagement::TransitionAction::MergeTicket;
use Kernel::System::SystemAddress;
use Kernel::System::CustomerUser;
use Kernel::System::CheckItem;
use Kernel::System::Web::UploadCache;
use Kernel::System::State;
use Kernel::System::LinkObject;
use Kernel::System::DynamicField;
use Kernel::System::DynamicField::Backend;
use Kernel::System::VariableCheck qw(:all);
use Mail::Address;
# ---
# ITSM
# ---
use Kernel::System::Service;
use Kernel::System::GeneralCatalog;
use Kernel::System::ITSMCIPAllocate;
# ---
use utf8;
use Data::Dumper;
use vars qw($VERSION);
$VERSION = qw($Revision: 1.3 $) [1];
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {%Param};
bless( $Self, $Type );
# check needed objects
for my $Needed (
qw(ParamObject DBObject TicketObject LayoutObject LogObject QueueObject MainObject ConfigObject)
#qw(ConfigObject LogObject EncodeObject DBObject MainObject TimeObject TicketObject)
)
{
# die "Got no $Needed!" if !$Param{$Needed};
$Self->{$Needed} = $Param{$Needed};
}
$Self->{LinkObject} = Kernel::System::LinkObject->new(%Param);
$Self->{DynamicFieldObject} = Kernel::System::DynamicField->new(%Param);
$Self->{BackendObject} = Kernel::System::DynamicField::Backend->new(%Param);
return $Self;
}
sub Run {
my ( $Self, %Param ) = @_;
for my $Needed (qw(UserID Ticket Config )) {
if ( !defined $Param{$Needed} ) {
$Self->{LogObject}->Log(
Priority => 'error',
Message => "MergeTicket.pm Need $Needed!",
);
return;
}
}
# Check if we have Ticket to deal with
if ( !IsHashRefWithData( $Param{Ticket} ) ) {
$Self->{LogObject}->Log(
Priority => 'error',
Message => "MergeTicket.pm Ticket has no values!",
);
return;
}
# Check if we have a ConfigHash
if ( !IsHashRefWithData( $Param{Config} ) ) {
$Self->{LogObject}->Log(
Priority => 'error',
Message => "MergeTicket.pm Config has no values!",
);
return;
}
#find the ticket parent
my %ticketsParent = $Self->{LinkObject}->LinkKeyListWithData(
Object1 => 'Ticket',
Key1 => $Param{Ticket}->{TicketID},
Object2 => 'Ticket',
State => 'Valid',
Type => 'ParentChild', # (optional)
Direction => 'Source', # (optional) default Both (Source|Target|Both)
UserID => 1,
);
my $parentTicketId = 1;
foreach $key (keys %ticketsParent){
$parentTicketId = $key;
}
if($Param{Config}->{fields}){
#get the dynamic Field
my %parentTicketSearch = $Self->{TicketObject}->TicketGet(
TicketID => $parentTicketId,
DynamicFields => 1, # Optional, default 0. To include the dynamic field values for this ticket on the return structure.
UserID => 1,
Silent => 0, # Optional, default 0. To suppress the warning if the ticket does not exist.
);
my %childTicketSearch = $Self->{TicketObject}->TicketGet(
TicketID => $Param{Ticket}->{TicketID},
DynamicFields => 1, # Optional, default 0. To include the dynamic field values for this ticket on the return structure.
UserID => 1,
Silent => 0, # Optional, default 0. To suppress the warning if the ticket does not exist.
);
my @ticketDynamicFields = split(',', $Param{Config}->{fields});
foreach my $field (@ticketDynamiFields) {
if ($parentTicketSearch{"DynamicField_".$field}){
# get config for ProcessManagementActivityID dynamic field
my $fieldConfig = $Self->{DynamicFieldObject}->DynamicFieldGet(
Name => $field,
);
my $fieldSuccess = $Self->{BackendObject}->ValueSet(
DynamicFieldConfig => $fieldConfig,
ObjectID => $parentTicketId,
Value => $childTicketSearch{"DynamicField_".$field},
UserID => 1,
);
if (!$fieldSuccess){
#something wrong
$Self->{LogObject}->Log(
Priority => 'error',
Message => "MergeTicket.pm Cannot set DynamicField (".$field.") value to parent ticket :".$parentTicketId." , child ticket: ".$Param{Ticket}->{TicketID},
);
}else{
$Self->{LogObject}->Log(
Priority => 'info',
Message => "MergeTicket.pm DynamicField (".$field.") changed to: ".$childTicketSearch{"DynamicField_".$field}."\n child ticket :".$Param{Ticket}->{TicketID}.", parent ticket:".$parentTicketId,
);
}
}else{
$Self->{LogObject}->Log(
Priority => 'error',
Message => "MergeTicket.pm Cannot add DynamicField (".$field.") to parent ticket :".$parentTicketId." the child ticket: ".$Param{Ticket}->{TicketID}." doesn't have DynamicField: ".$field,
);
}
}
};
# merge the child within the parent
$Self->{TicketObject}->TicketMerge(
MainTicketID => $parentTicketId,
MergeTicketID => $Param{Ticket}->{TicketID},
UserID => 1,
);
$Self->{LogObject}->Log(
Priority => 'info',
Message => "MergeTicket.pm called with Merge Ticket: ".$Param{Ticket}->{TicketID} . " Main Ticket: ".$parentTicketId ,
);
return ;
}
1;