Repository navigation
Expand file tree
/
Copy pathTicketCreate.pm
More file actions
1739 lines (1461 loc) · 58.9 KB
/
Copy pathTicketCreate.pm
File metadata and controls
1739 lines (1461 loc) · 58.9 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# --
# 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::GenericInterface::Operation::Ticket::TicketCreate;
use strict;
use warnings;
use Kernel::System::VariableCheck qw(IsArrayRefWithData IsHashRefWithData IsString IsStringWithData);
use Kernel::System::LinkObject;
use parent qw(
Kernel::GenericInterface::Operation::Common
Kernel::GenericInterface::Operation::Ticket::Common
);
our $ObjectManagerDisabled = 1;
=head1 NAME
Kernel::GenericInterface::Operation::Ticket::TicketCreate - GenericInterface Ticket TicketCreate Operation backend
=head1 PUBLIC INTERFACE
=head2 new()
usually, you want to create an instance of this
by using Kernel::GenericInterface::Operation->new();
=cut
sub new {
my ( $Type, %Param ) = @_;
my $Self = {};
bless( $Self, $Type );
# check needed objects
for my $Needed (qw( DebuggerObject WebserviceID )) {
if ( !$Param{$Needed} ) {
return {
Success => 0,
ErrorMessage => "Got no $Needed!",
};
}
$Self->{$Needed} = $Param{$Needed};
}
$Self->{Config} = $Kernel::OM->Get('Kernel::Config')->Get('GenericInterface::Operation::TicketCreate');
$Self->{Operation} = $Param{Operation};
return $Self;
}
=head2 Run()
perform TicketCreate Operation. This will return the created ticket number.
my $Result = $OperationObject->Run(
Data => {
UserLogin => 'some agent login', # UserLogin or CustomerUserLogin or SessionID is
# required
CustomerUserLogin => 'some customer login',
SessionID => 123,
Password => 'some password', # if UserLogin or CustomerUserLogin is sent then
# Password is required
Ticket => {
Title => 'some ticket title',
QueueID => 123, # QueueID or Queue is required
Queue => 'some queue name',
LockID => 123, # optional
Lock => 'some lock name', # optional
TypeID => 123, # optional
Type => 'some type name', # optional
ServiceID => 123, # optional
Service => 'some service name', # optional
SLAID => 123, # optional
SLA => 'some SLA name', # optional
StateID => 123, # StateID or State is required
State => 'some state name',
PriorityID => 123, # PriorityID or Priority is required
Priority => 'some priority name',
OwnerID => 123, # optional
Owner => 'some user login', # optional
ResponsibleID => 123, # optional
Responsible => 'some user login', # optional
CustomerUser => 'some customer user login',
PendingTime { # optional
Year => 2011,
Month => 12
Day => 03,
Hour => 23,
Minute => 05,
},
# or
# PendingTime {
# Diff => 10080, # Pending time in minutes
#},
},
Article => {
CommunicationChannel => 'Email', # CommunicationChannel or CommunicationChannelID must be provided.
CommunicationChannelID => 1,
IsVisibleForCustomer => 1, # optional
SenderTypeID => 123, # optional
SenderType => 'some sender type name', # optional
AutoResponseType => 'some auto response type', # optional
From => 'some from string', # optional
Subject => 'some subject',
Body => 'some body',
ContentType => 'some content type', # ContentType or MimeType and Charset is required
MimeType => 'some mime type',
Charset => 'some charset',
HistoryType => 'some history type', # optional
HistoryComment => 'Some history comment', # optional
TimeUnit => 123, # optional
NoAgentNotify => 1, # optional
ForceNotificationToUserID => [1, 2, 3] # optional
ExcludeNotificationToUserID => [1, 2, 3] # optional
ExcludeMuteNotificationToUserID => [1, 2, 3] # optional
},
DynamicField => [ # optional
{
Name => 'some name',
Value => $Value, # value type depends on the dynamic field
},
# ...
],
# or
# DynamicField => {
# Name => 'some name',
# Value => $Value,
#},
Attachment => [
{
Content => 'content' # base64 encoded
ContentType => 'some content type'
Filename => 'some fine name'
},
# ...
],
#or
#Attachment => {
# Content => 'content'
# ContentType => 'some content type'
# Filename => 'some fine name'
#},
},
);
$Result = {
Success => 1, # 0 or 1
ErrorMessage => '', # in case of error
Data => { # result data payload after Operation
TicketID => 123, # Ticket ID number in OTRS (help desk system)
TicketNumber => 2324454323322 # Ticket Number in OTRS (Help desk system)
ArticleID => 43, # Article ID number in OTRS (help desk system)
Error => { # should not return errors
ErrorCode => 'Ticket.Create.ErrorCode'
ErrorMessage => 'Error Description'
},
# If IncludeTicketData is enabled
Ticket => [
{
TicketNumber => '20101027000001',
Title => 'some title',
TicketID => 123,
State => 'some state',
StateID => 123,
StateType => 'some state type',
Priority => 'some priority',
PriorityID => 123,
Lock => 'lock',
LockID => 123,
Queue => 'some queue',
QueueID => 123,
CustomerID => 'customer_id_123',
CustomerUserID => 'customer_user_id_123',
Owner => 'some_owner_login',
OwnerID => 123,
Type => 'some ticket type',
TypeID => 123,
SLA => 'some sla',
SLAID => 123,
Service => 'some service',
ServiceID => 123,
Responsible => 'some_responsible_login',
ResponsibleID => 123,
Age => 3456,
Created => '2010-10-27 20:15:00'
CreateBy => 123,
Changed => '2010-10-27 20:15:15',
ChangeBy => 123,
ArchiveFlag => 'y',
DynamicField => [
{
Name => 'some name',
Value => 'some value',
},
],
# (time stamps of expected escalations)
EscalationResponseTime (unix time stamp of response time escalation)
EscalationUpdateTime (unix time stamp of update time escalation)
EscalationSolutionTime (unix time stamp of solution time escalation)
# (general escalation info of nearest escalation type)
EscalationDestinationIn (escalation in e. g. 1h 4m)
EscalationDestinationTime (date of escalation in unix time, e. g. 72193292)
EscalationDestinationDate (date of escalation, e. g. "2009-02-14 18:00:00")
EscalationTimeWorkingTime (seconds of working/service time till escalation, e. g. "1800")
EscalationTime (seconds total till escalation of nearest escalation time type - response, update or solution time, e. g. "3600")
# (detailed escalation info about first response, update and solution time)
FirstResponseTimeEscalation (if true, ticket is escalated)
FirstResponseTimeNotification (if true, notify - x% of escalation has reached)
FirstResponseTimeDestinationTime (date of escalation in unix time, e. g. 72193292)
FirstResponseTimeDestinationDate (date of escalation, e. g. "2009-02-14 18:00:00")
FirstResponseTimeWorkingTime (seconds of working/service time till escalation, e. g. "1800")
FirstResponseTime (seconds total till escalation, e. g. "3600")
UpdateTimeEscalation (if true, ticket is escalated)
UpdateTimeNotification (if true, notify - x% of escalation has reached)
UpdateTimeDestinationTime (date of escalation in unix time, e. g. 72193292)
UpdateTimeDestinationDate (date of escalation, e. g. "2009-02-14 18:00:00")
UpdateTimeWorkingTime (seconds of working/service time till escalation, e. g. "1800")
UpdateTime (seconds total till escalation, e. g. "3600")
SolutionTimeEscalation (if true, ticket is escalated)
SolutionTimeNotification (if true, notify - x% of escalation has reached)
SolutionTimeDestinationTime (date of escalation in unix time, e. g. 72193292)
SolutionTimeDestinationDate (date of escalation, e. g. "2009-02-14 18:00:00")
SolutionTimeWorkingTime (seconds of working/service time till escalation, e. g. "1800")
SolutionTime (seconds total till escalation, e. g. "3600")
Article => [
{
ArticleID
From
To
Cc
Subject
Body
ReplyTo
MessageID
InReplyTo
References
SenderType
SenderTypeID
CommunicationChannelID
IsVisibleForCustomer
ContentType
Charset
MimeType
IncomingTime
DynamicField => [
{
Name => 'some name',
Value => 'some value',
},
],
Attachment => [
{
Content => "xxxx", # actual attachment contents, base64 enconded
ContentAlternative => "",
ContentID => "",
ContentType => "application/pdf",
Filename => "StdAttachment-Test1.pdf",
Filesize => "4.6 KBytes",
FilesizeRaw => 4722,
},
],
},
],
},
],
},
};
=cut
sub Run {
my ( $Self, %Param ) = @_;
my $Result = $Self->Init(
WebserviceID => $Self->{WebserviceID},
);
if ( !$Result->{Success} ) {
$Self->ReturnError(
ErrorCode => 'Webservice.InvalidConfiguration',
ErrorMessage => $Result->{ErrorMessage},
);
}
# check needed stuff
if (
!$Param{Data}->{UserLogin}
&& !$Param{Data}->{CustomerUserLogin}
&& !$Param{Data}->{SessionID}
)
{
return $Self->ReturnError(
ErrorCode => 'TicketCreate.MissingParameter',
ErrorMessage => "TicketCreate: UserLogin, CustomerUserLogin or SessionID is required!",
);
}
if ( $Param{Data}->{UserLogin} || $Param{Data}->{CustomerUserLogin} ) {
if ( !$Param{Data}->{Password} )
{
return $Self->ReturnError(
ErrorCode => 'TicketCreate.MissingParameter',
ErrorMessage => "TicketCreate: Password or SessionID is required!",
);
}
}
# authenticate user
my ( $UserID, $UserType ) = $Self->Auth(
%Param,
);
if ( !$UserID ) {
return $Self->ReturnError(
ErrorCode => 'TicketCreate.AuthFail',
ErrorMessage => "TicketCreate: User could not be authenticated!",
);
}
my $PermissionUserID = $UserID;
if ( $UserType eq 'Customer' ) {
$UserID = $Kernel::OM->Get('Kernel::Config')->Get('CustomerPanelUserID');
}
# check needed hashes
for my $Needed (qw(Ticket Article)) {
if ( !IsHashRefWithData( $Param{Data}->{$Needed} ) ) {
return $Self->ReturnError(
ErrorCode => 'TicketCreate.MissingParameter',
ErrorMessage => "TicketCreate: $Needed parameter is missing or not valid!",
);
}
}
# check optional array/hashes
for my $Optional (qw(DynamicField Attachment)) {
if (
defined $Param{Data}->{$Optional}
&& !IsHashRefWithData( $Param{Data}->{$Optional} )
&& !IsArrayRefWithData( $Param{Data}->{$Optional} )
)
{
return $Self->ReturnError(
ErrorCode => 'TicketCreate.MissingParameter',
ErrorMessage => "TicketCreate: $Optional parameter is missing or not valid!",
);
}
}
# isolate ticket parameter
my $Ticket = $Param{Data}->{Ticket};
# remove leading and trailing spaces
for my $Attribute ( sort keys %{$Ticket} ) {
if ( ref $Attribute ne 'HASH' && ref $Attribute ne 'ARRAY' ) {
#remove leading spaces
$Ticket->{$Attribute} =~ s{\A\s+}{};
#remove trailing spaces
$Ticket->{$Attribute} =~ s{\s+\z}{};
}
}
if ( IsHashRefWithData( $Ticket->{PendingTime} ) ) {
for my $Attribute ( sort keys %{ $Ticket->{PendingTime} } ) {
if ( ref $Attribute ne 'HASH' && ref $Attribute ne 'ARRAY' ) {
#remove leading spaces
$Ticket->{PendingTime}->{$Attribute} =~ s{\A\s+}{};
#remove trailing spaces
$Ticket->{PendingTime}->{$Attribute} =~ s{\s+\z}{};
}
}
}
# check Ticket attribute values
my $TicketCheck = $Self->_CheckTicket( Ticket => $Ticket );
if ( !$TicketCheck->{Success} ) {
return $Self->ReturnError( %{$TicketCheck} );
}
# check create permissions
my $Permission = $Self->CheckCreatePermissions(
Ticket => $Ticket,
UserID => $PermissionUserID,
UserType => $UserType,
);
if ( !$Permission ) {
return $Self->ReturnError(
ErrorCode => 'TicketCreate.AccessDenied',
ErrorMessage => "TicketCreate: Can not create tickets in given Queue or QueueID!",
);
}
# isolate Article parameter
my $Article = $Param{Data}->{Article};
$Article->{UserType} = $UserType;
# remove leading and trailing spaces
for my $Attribute ( sort keys %{$Article} ) {
if ( ref $Attribute ne 'HASH' && ref $Attribute ne 'ARRAY' ) {
#remove leading spaces
$Article->{$Attribute} =~ s{\A\s+}{};
#remove trailing spaces
$Article->{$Attribute} =~ s{\s+\z}{};
}
}
if ( IsHashRefWithData( $Article->{OrigHeader} ) ) {
for my $Attribute ( sort keys %{ $Article->{OrigHeader} } ) {
if ( ref $Attribute ne 'HASH' && ref $Attribute ne 'ARRAY' ) {
#remove leading spaces
$Article->{OrigHeader}->{$Attribute} =~ s{\A\s+}{};
#remove trailing spaces
$Article->{OrigHeader}->{$Attribute} =~ s{\s+\z}{};
}
}
}
# Check attributes that can be set by sysconfig.
if ( !$Article->{AutoResponseType} ) {
$Article->{AutoResponseType} = $Self->{Config}->{AutoResponseType} || '';
}
# TODO: GenericInterface::Operation::TicketCreate###CommunicationChannel
if ( !$Article->{CommunicationChannelID} && !$Article->{CommunicationChannel} ) {
$Article->{CommunicationChannel} = 'Internal';
}
if ( !defined $Article->{IsVisibleForCustomer} ) {
$Article->{IsVisibleForCustomer} = $Self->{Config}->{IsVisibleForCustomer} // 1;
}
if ( !$Article->{SenderTypeID} && !$Article->{SenderType} ) {
$Article->{SenderType} = $UserType eq 'User' ? 'agent' : 'customer';
}
if ( !$Article->{HistoryType} ) {
$Article->{HistoryType} = $Self->{Config}->{HistoryType} || '';
}
if ( !$Article->{HistoryComment} ) {
$Article->{HistoryComment} = $Self->{Config}->{HistoryComment} || '';
}
# check Article attribute values
my $ArticleCheck = $Self->_CheckArticle( Article => $Article );
if ( !$ArticleCheck->{Success} ) {
if ( !$ArticleCheck->{ErrorCode} ) {
return {
Success => 0,
%{$ArticleCheck},
};
}
return $Self->ReturnError( %{$ArticleCheck} );
}
my $DynamicField;
my @DynamicFieldList;
if ( defined $Param{Data}->{DynamicField} ) {
# isolate DynamicField parameter
$DynamicField = $Param{Data}->{DynamicField};
# homogenate input to array
if ( ref $DynamicField eq 'HASH' ) {
push @DynamicFieldList, $DynamicField;
}
else {
@DynamicFieldList = @{$DynamicField};
}
# check DynamicField internal structure
for my $DynamicFieldItem (@DynamicFieldList) {
if ( !IsHashRefWithData($DynamicFieldItem) ) {
return {
ErrorCode => 'TicketCreate.InvalidParameter',
ErrorMessage =>
"TicketCreate: Ticket->DynamicField parameter is invalid!",
};
}
# remove leading and trailing spaces
for my $Attribute ( sort keys %{$DynamicFieldItem} ) {
if ( ref $Attribute ne 'HASH' && ref $Attribute ne 'ARRAY' ) {
#remove leading spaces
$DynamicFieldItem->{$Attribute} =~ s{\A\s+}{};
#remove trailing spaces
$DynamicFieldItem->{$Attribute} =~ s{\s+\z}{};
}
}
# check DynamicField attribute values
my $DynamicFieldCheck = $Self->_CheckDynamicField( DynamicField => $DynamicFieldItem );
if ( !$DynamicFieldCheck->{Success} ) {
return $Self->ReturnError( %{$DynamicFieldCheck} );
}
}
}
my $Attachment;
my @AttachmentList;
if ( defined $Param{Data}->{Attachment} ) {
# isolate Attachment parameter
$Attachment = $Param{Data}->{Attachment};
# homogenate input to array
if ( ref $Attachment eq 'HASH' ) {
push @AttachmentList, $Attachment;
}
else {
@AttachmentList = @{$Attachment};
}
# check Attachment internal structure
for my $AttachmentItem (@AttachmentList) {
if ( !IsHashRefWithData($AttachmentItem) ) {
return {
ErrorCode => 'TicketCreate.InvalidParameter',
ErrorMessage =>
"TicketCreate: Ticket->Attachment parameter is invalid!",
};
}
# remove leading and trailing spaces
for my $Attribute ( sort keys %{$AttachmentItem} ) {
if ( ref $Attribute ne 'HASH' && ref $Attribute ne 'ARRAY' ) {
#remove leading spaces
$AttachmentItem->{$Attribute} =~ s{\A\s+}{};
#remove trailing spaces
$AttachmentItem->{$Attribute} =~ s{\s+\z}{};
}
}
# check Attachment attribute values
my $AttachmentCheck = $Self->_CheckAttachment( Attachment => $AttachmentItem );
if ( !$AttachmentCheck->{Success} ) {
return $Self->ReturnError( %{$AttachmentCheck} );
}
}
}
return $Self->_TicketCreate(
Ticket => $Ticket,
Article => $Article,
DynamicFieldList => \@DynamicFieldList,
AttachmentList => \@AttachmentList,
UserID => $UserID,
);
}
=begin Internal:
=head2 _CheckTicket()
checks if the given ticket parameters are valid.
my $TicketCheck = $OperationObject->_CheckTicket(
Ticket => $Ticket, # all ticket parameters
);
returns:
$TicketCheck = {
Success => 1, # if everything is OK
}
$TicketCheck = {
ErrorCode => 'Function.Error', # if error
ErrorMessage => 'Error description',
}
=cut
sub _CheckTicket {
my ( $Self, %Param ) = @_;
my $Ticket = $Param{Ticket};
# check ticket internally
for my $Needed (qw(Title CustomerUser)) {
if ( !$Ticket->{$Needed} ) {
return {
ErrorCode => 'TicketCreate.MissingParameter',
ErrorMessage => "TicketCreate: Ticket->$Needed parameter is missing!",
};
}
}
# check Ticket->CustomerUser
if ( !$Self->ValidateCustomer( %{$Ticket} ) ) {
return {
ErrorCode => 'TicketCreate.InvalidParameter',
ErrorMessage =>
"TicketCreate: Ticket->CustomerUser parameter is invalid!",
};
}
# check Ticket->Queue
if ( !$Ticket->{QueueID} && !$Ticket->{Queue} ) {
return {
ErrorCode => 'TicketCreate.MissingParameter',
ErrorMessage => "TicketCreate: Ticket->QueueID or Ticket->Queue parameter is required!",
};
}
if ( !$Self->ValidateQueue( %{$Ticket} ) ) {
return {
ErrorCode => 'TicketCreate.InvalidParameter',
ErrorMessage => "TicketCreate: Ticket->QueueID or Ticket->Queue parameter is invalid!",
};
}
# check Ticket->Lock
if ( $Ticket->{LockID} || $Ticket->{Lock} ) {
if ( !$Self->ValidateLock( %{$Ticket} ) ) {
return {
ErrorCode => 'TicketCreate.InvalidParameter',
ErrorMessage => "TicketCreate: Ticket->LockID or Ticket->Lock parameter is"
. " invalid!",
};
}
}
# check Ticket->Type
# Ticket type could be required or not depending on sysconfig option
if (
!$Ticket->{TypeID}
&& !$Ticket->{Type}
&& $Kernel::OM->Get('Kernel::Config')->Get('Ticket::Type')
)
{
return {
ErrorCode => 'TicketCreate.MissingParameter',
ErrorMessage => "TicketCreate: Ticket->TypeID or Ticket->Type parameter is required"
. " by sysconfig option!",
};
}
if ( $Ticket->{TypeID} || $Ticket->{Type} ) {
if ( !$Self->ValidateType( %{$Ticket} ) ) {
return {
ErrorCode => 'TicketCreate.InvalidParameter',
ErrorMessage =>
"TicketCreate: Ticket->TypeID or Ticket->Type parameter is invalid!",
};
}
}
# check Ticket->Service
if ( $Ticket->{ServiceID} || $Ticket->{Service} ) {
if ( !$Self->ValidateService( %{$Ticket} ) ) {
return {
ErrorCode => 'TicketCreate.InvalidParameter',
ErrorMessage =>
"TicketCreate: Ticket->ServiceID or Ticket->Service parameter is invalid!",
};
}
}
# check Ticket->SLA
if ( $Ticket->{SLAID} || $Ticket->{SLA} ) {
if ( !$Self->ValidateSLA( %{$Ticket} ) ) {
return {
ErrorCode => 'TicketCreate.InvalidParameter',
ErrorMessage =>
"TicketCreate: Ticket->SLAID or Ticket->SLA parameter is invalid!",
};
}
}
# check Ticket->State
if ( !$Ticket->{StateID} && !$Ticket->{State} ) {
return {
ErrorCode => 'TicketCreate.MissingParameter',
ErrorMessage => "TicketCreate: Ticket->StateID or Ticket->State parameter is required!",
};
}
if ( !$Self->ValidateState( %{$Ticket} ) ) {
return {
ErrorCode => 'TicketCreate.InvalidParameter',
ErrorMessage => "TicketCreate: Ticket->StateID or Ticket->State parameter is invalid!",
};
}
# check Ticket->Priority
if ( !$Ticket->{PriorityID} && !$Ticket->{Priority} ) {
return {
ErrorCode => 'TicketCreate.MissingParameter',
ErrorMessage => "TicketCreate: Ticket->PriorityID or Ticket->Priority parameter is"
. " required!",
};
}
if ( !$Self->ValidatePriority( %{$Ticket} ) ) {
return {
ErrorCode => 'TicketCreate.InvalidParameter',
ErrorMessage => "TicketCreate: Ticket->PriorityID or Ticket->Priority parameter is"
. " invalid!",
};
}
# check Ticket->Owner
if ( $Ticket->{OwnerID} || $Ticket->{Owner} ) {
if ( !$Self->ValidateOwner( %{$Ticket} ) ) {
return {
ErrorCode => 'TicketCreate.InvalidParameter',
ErrorMessage =>
"TicketCreate: Ticket->OwnerID or Ticket->Owner parameter is invalid!",
};
}
}
# check Ticket->Responsible
if ( $Ticket->{ResponsibleID} || $Ticket->{Responsible} ) {
if ( !$Self->ValidateResponsible( %{$Ticket} ) ) {
return {
ErrorCode => 'TicketCreate.InvalidParameter',
ErrorMessage => "TicketCreate: Ticket->ResponsibleID or Ticket->Responsible"
. " parameter is invalid!",
};
}
}
# check Ticket->PendingTime
if ( $Ticket->{PendingTime} ) {
if ( !$Self->ValidatePendingTime( %{$Ticket} ) ) {
return {
ErrorCode => 'TicketCreate.InvalidParameter',
ErrorMessage => "TicketCreate: Ticket->PendingTime parameter is invalid!",
};
}
}
# if everything is OK then return Success
return {
Success => 1,
};
}
=head2 _CheckArticle()
checks if the given article parameter is valid.
my $ArticleCheck = $OperationObject->_CheckArticle(
Article => $Article, # all article parameters
);
returns:
$ArticleCheck = {
Success => 1, # if everething is OK
}
$ArticleCheck = {
ErrorCode => 'Function.Error', # if error
ErrorMessage => 'Error description',
}
=cut
sub _CheckArticle {
my ( $Self, %Param ) = @_;
my $Article = $Param{Article};
# check ticket internally
for my $Needed (qw(Subject Body AutoResponseType)) {
if ( !$Article->{$Needed} ) {
return {
ErrorCode => 'TicketCreate.MissingParameter',
ErrorMessage => "TicketCreate: Article->$Needed parameter is missing!",
};
}
}
# check Article->AutoResponseType
if ( !$Article->{AutoResponseType} ) {
# return internal server error
return {
ErrorMessage => "TicketCreate: Article->AutoResponseType parameter is required!"
};
}
if ( !$Self->ValidateAutoResponseType( %{$Article} ) ) {
return {
ErrorCode => 'TicketCreate.InvalidParameter',
ErrorMessage => "TicketCreate: Article->AutoResponseType parameter is invalid!",
};
}
# check Article->CommunicationChannel
if ( !$Article->{CommunicationChannel} && !$Article->{CommunicationChannelID} ) {
# return internal server error
return {
ErrorMessage => "TicketCreate: Article->CommunicationChannelID or Article->CommunicationChannel parameter"
. " is required and Sysconfig CommunicationChannelID setting could not be read!"
};
}
if ( !$Self->ValidateArticleCommunicationChannel( %{$Article} ) ) {
return {
ErrorCode => 'TicketCreate.InvalidParameter',
ErrorMessage => "TicketCreate: Article->CommunicationChannel or Article->CommunicationChannelID parameter"
. " is invalid or not supported!",
};
}
# check Article->SenderType
if ( !$Article->{SenderTypeID} && !$Article->{SenderType} ) {
# return internal server error
return {
ErrorMessage => "TicketCreate: Article->SenderTypeID or Article->SenderType parameter"
. " is required and Sysconfig SenderTypeID setting could not be read!"
};
}
if ( !$Self->ValidateSenderType( %{$Article} ) ) {
return {
ErrorCode => 'TicketCreate.InvalidParameter',
ErrorMessage => "TicketCreate: Article->SenderTypeID or Ticket->SenderType parameter"
. " is invalid!",
};
}
# check Article->From
if ( $Article->{From} ) {
if ( !$Self->ValidateFrom( %{$Article} ) ) {
return {
ErrorCode => 'TicketCreate.InvalidParameter',
ErrorMessage => "TicketCreate: Article->From parameter is invalid!",
};
}
}
# check Article->ContentType vs Article->MimeType and Article->Charset
if ( !$Article->{ContentType} && !$Article->{MimeType} && !$Article->{Charset} ) {
return {
ErrorCode => 'TicketCreate.MissingParameter',
ErrorMessage => "TicketCreate: Article->ContentType or Ticket->MimeType and"
. " Article->Charset parameters are required!",
};
}
if ( $Article->{MimeType} && !$Article->{Charset} ) {
return {
ErrorCode => 'TicketCreate.MissingParameter',
ErrorMessage => "TicketCreate: Article->Charset is required!",
};
}
if ( $Article->{Charset} && !$Article->{MimeType} ) {
return {
ErrorCode => 'TicketCreate.MissingParameter',
ErrorMessage => "TicketCreate: Article->MimeType is required!",
};
}
# check Article->MimeType
if ( $Article->{MimeType} ) {
$Article->{MimeType} = lc $Article->{MimeType};
if ( !$Self->ValidateMimeType( %{$Article} ) ) {
return {
ErrorCode => 'TicketCreate.InvalidParameter',
ErrorMessage => "TicketCreate: Article->MimeType is invalid!",
};
}
}
# check Article->MimeType
if ( $Article->{Charset} ) {
$Article->{Charset} = lc $Article->{Charset};
if ( !$Self->ValidateCharset( %{$Article} ) ) {
return {
ErrorCode => 'TicketCreate.InvalidParameter',
ErrorMessage => "TicketCreate: Article->Charset is invalid!",
};
}
}
# check Article->ContentType
if ( $Article->{ContentType} ) {
$Article->{ContentType} = lc $Article->{ContentType};
# check Charset part
my $Charset = '';
if ( $Article->{ContentType} =~ /charset=/i ) {
$Charset = $Article->{ContentType};
$Charset =~ s/.+?charset=("|'|)(\w+)/$2/gi;
$Charset =~ s/"|'//g;
$Charset =~ s/(.+?);.*/$1/g;
}
if ( !$Self->ValidateCharset( Charset => $Charset ) ) {
return {
ErrorCode => 'TicketCreate.InvalidParameter',
ErrorMessage => "TicketCreate: Article->ContentType is invalid!",
};
}
# check MimeType part
my $MimeType = '';
if ( $Article->{ContentType} =~ /^(\w+\/\w+)/i ) {
$MimeType = $1;
$MimeType =~ s/"|'//g;
}
if ( !$Self->ValidateMimeType( MimeType => $MimeType ) ) {
return {
ErrorCode => 'TicketCreate.InvalidParameter',
ErrorMessage => "TicketCreate: Article->ContentType is invalid!",
};
}
}
# check Article->HistoryType
if ( !$Article->{HistoryType} ) {
# return internal server error
return {
ErrorMessage => "TicketCreate: Article-> HistoryType is required and Sysconfig"
. " HistoryType setting could not be read!"
};
}
if ( !$Self->ValidateHistoryType( %{$Article} ) ) {
return {
ErrorCode => 'TicketCreate.InvalidParameter',
ErrorMessage => "TicketCreate: Article->HistoryType parameter is invalid!",
};
}
# check Article->HistoryComment
if ( !$Article->{HistoryComment} ) {
# return internal server error
return {
ErrorMessage => "TicketCreate: Article->HistoryComment is required and Sysconfig"
. " HistoryComment setting could not be read!"
};
}
# get config object
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
# check Article->TimeUnit
# TimeUnit could be required or not depending on sysconfig option
if (
( !defined $Article->{TimeUnit} || !IsStringWithData( $Article->{TimeUnit} ) )
&& $ConfigObject->{'Ticket::Frontend::AccountTime'}
&& $ConfigObject->{'Ticket::Frontend::NeedAccountedTime'}
)
{
return {
ErrorCode => 'TicketCreate.MissingParameter',