init III
This commit is contained in:
193
Perl OTRS/Kernel/System/ProcessManagement/Activity.pm
Normal file
193
Perl OTRS/Kernel/System/ProcessManagement/Activity.pm
Normal file
@@ -0,0 +1,193 @@
|
||||
# --
|
||||
# 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::ProcessManagement::Activity;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::Activity - Activities lib
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
All Process Management Activity functions.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $ActivityObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::Activity');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 ActivityGet()
|
||||
|
||||
Get Activity info
|
||||
Returned activity dialogs are limited to given interface
|
||||
|
||||
my $Activity = $ActivityObject->ActivityGet(
|
||||
ActivityEntityID => 'A1',
|
||||
Interface => ['AgentInterface'], # ['AgentInterface'] or ['CustomerInterface'] or ['AgentInterface', 'CustomerInterface'] or 'all'
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$Activity = {
|
||||
'Name' => 'Activity 3'
|
||||
'CreateTime' => '08-02-2012 13:37:00',
|
||||
'ChangeBy' => '2',
|
||||
'ChangeTime' => '09-02-2012 13:37:00',
|
||||
'CreateBy' => '3',
|
||||
'ActivityDialog' => {
|
||||
'1' => 'AD5',
|
||||
'3' => 'AD7',
|
||||
'2' => 'AD6',
|
||||
},
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub ActivityGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(ActivityEntityID Interface)) {
|
||||
if ( !defined $Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get config object
|
||||
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
|
||||
|
||||
my $Activity = $ConfigObject->Get('Process::Activity');
|
||||
|
||||
if ( !IsHashRefWithData($Activity) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need Activity config!'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
my $ActivityEntity = $Activity->{ $Param{ActivityEntityID} };
|
||||
|
||||
if ( !IsHashRefWithData($ActivityEntity) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "No data for Activity '$Param{ActivityEntityID}' found!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# limit activity dialogs by interface
|
||||
return $ActivityEntity if ref $Param{Interface} ne 'ARRAY' && $Param{Interface} eq 'all';
|
||||
if ( ref $Param{Interface} ne 'ARRAY' && $Param{Interface} ne 'all' ) {
|
||||
$Param{Interface} = [ $Param{Interface} ];
|
||||
}
|
||||
|
||||
# get activity dialogs
|
||||
my $ActivityDialogs = $ConfigObject->Get('Process::ActivityDialog');
|
||||
|
||||
if ( IsHashRefWithData( $ActivityEntity->{ActivityDialog} ) ) {
|
||||
|
||||
# filter activity dialogs
|
||||
ACTIVITYDIALOG:
|
||||
for my $ActivityDialogID ( sort keys %{ $ActivityEntity->{ActivityDialog} } ) {
|
||||
my $ActivityDialog = $ActivityEntity->{ActivityDialog}->{$ActivityDialogID};
|
||||
if ( IsHashRefWithData($ActivityDialog) ) {
|
||||
$ActivityDialog = $ActivityDialog->{ActivityDialogEntityID};
|
||||
}
|
||||
for my $Interface ( @{ $Param{Interface} } ) {
|
||||
|
||||
# keep activity dialog if interface is included in activity dialog configuration
|
||||
if (
|
||||
grep { $_ eq $Interface } @{ $ActivityDialogs->{$ActivityDialog}->{Interface} }
|
||||
)
|
||||
{
|
||||
next ACTIVITYDIALOG;
|
||||
}
|
||||
}
|
||||
|
||||
# remove activity dialog if no match could be found
|
||||
delete $ActivityEntity->{ActivityDialog}->{$ActivityDialogID};
|
||||
}
|
||||
}
|
||||
|
||||
return $ActivityEntity;
|
||||
}
|
||||
|
||||
=head2 ActivityList()
|
||||
|
||||
Get a list of all Activities
|
||||
|
||||
my $Activities = $ActivityObject->ActivityList();
|
||||
|
||||
Returns:
|
||||
|
||||
$ActivityList = {
|
||||
'A1' => 'Activity 1',
|
||||
'A2' => 'Activity 2',
|
||||
'A3' => '',
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub ActivityList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $Activities = $Kernel::OM->Get('Kernel::Config')->Get('Process::Activity');
|
||||
|
||||
if ( !IsHashRefWithData($Activities) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need Activity config!'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
my %ActivityList = map { $_ => $Activities->{$_}->{Name} || '' } keys %{$Activities};
|
||||
|
||||
return \%ActivityList;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
271
Perl OTRS/Kernel/System/ProcessManagement/ActivityDialog.pm
Normal file
271
Perl OTRS/Kernel/System/ProcessManagement/ActivityDialog.pm
Normal file
@@ -0,0 +1,271 @@
|
||||
# --
|
||||
# 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::ProcessManagement::ActivityDialog;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::ActivityDialog - activity dialog lib
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
All Process Management Activity Dialog functions.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $ActivityDialogObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::ActivityDialog');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 ActivityDialogGet()
|
||||
|
||||
Get activity dialog info
|
||||
|
||||
my $ActivityDialog = $ActivityDialogObject->ActivityDialogGet(
|
||||
ActivityDialogEntityID => 'AD1',
|
||||
Interface => ['AgentInterface'], # ['AgentInterface'] or ['CustomerInterface'] or ['AgentInterface', 'CustomerInterface'] or 'all'
|
||||
Silent => 1, # 1 or 0, default 0, if set to 1, will not log errors about not matching interfaces
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$ActivityDialog = {
|
||||
Name => 'UnitTestActivity',
|
||||
Interface => 'CustomerInterface', # 'AgentInterface', 'CustomerInterface', ['AgentInterface'] or ['CustomerInterface'] or ['AgentInterface', 'CustomerInterface']
|
||||
DescriptionShort => 'AD1 Process Short',
|
||||
DescriptionLong => 'AD1 Process Long description',
|
||||
CreateTime => '07-02-2012 13:37:00',
|
||||
CreateBy => '2',
|
||||
ChangeTime => '08-02-2012 13:37:00',
|
||||
ChangeBy => '3',
|
||||
Fields => {
|
||||
DynamicField_Make => {
|
||||
Display => 2,
|
||||
DescriptionLong => 'Make Long',
|
||||
DescriptionShort => 'Make Short',
|
||||
},
|
||||
DynamicField_VWModel => {
|
||||
Display => 2,
|
||||
DescriptionLong => 'VWModel Long',
|
||||
DescriptionShort => 'VWModel Short',
|
||||
},
|
||||
DynamicField_PeugeotModel => {
|
||||
Display => 0,
|
||||
DescriptionLong => 'PeugeotModel Long',
|
||||
DescriptionShort => 'PeugeotModel Short',
|
||||
},
|
||||
StateID => {
|
||||
Display => 1,
|
||||
DescriptionLong => 'StateID Long',
|
||||
DescriptionShort => 'StateID Short',
|
||||
},
|
||||
},
|
||||
FieldOrder => [
|
||||
'StateID',
|
||||
'DynamicField_Make',
|
||||
'DynamicField_VWModelModel',
|
||||
'DynamicField_PeugeotModel'
|
||||
],
|
||||
SubmitAdviceText => 'NOTE: If you submit the form ...',
|
||||
SubmitButtonText => 'Make an inquiry',
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub ActivityDialogGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(ActivityDialogEntityID Interface)) {
|
||||
if ( !defined $Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $Param{Interface} ne 'all' && ref $Param{Interface} ne 'ARRAY' ) {
|
||||
$Param{Interface} = [ $Param{Interface} ];
|
||||
}
|
||||
|
||||
my $ActivityDialog = $Kernel::OM->Get('Kernel::Config')->Get('Process::ActivityDialog');
|
||||
|
||||
if ( !IsHashRefWithData($ActivityDialog) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need ActivityDialog config!'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !IsHashRefWithData( $ActivityDialog->{ $Param{ActivityDialogEntityID} } ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "No Data for ActivityDialog '$Param{ActivityDialogEntityID}' found!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
$Param{Interface} ne 'all'
|
||||
&& !IsArrayRefWithData(
|
||||
$ActivityDialog->{ $Param{ActivityDialogEntityID} }->{Interface}
|
||||
)
|
||||
)
|
||||
{
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "No Interface for ActivityDialog '$Param{ActivityDialogEntityID}' found!"
|
||||
);
|
||||
}
|
||||
|
||||
if ( $Param{Interface} ne 'all' ) {
|
||||
my $Success;
|
||||
INTERFACE:
|
||||
for my $CurrentInterface ( @{ $Param{Interface} } ) {
|
||||
if (
|
||||
grep { $CurrentInterface eq $_ }
|
||||
@{ $ActivityDialog->{ $Param{ActivityDialogEntityID} }->{Interface} }
|
||||
)
|
||||
{
|
||||
$Success = 1;
|
||||
last INTERFACE;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !$Success ) {
|
||||
if ( !$Param{Silent} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message =>
|
||||
"Not permitted Interface(s) '"
|
||||
. join( '\', \'', @{ $Param{Interface} } )
|
||||
. "' for ActivityDialog '$Param{ActivityDialogEntityID}'!"
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return $ActivityDialog->{ $Param{ActivityDialogEntityID} };
|
||||
}
|
||||
|
||||
=head2 ActivityDialogCompletedCheck()
|
||||
|
||||
Checks if an activity dialog is completed
|
||||
|
||||
my $Completed = $ActivityDialogObject->ActivityDialogCompletedCheck(
|
||||
ActivityDialogEntityID => 'AD1',
|
||||
Data => {
|
||||
Queue => 'Raw',
|
||||
DynamicField1 => 'Value',
|
||||
Subject => 'Testsubject',
|
||||
# ...
|
||||
},
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$Completed = 1; # 0
|
||||
|
||||
=cut
|
||||
|
||||
sub ActivityDialogCompletedCheck {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(ActivityDialogEntityID Data)) {
|
||||
if ( !defined $Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !IsHashRefWithData( $Param{Data} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Data has no values!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
my $ActivityDialog = $Self->ActivityDialogGet(
|
||||
ActivityDialogEntityID => $Param{ActivityDialogEntityID},
|
||||
Interface => 'all',
|
||||
);
|
||||
if ( !$ActivityDialog ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Can't get ActivtyDialog '$Param{ActivityDialogEntityID}'!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !$ActivityDialog->{Fields} || ref $ActivityDialog->{Fields} ne 'HASH' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Can't get fields for ActivtyDialog '$Param{ActivityDialogEntityID}'!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# loop over the fields of the config activity dialog to check if the required fields are filled
|
||||
FIELDLOOP:
|
||||
for my $Field ( sort keys %{ $ActivityDialog->{Fields} } ) {
|
||||
|
||||
# Checks if Field was invisible
|
||||
next FIELDLOOP if ( !$ActivityDialog->{Fields}->{$Field}->{Display} );
|
||||
|
||||
# Checks if Field was visible but not required
|
||||
next FIELDLOOP if ( $ActivityDialog->{Fields}->{$Field}->{Display} == 1 );
|
||||
|
||||
# checks if $Data->{Field} is defined and not an empty string
|
||||
return if ( !IsStringWithData( $Param{Data}->{$Field} ) );
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
777
Perl OTRS/Kernel/System/ProcessManagement/DB/Activity.pm
Normal file
777
Perl OTRS/Kernel/System/ProcessManagement/DB/Activity.pm
Normal file
@@ -0,0 +1,777 @@
|
||||
# --
|
||||
# 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::ProcessManagement::DB::Activity;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::Cache',
|
||||
'Kernel::System::DB',
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::ProcessManagement::DB::ActivityDialog',
|
||||
'Kernel::System::YAML',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::DB::Activity
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Process Management DB Activity backend
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $ActivityObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::Activity');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
# get the cache TTL (in seconds)
|
||||
$Self->{CacheTTL} = int( $Kernel::OM->Get('Kernel::Config')->Get('Process::CacheTTL') || 3600 );
|
||||
|
||||
# set lower if database is case sensitive
|
||||
$Self->{Lower} = '';
|
||||
if ( $Kernel::OM->Get('Kernel::System::DB')->GetDatabaseFunction('CaseSensitive') ) {
|
||||
$Self->{Lower} = 'LOWER';
|
||||
}
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 ActivityAdd()
|
||||
|
||||
add new Activity
|
||||
|
||||
returns the id of the created activity if success or undef otherwise
|
||||
|
||||
my $ID = $ActivityObject->ActivityAdd(
|
||||
EntityID => 'A1' # mandatory, exportable unique identifier
|
||||
Name => 'NameOfActivity', # mandatory
|
||||
Config => $ConfigHashRef, # mandatory, activity configuration to be stored in YAML
|
||||
# format
|
||||
UserID => 123, # mandatory
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$ID = 567;
|
||||
|
||||
=cut
|
||||
|
||||
sub ActivityAdd {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Key (qw(EntityID Name Config UserID)) {
|
||||
if ( !$Param{$Key} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Key!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get database object
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# check if EntityID already exists
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => "
|
||||
SELECT id
|
||||
FROM pm_activity
|
||||
WHERE $Self->{Lower}(entity_id) = $Self->{Lower}(?)",
|
||||
Bind => [ \$Param{EntityID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
|
||||
my $EntityExists;
|
||||
while ( my @Data = $DBObject->FetchrowArray() ) {
|
||||
$EntityExists = 1;
|
||||
}
|
||||
|
||||
if ($EntityExists) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "The EntityID:$Param{EntityID} already exists for an activity!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# check config valid format
|
||||
if ( ref $Param{Config} ne 'HASH' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Config needs to be a valid Hash reference!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# dump config as string
|
||||
my $Config = $Kernel::OM->Get('Kernel::System::YAML')->Dump( Data => $Param{Config} );
|
||||
|
||||
# Make sure the resulting string has the UTF-8 flag. YAML only sets it if
|
||||
# part of the data already had it.
|
||||
utf8::upgrade($Config);
|
||||
|
||||
# sql
|
||||
return if !$DBObject->Do(
|
||||
SQL => '
|
||||
INSERT INTO pm_activity (entity_id, name, config, create_time, create_by, change_time,
|
||||
change_by)
|
||||
VALUES (?, ?, ?, current_timestamp, ?, current_timestamp, ?)',
|
||||
Bind => [
|
||||
\$Param{EntityID}, \$Param{Name}, \$Config, \$Param{UserID}, \$Param{UserID},
|
||||
],
|
||||
);
|
||||
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => 'SELECT id FROM pm_activity WHERE entity_id = ?',
|
||||
Bind => [ \$Param{EntityID} ],
|
||||
);
|
||||
|
||||
my $ID;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
$ID = $Row[0];
|
||||
}
|
||||
|
||||
# delete cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
|
||||
Type => 'ProcessManagement_Activity',
|
||||
);
|
||||
|
||||
return if !$ID;
|
||||
|
||||
return $ID;
|
||||
}
|
||||
|
||||
=head2 ActivityDelete()
|
||||
|
||||
delete an Activity
|
||||
|
||||
returns 1 if success or undef otherwise
|
||||
|
||||
my $Success = $ActivityObject->ActivityDelete(
|
||||
ID => 123,
|
||||
UserID => 123,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ActivityDelete {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Key (qw(ID UserID)) {
|
||||
if ( !$Param{$Key} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Key!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check if exists
|
||||
my $Activity = $Self->ActivityGet(
|
||||
ID => $Param{ID},
|
||||
UserID => 1,
|
||||
);
|
||||
return if !IsHashRefWithData($Activity);
|
||||
|
||||
# delete activity
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => 'DELETE FROM pm_activity WHERE id = ?',
|
||||
Bind => [ \$Param{ID} ],
|
||||
);
|
||||
|
||||
# delete cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
|
||||
Type => 'ProcessManagement_Activity',
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 ActivityGet()
|
||||
|
||||
get Activity attributes
|
||||
|
||||
my $Activity = $ActivityObject->ActivityGet(
|
||||
ID => 123, # ID or EntityID is needed
|
||||
EntityID => 'A1',
|
||||
ActivityDialogNames => 1, # default 0, 1 || 0, if 0 returns an ActivityDialogs array
|
||||
# with the activity dialog entity IDs, if 1 returns an
|
||||
# ActivitiDialogs hash with the activity entity IDs as
|
||||
# keys and ActivityDialog Names as values
|
||||
UserID => 123, # mandatory
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$Activity = {
|
||||
ID => 123,
|
||||
EntityID => 'A1',
|
||||
Name => 'some name',
|
||||
Config => $ConfigHashRef,
|
||||
ActiviyDialogs => ['AD1','AD2','AD3'],
|
||||
CreateTime => '2012-07-04 15:08:00',
|
||||
ChangeTime => '2012-07-04 15:08:00',
|
||||
};
|
||||
|
||||
$Activity = {
|
||||
ID => 123,
|
||||
EntityID => 'P1',
|
||||
Name => 'some name',
|
||||
Config => $ConfigHashRef,
|
||||
ActivityDialogs => {
|
||||
'AD1' => 'ActivityDialog1',
|
||||
'AD2' => 'ActivityDialog2',
|
||||
'AD3' => 'ActivityDialog3',
|
||||
};
|
||||
CreateTime => '2012-07-04 15:08:00',
|
||||
ChangeTime => '2012-07-04 15:08:00',
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub ActivityGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
if ( !$Param{ID} && !$Param{EntityID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need ID or EntityID!'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need UserID!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
my $ActivityDialogNames = 0;
|
||||
if ( defined $Param{ActivityDialogNames} && $Param{ActivityDialogNames} == 1 ) {
|
||||
$ActivityDialogNames = 1;
|
||||
}
|
||||
|
||||
# check cache
|
||||
my $CacheKey;
|
||||
if ( $Param{ID} ) {
|
||||
$CacheKey = 'ActivityGet::ID::' . $Param{ID} . '::ActivityDialogNames::'
|
||||
. $ActivityDialogNames;
|
||||
}
|
||||
else {
|
||||
$CacheKey = 'ActivityGet::EntityID::' . $Param{EntityID} . '::ActivityDialogNames::'
|
||||
. $ActivityDialogNames;
|
||||
}
|
||||
|
||||
# get cache object
|
||||
my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');
|
||||
|
||||
my $Cache = $CacheObject->Get(
|
||||
Type => 'ProcessManagement_Activity',
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if $Cache;
|
||||
|
||||
# get database object
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# sql
|
||||
if ( $Param{ID} ) {
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT id, entity_id, name, config, create_time, change_time
|
||||
FROM pm_activity
|
||||
WHERE id = ?',
|
||||
Bind => [ \$Param{ID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
}
|
||||
else {
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT id, entity_id, name, config, create_time, change_time
|
||||
FROM pm_activity
|
||||
WHERE entity_id = ?',
|
||||
Bind => [ \$Param{EntityID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
}
|
||||
|
||||
# get yaml object
|
||||
my $YAMLObject = $Kernel::OM->Get('Kernel::System::YAML');
|
||||
|
||||
my %Data;
|
||||
while ( my @Data = $DBObject->FetchrowArray() ) {
|
||||
|
||||
my $Config = $YAMLObject->Load( Data => $Data[3] );
|
||||
|
||||
%Data = (
|
||||
ID => $Data[0],
|
||||
EntityID => $Data[1],
|
||||
Name => $Data[2],
|
||||
Config => $Config,
|
||||
CreateTime => $Data[4],
|
||||
ChangeTime => $Data[5],
|
||||
);
|
||||
}
|
||||
|
||||
return if !$Data{ID};
|
||||
|
||||
# create the ActivityDialogsList
|
||||
if ($ActivityDialogNames) {
|
||||
|
||||
my %ActivityDialogs;
|
||||
if ( IsHashRefWithData( $Data{Config}->{ActivityDialog} ) ) {
|
||||
|
||||
# get activity dialog object
|
||||
my $ActivityDialogObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::ActivityDialog');
|
||||
|
||||
my $ActivityDialogList = $ActivityDialogObject->ActivityDialogList(
|
||||
UseEntities => 1,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
for my $ActivityOrder ( sort { $a <=> $b } keys %{ $Data{Config}->{ActivityDialog} } ) {
|
||||
$ActivityDialogs{ $Data{Config}->{ActivityDialog}->{$ActivityOrder} }
|
||||
= $ActivityDialogList->{ $Data{Config}->{ActivityDialog}->{$ActivityOrder} };
|
||||
}
|
||||
}
|
||||
$Data{ActivityDialogs} = \%ActivityDialogs;
|
||||
}
|
||||
else {
|
||||
my @ActivityDialogList;
|
||||
|
||||
if ( IsHashRefWithData( $Data{Config}->{ActivityDialog} ) ) {
|
||||
@ActivityDialogList = map { $Data{Config}->{ActivityDialog}->{$_} }
|
||||
sort { $a <=> $b } keys %{ $Data{Config}->{ActivityDialog} };
|
||||
}
|
||||
$Data{ActivityDialogs} = \@ActivityDialogList;
|
||||
}
|
||||
|
||||
# set cache
|
||||
$CacheObject->Set(
|
||||
Type => 'ProcessManagement_Activity',
|
||||
Key => $CacheKey,
|
||||
Value => \%Data,
|
||||
TTL => $Self->{CacheTTL},
|
||||
);
|
||||
|
||||
return \%Data;
|
||||
}
|
||||
|
||||
=head2 ActivityUpdate()
|
||||
|
||||
update Activity attributes
|
||||
|
||||
returns 1 if success or undef otherwise
|
||||
|
||||
my $Success = $ActivityObject->ActivityUpdate(
|
||||
ID => 123, # mandatory
|
||||
EntityID => 'A1' # mandatory, exportable unique identifier
|
||||
Name => 'NameOfProcess', # mandatory
|
||||
Config => $ConfigHashRef, # mandatory, process configuration to be stored in YAML
|
||||
# format
|
||||
UserID => 123, # mandatory
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ActivityUpdate {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Key (qw(ID EntityID Name Config UserID)) {
|
||||
if ( !$Param{$Key} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Key!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get database object
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# check if EntityID already exists
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => "
|
||||
SELECT id FROM pm_activity
|
||||
WHERE $Self->{Lower}(entity_id) = $Self->{Lower}(?)
|
||||
AND id != ?",
|
||||
Bind => [ \$Param{EntityID}, \$Param{ID} ],
|
||||
LIMIT => 1,
|
||||
);
|
||||
|
||||
my $EntityExists;
|
||||
while ( my @Data = $DBObject->FetchrowArray() ) {
|
||||
$EntityExists = 1;
|
||||
}
|
||||
|
||||
if ($EntityExists) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "The EntityID:$Param{Name} already exists for a activity!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# check config valid format
|
||||
if ( ref $Param{Config} ne 'HASH' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Config needs to be a valid Hash reference!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# dump config as string
|
||||
my $Config = $Kernel::OM->Get('Kernel::System::YAML')->Dump( Data => $Param{Config} );
|
||||
|
||||
# Make sure the resulting string has the UTF-8 flag. YAML only sets it if
|
||||
# part of the data already had it.
|
||||
utf8::upgrade($Config);
|
||||
|
||||
# check if need to update db
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT entity_id, name, config
|
||||
FROM pm_activity
|
||||
WHERE id = ?',
|
||||
Bind => [ \$Param{ID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
|
||||
my $CurrentEntityID;
|
||||
my $CurrentName;
|
||||
my $CurrentConfig;
|
||||
while ( my @Data = $DBObject->FetchrowArray() ) {
|
||||
$CurrentEntityID = $Data[0];
|
||||
$CurrentName = $Data[1];
|
||||
$CurrentConfig = $Data[2];
|
||||
}
|
||||
|
||||
if ($CurrentEntityID) {
|
||||
|
||||
return 1 if $CurrentEntityID eq $Param{EntityID}
|
||||
&& $CurrentName eq $Param{Name}
|
||||
&& $CurrentConfig eq $Config;
|
||||
}
|
||||
|
||||
# sql
|
||||
return if !$DBObject->Do(
|
||||
SQL => '
|
||||
UPDATE pm_activity
|
||||
SET entity_id = ?, name = ?, config = ?, change_time = current_timestamp, change_by = ?
|
||||
WHERE id = ?',
|
||||
Bind => [
|
||||
\$Param{EntityID}, \$Param{Name}, \$Config, \$Param{UserID},
|
||||
\$Param{ID},
|
||||
],
|
||||
);
|
||||
|
||||
# delete cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
|
||||
Type => 'ProcessManagement_Activity',
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 ActivityList()
|
||||
|
||||
get an Activity list
|
||||
|
||||
my $List = $ActivityObject->ActivityList(
|
||||
UseEntities => 0, # default 0, 1 || 0. if 0 the return hash keys are
|
||||
# the activity IDs otherwise keys are the
|
||||
# activity entity IDs
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$List = {
|
||||
1 => 'Activity1',
|
||||
}
|
||||
|
||||
or
|
||||
|
||||
$List = {
|
||||
'A1' => 'Activity1',
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub ActivityList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need UserID!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get cache object
|
||||
my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');
|
||||
|
||||
# check cache
|
||||
my $UseEntities = 0;
|
||||
if ( defined $Param{UseEntities} && $Param{UseEntities} ) {
|
||||
$UseEntities = 1;
|
||||
}
|
||||
my $CacheKey = 'ActivityList::UseEntities::' . $UseEntities;
|
||||
my $Cache = $CacheObject->Get(
|
||||
Type => 'ProcessManagement_Activity',
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if ref $Cache;
|
||||
|
||||
# get database object
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT id, entity_id, name
|
||||
FROM pm_activity',
|
||||
);
|
||||
|
||||
my %Data;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
if ( !$UseEntities ) {
|
||||
$Data{ $Row[0] } = $Row[2];
|
||||
}
|
||||
else {
|
||||
$Data{ $Row[1] } = $Row[2];
|
||||
}
|
||||
}
|
||||
|
||||
# set cache
|
||||
$CacheObject->Set(
|
||||
Type => 'ProcessManagement_Activity',
|
||||
Key => $CacheKey,
|
||||
Value => \%Data,
|
||||
TTL => $Self->{CacheTTL},
|
||||
);
|
||||
|
||||
return \%Data;
|
||||
}
|
||||
|
||||
=head2 ActivityListGet()
|
||||
|
||||
get an Activity list with all activity details
|
||||
|
||||
my $List = $ActivityObject->ActivityListGet(
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$List = [
|
||||
{
|
||||
ID => 123,
|
||||
EntityID => 'A1',
|
||||
Name => 'some name',
|
||||
Config => $ConfigHashRef,
|
||||
ActiviyDialogs => ['AD1','AD2','AD3'],
|
||||
CreateTime => '2012-07-04 15:08:00',
|
||||
ChangeTime => '2012-07-04 15:08:00',
|
||||
}
|
||||
{
|
||||
ID => 456,
|
||||
EntityID => 'A2',
|
||||
Name => 'some name',
|
||||
Config => $ConfigHashRef,
|
||||
ActiviyDialogs => ['AD3','AD4','AD5'],
|
||||
CreateTime => '2012-07-04 15:09:00',
|
||||
ChangeTime => '2012-07-04 15:09:00',
|
||||
}
|
||||
];
|
||||
|
||||
=cut
|
||||
|
||||
sub ActivityListGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need UserID!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get cache object
|
||||
my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');
|
||||
|
||||
# check cache
|
||||
my $CacheKey = 'ActivityListGet';
|
||||
|
||||
my $Cache = $CacheObject->Get(
|
||||
Type => 'ProcessManagement_Activity',
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if $Cache;
|
||||
|
||||
# get database object
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# sql
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT id, entity_id
|
||||
FROM pm_activity
|
||||
ORDER BY id',
|
||||
);
|
||||
|
||||
my @ActivityIDs;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
push @ActivityIDs, $Row[0];
|
||||
}
|
||||
|
||||
my @Data;
|
||||
for my $ItemID (@ActivityIDs) {
|
||||
|
||||
my $ActivityData = $Self->ActivityGet(
|
||||
ID => $ItemID,
|
||||
UserID => 1,
|
||||
);
|
||||
push @Data, $ActivityData;
|
||||
}
|
||||
|
||||
# set cache
|
||||
$CacheObject->Set(
|
||||
Type => 'ProcessManagement_Activity',
|
||||
Key => $CacheKey,
|
||||
Value => \@Data,
|
||||
TTL => $Self->{CacheTTL},
|
||||
);
|
||||
|
||||
return \@Data;
|
||||
}
|
||||
|
||||
=head2 ActivitySearch()
|
||||
|
||||
search activities by process name
|
||||
|
||||
my $ActivityEntityIDs = $ActivityObject->ActivitySearch(
|
||||
ActivityName => 'SomeText', # e. g. "SomeText*", "Some*ext" or ['*SomeTest1*', '*SomeTest2*']
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$ActivityEntityIDs = [ 'Activity-e11e2e9aa83344a235279d4f6babc6ec', 'Activity-f8194a25ab0ccddefeb4240c281c1f56' ];
|
||||
|
||||
=cut
|
||||
|
||||
sub ActivitySearch {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
if ( !$Param{ActivityName} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need ActivityName!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
my $SQL = 'SELECT DISTINCT entity_id
|
||||
FROM pm_activity ';
|
||||
|
||||
# if it's no ref, put it to array ref
|
||||
if ( ref $Param{ActivityName} eq '' ) {
|
||||
$Param{ActivityName} = [ $Param{ActivityName} ];
|
||||
}
|
||||
|
||||
if ( IsArrayRefWithData( $Param{ActivityName} ) ) {
|
||||
$SQL .= ' WHERE' if IsArrayRefWithData( $Param{ActivityName} );
|
||||
}
|
||||
|
||||
my @QuotedSearch;
|
||||
my $SQLOR = 0;
|
||||
|
||||
VALUE:
|
||||
for my $Value ( @{ $Param{ActivityName} } ) {
|
||||
|
||||
next VALUE if !defined $Value || !length $Value;
|
||||
|
||||
$Value = '%' . $DBObject->Quote( $Value, 'Like' ) . '%';
|
||||
$Value =~ s/\*/%/g;
|
||||
$Value =~ s/%%/%/gi;
|
||||
|
||||
if ($SQLOR) {
|
||||
$SQL .= ' OR';
|
||||
}
|
||||
|
||||
$SQL .= ' name LIKE ? ';
|
||||
|
||||
push @QuotedSearch, $Value;
|
||||
$SQLOR = 1;
|
||||
|
||||
}
|
||||
|
||||
if ( IsArrayRefWithData( $Param{ActivityName} ) ) {
|
||||
$SQL .= $DBObject->GetDatabaseFunction('LikeEscapeString');
|
||||
}
|
||||
$SQL .= ' ORDER BY entity_id';
|
||||
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => $SQL,
|
||||
Bind => [ \(@QuotedSearch) ]
|
||||
);
|
||||
|
||||
my @Data;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
push @Data, $Row[0];
|
||||
}
|
||||
|
||||
return \@Data;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
689
Perl OTRS/Kernel/System/ProcessManagement/DB/ActivityDialog.pm
Normal file
689
Perl OTRS/Kernel/System/ProcessManagement/DB/ActivityDialog.pm
Normal file
@@ -0,0 +1,689 @@
|
||||
# --
|
||||
# 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::ProcessManagement::DB::ActivityDialog;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::Cache',
|
||||
'Kernel::System::DB',
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::YAML',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::DB::ActivityDialog
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Process Management DB ActivityDialog backend
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $ActivityDialogObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::ActivityDialog');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
# get the cache TTL (in seconds)
|
||||
$Self->{CacheTTL} = int( $Kernel::OM->Get('Kernel::Config')->Get('Process::CacheTTL') || 3600 );
|
||||
|
||||
# set lower if database is case sensitive
|
||||
$Self->{Lower} = '';
|
||||
if ( $Kernel::OM->Get('Kernel::System::DB')->GetDatabaseFunction('CaseSensitive') ) {
|
||||
$Self->{Lower} = 'LOWER';
|
||||
}
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 ActivityDialogAdd()
|
||||
|
||||
add new ActivityDialog
|
||||
|
||||
returns the id of the created activity dialog if success or undef otherwise
|
||||
|
||||
my $ID = $ActivityDialogObject->ActivityDialogAdd(
|
||||
EntityID => 'AD1' # mandatory, exportable unique identifier
|
||||
Name => 'NameOfActivityDialog', # mandatory
|
||||
Config => $ConfigHashRef, # mandatory, activity dialog configuration to be
|
||||
# stored in YAML format
|
||||
UserID => 123, # mandatory
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$ID = 567;
|
||||
|
||||
=cut
|
||||
|
||||
sub ActivityDialogAdd {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Key (qw(EntityID Name Config UserID)) {
|
||||
if ( !$Param{$Key} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Key!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get database object
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# check if EntityID already exists
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => "
|
||||
SELECT id
|
||||
FROM pm_activity_dialog
|
||||
WHERE $Self->{Lower}(entity_id) = $Self->{Lower}(?)",
|
||||
Bind => [ \$Param{EntityID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
|
||||
my $EntityExists;
|
||||
while ( my @Data = $DBObject->FetchrowArray() ) {
|
||||
$EntityExists = 1;
|
||||
}
|
||||
|
||||
if ($EntityExists) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "The EntityID:$Param{EntityID} already exists for an activity dialog!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# check config valid format (at least it must contain the description short, fields and field
|
||||
# order)
|
||||
if ( !IsHashRefWithData( $Param{Config} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Config needs to be a valid Hash reference!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
for my $Needed (qw(DescriptionShort Fields FieldOrder)) {
|
||||
if ( !$Param{Config}->{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed in Config!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check config formats
|
||||
if ( ref $Param{Config}->{Fields} ne 'HASH' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Config Fields must be a Hash!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
if ( ref $Param{Config}->{FieldOrder} ne 'ARRAY' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Config Fields must be an Array!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# dump layout and config as string
|
||||
my $Config = $Kernel::OM->Get('Kernel::System::YAML')->Dump( Data => $Param{Config} );
|
||||
|
||||
# Make sure the resulting string has the UTF-8 flag. YAML only sets it if
|
||||
# part of the data already had it.
|
||||
utf8::upgrade($Config);
|
||||
|
||||
# sql
|
||||
return if !$DBObject->Do(
|
||||
SQL => '
|
||||
INSERT INTO pm_activity_dialog ( entity_id, name, config, create_time,
|
||||
create_by, change_time, change_by )
|
||||
VALUES (?, ?, ?, current_timestamp, ?, current_timestamp, ?)',
|
||||
Bind => [
|
||||
\$Param{EntityID}, \$Param{Name}, \$Config, \$Param{UserID}, \$Param{UserID},
|
||||
],
|
||||
);
|
||||
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => 'SELECT id FROM pm_activity_dialog WHERE entity_id = ?',
|
||||
Bind => [ \$Param{EntityID} ],
|
||||
);
|
||||
|
||||
my $ID;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
$ID = $Row[0];
|
||||
}
|
||||
|
||||
# delete cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
|
||||
Type => 'ProcessManagement_ActivityDialog',
|
||||
);
|
||||
|
||||
return if !$ID;
|
||||
|
||||
return $ID;
|
||||
}
|
||||
|
||||
=head2 ActivityDialogDelete()
|
||||
|
||||
delete an ActivityDialog
|
||||
|
||||
returns 1 if success or undef otherwise
|
||||
|
||||
my $Success = $ActivityDialogObject->ActivityDialogDelete(
|
||||
ID => 123,
|
||||
UserID => 123,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ActivityDialogDelete {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Key (qw(ID UserID)) {
|
||||
if ( !$Param{$Key} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Key!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check if exists
|
||||
my $ActivityDialog = $Self->ActivityDialogGet(
|
||||
ID => $Param{ID},
|
||||
UserID => 1,
|
||||
);
|
||||
return if !IsHashRefWithData($ActivityDialog);
|
||||
|
||||
# delete activity dialog
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => 'DELETE FROM pm_activity_dialog WHERE id = ?',
|
||||
Bind => [ \$Param{ID} ],
|
||||
);
|
||||
|
||||
# delete cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
|
||||
Type => 'ProcessManagement_ActivityDialog',
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 ActivityDialogGet()
|
||||
|
||||
get Activity Dialog attributes
|
||||
|
||||
my $ActivityDialog = $ActivityDialogObject->ActivityDialogGet(
|
||||
ID => 123, # ID or EntityID is needed
|
||||
EntityID => 'P1',
|
||||
UserID => 123, # mandatory
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$ActivityDialog = {
|
||||
ID => 123,
|
||||
EntityID => 'AD1',
|
||||
Name => 'some name',
|
||||
Config => $ConfigHashRef,
|
||||
CreateTime => '2012-07-04 15:08:00',
|
||||
ChangeTime => '2012-07-04 15:08:00',
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub ActivityDialogGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
if ( !$Param{ID} && !$Param{EntityID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need ID or EntityID!'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need UserID!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get cache object
|
||||
my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');
|
||||
|
||||
# check cache
|
||||
my $CacheKey;
|
||||
if ( $Param{ID} ) {
|
||||
$CacheKey = 'ActivityDialogGet::ID::' . $Param{ID};
|
||||
}
|
||||
else {
|
||||
$CacheKey = 'ActivityDialogGet::EntityID::' . $Param{EntityID};
|
||||
}
|
||||
|
||||
my $Cache = $CacheObject->Get(
|
||||
Type => 'ProcessManagement_ActivityDialog',
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if $Cache;
|
||||
|
||||
# get database object
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# sql
|
||||
if ( $Param{ID} ) {
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT id, entity_id, name, config, create_time, change_time
|
||||
FROM pm_activity_dialog
|
||||
WHERE id = ?',
|
||||
Bind => [ \$Param{ID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
}
|
||||
else {
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT id, entity_id, name, config, create_time, change_time
|
||||
FROM pm_activity_dialog
|
||||
WHERE entity_id = ?',
|
||||
Bind => [ \$Param{EntityID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
}
|
||||
|
||||
# get yaml object
|
||||
my $YAMLObject = $Kernel::OM->Get('Kernel::System::YAML');
|
||||
|
||||
my %Data;
|
||||
while ( my @Data = $DBObject->FetchrowArray() ) {
|
||||
|
||||
my $Config = $YAMLObject->Load( Data => $Data[3] );
|
||||
|
||||
%Data = (
|
||||
ID => $Data[0],
|
||||
EntityID => $Data[1],
|
||||
Name => $Data[2],
|
||||
Config => $Config,
|
||||
CreateTime => $Data[4],
|
||||
ChangeTime => $Data[5],
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
return if !$Data{ID};
|
||||
|
||||
# set cache
|
||||
$CacheObject->Set(
|
||||
Type => 'ProcessManagement_ActivityDialog',
|
||||
Key => $CacheKey,
|
||||
Value => \%Data,
|
||||
TTL => $Self->{CacheTTL},
|
||||
);
|
||||
|
||||
return \%Data;
|
||||
}
|
||||
|
||||
=head2 ActivityDialogUpdate()
|
||||
|
||||
update ActivityDialog attributes
|
||||
|
||||
returns 1 if success or undef otherwise
|
||||
|
||||
my $Success = $ActivityDialogObject->ActivityDialogUpdate(
|
||||
ID => 123, # mandatory
|
||||
EntityID => 'AD1' # mandatory, exportable unique identifier
|
||||
Name => 'NameOfActivityDialog', # mandatory
|
||||
Config => $ConfigHashRef, # mandatory, actvity dialog configuration to be
|
||||
# stored in YAML format
|
||||
UserID => 123, # mandatory
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ActivityDialogUpdate {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Key (qw(ID EntityID Name Config UserID)) {
|
||||
if ( !$Param{$Key} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Key!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get database object
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# check if EntityID already exists
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => "
|
||||
SELECT id FROM pm_activity_dialog
|
||||
WHERE $Self->{Lower}(entity_id) = $Self->{Lower}(?)
|
||||
AND id != ?",
|
||||
Bind => [ \$Param{EntityID}, \$Param{ID} ],
|
||||
LIMIT => 1,
|
||||
);
|
||||
|
||||
my $EntityExists;
|
||||
while ( my @Data = $DBObject->FetchrowArray() ) {
|
||||
$EntityExists = 1;
|
||||
}
|
||||
|
||||
if ($EntityExists) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "The EntityID:$Param{Name} already exists for an ActivityDialog!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# check config valid format (at least it must contain the description)
|
||||
if ( !IsHashRefWithData( $Param{Config} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Config needs to be a valid Hash reference!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
for my $Needed (qw(DescriptionShort Fields FieldOrder)) {
|
||||
if ( !$Param{Config}->{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed in Config!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check config formats
|
||||
if ( ref $Param{Config}->{Fields} ne 'HASH' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Config Fields must be a Hash!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
if ( ref $Param{Config}->{FieldOrder} ne 'ARRAY' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Config Fields must be an Array!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# dump layout and config as string
|
||||
my $Config = $Kernel::OM->Get('Kernel::System::YAML')->Dump( Data => $Param{Config} );
|
||||
|
||||
# Make sure the resulting string has the UTF-8 flag. YAML only sets it if
|
||||
# part of the data already had it.
|
||||
utf8::upgrade($Config);
|
||||
|
||||
# check if need to update db
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT entity_id, name, config
|
||||
FROM pm_activity_dialog
|
||||
WHERE id = ?',
|
||||
Bind => [ \$Param{ID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
|
||||
my $CurrentEntityID;
|
||||
my $CurrentName;
|
||||
my $CurrentConfig;
|
||||
while ( my @Data = $DBObject->FetchrowArray() ) {
|
||||
$CurrentEntityID = $Data[0];
|
||||
$CurrentName = $Data[1];
|
||||
$CurrentConfig = $Data[2];
|
||||
}
|
||||
|
||||
if ($CurrentEntityID) {
|
||||
|
||||
return 1 if $CurrentEntityID eq $Param{EntityID}
|
||||
&& $CurrentName eq $Param{Name}
|
||||
&& $CurrentConfig eq $Config;
|
||||
}
|
||||
|
||||
# sql
|
||||
return if !$DBObject->Do(
|
||||
SQL => '
|
||||
UPDATE pm_activity_dialog
|
||||
SET entity_id = ?, name = ?, config = ?, change_time = current_timestamp,
|
||||
change_by = ?
|
||||
WHERE id = ?',
|
||||
Bind => [
|
||||
\$Param{EntityID}, \$Param{Name}, \$Config, \$Param{UserID}, \$Param{ID},
|
||||
],
|
||||
);
|
||||
|
||||
# delete cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
|
||||
Type => 'ProcessManagement_ActivityDialog',
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 ActivityDialogList()
|
||||
|
||||
get an ActivityDialog list
|
||||
|
||||
my $List = $ActivityDialogObject->ActivityDialogList(
|
||||
UseEntities => 0, # default 0, 1 || 0. if 0 the return hash keys are
|
||||
# the activity dialog IDs otherwise keys are the
|
||||
# activity dialog entity IDs
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$List = {
|
||||
1 => 'NameOfActivityDialog',
|
||||
}
|
||||
|
||||
or
|
||||
|
||||
$List = {
|
||||
'AD1' => 'NameOfActivityDialog',
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub ActivityDialogList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need UserID!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# check cache
|
||||
my $UseEntities = 0;
|
||||
if ( defined $Param{UseEntities} && $Param{UseEntities} ) {
|
||||
$UseEntities = 1;
|
||||
}
|
||||
|
||||
# get cache object
|
||||
my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');
|
||||
|
||||
my $CacheKey = 'ActivityDialogList::UseEntities::' . $UseEntities;
|
||||
my $Cache = $CacheObject->Get(
|
||||
Type => 'ProcessManagement_ActivityDialog',
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if ref $Cache;
|
||||
|
||||
# get database object
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
my $SQL = '
|
||||
SELECT id, entity_id, name
|
||||
FROM pm_activity_dialog';
|
||||
|
||||
return if !$DBObject->Prepare( SQL => $SQL );
|
||||
|
||||
my %Data;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
if ( !$UseEntities ) {
|
||||
$Data{ $Row[0] } = $Row[2];
|
||||
}
|
||||
else {
|
||||
$Data{ $Row[1] } = $Row[2];
|
||||
}
|
||||
}
|
||||
|
||||
# set cache
|
||||
$CacheObject->Set(
|
||||
Type => 'ProcessManagement_ActivityDialog',
|
||||
Key => $CacheKey,
|
||||
Value => \%Data,
|
||||
TTL => $Self->{CacheTTL},
|
||||
);
|
||||
|
||||
return \%Data;
|
||||
}
|
||||
|
||||
=head2 ActivityDialogListGet()
|
||||
|
||||
get an Activity Dialog list with all activity dialog details
|
||||
|
||||
my $List = $ActivityDialogObject->ActivityDialogListGet(
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$List = [
|
||||
{
|
||||
ID => 123,
|
||||
EntityID => 'AD1',
|
||||
Name => 'some name',
|
||||
Config => $ConfigHashRef,
|
||||
CreateTime => '2012-07-04 15:08:00',
|
||||
ChangeTime => '2012-07-04 15:08:00',
|
||||
}
|
||||
{
|
||||
ID => 456,
|
||||
EntityID => 'AD2',
|
||||
Name => 'some name',
|
||||
Config => $ConfigHashRef,
|
||||
CreateTime => '2012-07-04 15:09:00',
|
||||
ChangeTime => '2012-07-04 15:09:00',
|
||||
}
|
||||
];
|
||||
|
||||
=cut
|
||||
|
||||
sub ActivityDialogListGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need UserID!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get cache object
|
||||
my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');
|
||||
|
||||
# check cache
|
||||
my $CacheKey = 'ActivityDialogListGet';
|
||||
|
||||
my $Cache = $CacheObject->Get(
|
||||
Type => 'ProcessManagement_ActivityDialog',
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if $Cache;
|
||||
|
||||
# get database object
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# sql
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT id, entity_id
|
||||
FROM pm_activity_dialog
|
||||
ORDER BY id',
|
||||
);
|
||||
|
||||
my @ActivityDialogIDs;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
push @ActivityDialogIDs, $Row[0];
|
||||
}
|
||||
|
||||
my @Data;
|
||||
for my $ItemID (@ActivityDialogIDs) {
|
||||
|
||||
my $ActivityDialogData = $Self->ActivityDialogGet(
|
||||
ID => $ItemID,
|
||||
UserID => 1,
|
||||
);
|
||||
push @Data, $ActivityDialogData;
|
||||
}
|
||||
|
||||
# set cache
|
||||
$CacheObject->Set(
|
||||
Type => 'ProcessManagement_ActivityDialog',
|
||||
Key => $CacheKey,
|
||||
Value => \@Data,
|
||||
TTL => $Self->{CacheTTL},
|
||||
);
|
||||
|
||||
return \@Data;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
454
Perl OTRS/Kernel/System/ProcessManagement/DB/Entity.pm
Normal file
454
Perl OTRS/Kernel/System/ProcessManagement/DB/Entity.pm
Normal file
@@ -0,0 +1,454 @@
|
||||
# --
|
||||
# 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::ProcessManagement::DB::Entity;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::DB',
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::Main',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::DB::Entity
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Process Management DB Entity backend
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $EntityObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::Entity');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
$Self->{ValidEntities} = {
|
||||
'Process' => 1,
|
||||
'Activity' => 1,
|
||||
'ActivityDialog' => 1,
|
||||
'Transition' => 1,
|
||||
'TransitionAction' => 1,
|
||||
};
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 EntityIDGenerate()
|
||||
|
||||
generate unique Entity ID
|
||||
|
||||
my $EntityID = $EntityObject->EntityIDGenerate(
|
||||
EntityType => 'Process', # mandatory, 'Process' || 'Activity' || 'ActivityDialog'
|
||||
# || 'Transition' || 'TransitionAction'
|
||||
UserID => 123, # mandatory
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$EntityID = 'P1';
|
||||
|
||||
=cut
|
||||
|
||||
sub EntityIDGenerate {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Key (qw(EntityType UserID)) {
|
||||
if ( !$Param{$Key} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Key!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check entity type
|
||||
if ( !$Self->{ValidEntities}->{ $Param{EntityType} } ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "The EntityType:$Param{EntityType} is invalid!"
|
||||
);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
# this is not a 'proper' GUID as defined in RFC 4122 but it's close enough for
|
||||
# our purposes and we can replace it later if needed
|
||||
my $GUID = $Kernel::OM->Get('Kernel::System::Main')->GenerateRandomString(
|
||||
Length => 32,
|
||||
Dictionary => [ 0 .. 9, 'a' .. 'f' ], # hexadecimal
|
||||
);
|
||||
|
||||
my $EntityID = $Param{EntityType} . '-' . $GUID;
|
||||
|
||||
return $EntityID;
|
||||
}
|
||||
|
||||
=head2 EntitySyncStateSet()
|
||||
|
||||
set sync state for an entity.
|
||||
|
||||
my $Success = $EntityObject->EntitySyncStateSet(
|
||||
EntityType => 'Process', # 'Process' || 'Activity' || 'ActivityDialog'
|
||||
# || 'Transition' || 'TransitionAction', type of the
|
||||
# entity
|
||||
EntityID => 'P1',
|
||||
SyncState => 'not_sync', # the sync state to set
|
||||
UserID => 123,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub EntitySyncStateSet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Needed (qw(EntityType EntityID SyncState UserID)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check entity type
|
||||
if ( !$Self->{ValidEntities}->{ $Param{EntityType} } ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "The EntityType:$Param{EntityType} is invalid!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get database object
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# create new
|
||||
if ( !%{ $Self->EntitySyncStateGet(%Param) || {} } ) {
|
||||
return if !$DBObject->Do(
|
||||
SQL => '
|
||||
INSERT INTO pm_entity_sync
|
||||
(entity_type, entity_id, sync_state, create_time, change_time)
|
||||
VALUES (?, ?, ?, current_timestamp, current_timestamp)',
|
||||
Bind => [
|
||||
\$Param{EntityType}, \$Param{EntityID}, \$Param{SyncState},
|
||||
],
|
||||
);
|
||||
}
|
||||
else { # update existing
|
||||
|
||||
return if !$DBObject->Do(
|
||||
SQL => '
|
||||
UPDATE pm_entity_sync
|
||||
SET sync_state = ?, change_time = current_timestamp
|
||||
WHERE entity_type = ?
|
||||
AND entity_id = ?',
|
||||
Bind => [
|
||||
\$Param{SyncState}, \$Param{EntityType}, \$Param{EntityID},
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 EntitySyncStateGet()
|
||||
|
||||
gets the sync state of an entity
|
||||
|
||||
my $EntitySyncState = $EntityObject->EntitySyncStateGet(
|
||||
EntityType => 'Process', # 'Process' || 'Activity' || 'ActivityDialog'
|
||||
# || 'Transition' || 'TransitionAction', type of the
|
||||
# entity
|
||||
EntityID => 'P1',
|
||||
UserID => 123,
|
||||
);
|
||||
|
||||
If sync state was found, returns:
|
||||
|
||||
$EntitySyncState = {
|
||||
EntityType => 'Process',
|
||||
EntityID => 'P1',
|
||||
SyncState => 'not_sync',
|
||||
CreateTime => '2011-02-08 15:08:00',
|
||||
ChangeTime => '2011-02-08 15:08:00',
|
||||
};
|
||||
|
||||
If no sync state was found, returns undef.
|
||||
|
||||
=cut
|
||||
|
||||
sub EntitySyncStateGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Needed (qw(EntityType EntityID UserID)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check entity type
|
||||
if ( !$Self->{ValidEntities}->{ $Param{EntityType} } ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "The EntityType:$Param{EntityType} is invalid!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get database object
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT entity_type, entity_id, sync_state, create_time, change_time
|
||||
FROM pm_entity_sync
|
||||
WHERE entity_type =?
|
||||
AND entity_id = ?',
|
||||
Bind => [
|
||||
\$Param{EntityType}, \$Param{EntityID},
|
||||
],
|
||||
);
|
||||
|
||||
my %Result;
|
||||
|
||||
while ( my @Data = $DBObject->FetchrowArray() ) {
|
||||
|
||||
%Result = (
|
||||
EntityType => $Data[0],
|
||||
EntityID => $Data[1],
|
||||
SyncState => $Data[2],
|
||||
CreateTime => $Data[3],
|
||||
ChangeTime => $Data[4],
|
||||
);
|
||||
}
|
||||
|
||||
return if !IsHashRefWithData( \%Result );
|
||||
|
||||
return \%Result;
|
||||
}
|
||||
|
||||
=head2 EntitySyncStateDelete()
|
||||
|
||||
deletes sync state of an entity.
|
||||
|
||||
my $Success = $EntityObject->EntitySyncStateDelete(
|
||||
EntityType => 'Process', # 'Process' || 'Activity' || 'ActivityDialog'
|
||||
# || 'Transition' || 'TransitionAction', type of the
|
||||
# entity
|
||||
EntityID => 'P1',
|
||||
UserID => 123,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub EntitySyncStateDelete {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Key (qw(EntityType EntityID UserID)) {
|
||||
if ( !$Param{$Key} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Key!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check entity type
|
||||
if ( !$Self->{ValidEntities}->{ $Param{EntityType} } ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "The EntityType:$Param{EntityType} is invalid!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
return if ( !%{ $Self->EntitySyncStateGet(%Param) || {} } );
|
||||
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => '
|
||||
DELETE FROM pm_entity_sync
|
||||
WHERE entity_type = ?
|
||||
AND entity_id = ?',
|
||||
Bind => [
|
||||
\$Param{EntityType}, \$Param{EntityID},
|
||||
],
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 EntitySyncStatePurge()
|
||||
|
||||
deletes all entries .
|
||||
|
||||
my $Success = $EntityObject->EntitySyncStatePurge(
|
||||
UserID => 123,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub EntitySyncStatePurge {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Needed (qw(UserID)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => '
|
||||
DELETE FROM pm_entity_sync',
|
||||
Bind => [],
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 EntitySyncStateList()
|
||||
|
||||
gets a list of sync states.
|
||||
|
||||
my $EntitySyncStateList = $EntityObject->EntitySyncStateList(
|
||||
EntityType => 'Process', # optional, 'Process' || 'Activity' || 'ActivityDialog'
|
||||
# || 'Transition' || 'TransitionAction', type of the
|
||||
# entity
|
||||
SyncState => 'not_sync', # optional, only entries with this sync state
|
||||
UserID => 123,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$EntitySyncStateList = [
|
||||
{
|
||||
EntityType => 'Process',
|
||||
EntityID => 'P1',
|
||||
SyncState => 'sync_started',
|
||||
CreateTime => '2011-02-08 15:08:00',
|
||||
ChangeTime => '2011-02-08 15:08:00',
|
||||
},
|
||||
...
|
||||
];
|
||||
|
||||
=cut
|
||||
|
||||
sub EntitySyncStateList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Needed (qw(UserID)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $Param{EntityType} ) {
|
||||
|
||||
# check entity type
|
||||
if ( !$Self->{ValidEntities}->{ $Param{EntityType} } ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "The EntityType:$Param{EntityType} is invalid!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $SQL = '
|
||||
SELECT entity_type, entity_id, sync_state, create_time, change_time
|
||||
FROM pm_entity_sync';
|
||||
|
||||
my @Bind;
|
||||
|
||||
if ( $Param{EntityType} ) {
|
||||
$SQL .= ' WHERE entity_type = ?';
|
||||
push @Bind, \$Param{EntityType};
|
||||
|
||||
if ( $Param{SyncState} ) {
|
||||
$SQL .= ' AND sync_state = ?';
|
||||
push @Bind, \$Param{SyncState};
|
||||
}
|
||||
}
|
||||
elsif ( $Param{SyncState} ) {
|
||||
$SQL .= ' WHERE sync_state = ?';
|
||||
push @Bind, \$Param{SyncState};
|
||||
}
|
||||
|
||||
$SQL .= ' ORDER BY entity_id ASC';
|
||||
|
||||
# get database object
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => $SQL,
|
||||
Bind => \@Bind,
|
||||
);
|
||||
|
||||
my @Result;
|
||||
while ( my @Data = $DBObject->FetchrowArray() ) {
|
||||
|
||||
push @Result, {
|
||||
EntityType => $Data[0],
|
||||
EntityID => $Data[1],
|
||||
SyncState => $Data[2],
|
||||
CreateTime => $Data[3],
|
||||
ChangeTime => $Data[4],
|
||||
};
|
||||
}
|
||||
|
||||
return \@Result;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
2197
Perl OTRS/Kernel/System/ProcessManagement/DB/Process.pm
Normal file
2197
Perl OTRS/Kernel/System/ProcessManagement/DB/Process.pm
Normal file
File diff suppressed because it is too large
Load Diff
155
Perl OTRS/Kernel/System/ProcessManagement/DB/Process/State.pm
Normal file
155
Perl OTRS/Kernel/System/ProcessManagement/DB/Process/State.pm
Normal file
@@ -0,0 +1,155 @@
|
||||
# --
|
||||
# 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::ProcessManagement::DB::Process::State;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::Language qw(Translatable);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::DB::Process::State
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Process Management DB State backend
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $ProcessStateObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::Process::State');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
# create States list
|
||||
$Self->{StateList} = {
|
||||
'S1' => Translatable('Active'),
|
||||
'S2' => Translatable('Inactive'),
|
||||
'S3' => Translatable('FadeAway'),
|
||||
};
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 StateList()
|
||||
|
||||
get a State list
|
||||
|
||||
my $List = $StateObject->StateList(
|
||||
UserID => 123,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$List = {
|
||||
'S1' => 'Active',
|
||||
'S2' => 'Inactive',
|
||||
'S3' => 'FadeAway',
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub StateList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need UserID!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
return $Self->{StateList};
|
||||
}
|
||||
|
||||
=head2 StateLookup()
|
||||
|
||||
get State name or State EntityID
|
||||
|
||||
my $Name = $StateObject->StateLookup(
|
||||
EntityID => 'S1',
|
||||
UserID => 123,
|
||||
);
|
||||
|
||||
Returns:
|
||||
$Name = 'Active';
|
||||
|
||||
my $EntityID = $StateObject->StateLookup(
|
||||
Name => 'Active',
|
||||
UserID => 123,
|
||||
);
|
||||
|
||||
Returns:
|
||||
$EntityID = 'S1';
|
||||
|
||||
=cut
|
||||
|
||||
sub StateLookup {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need UserID!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !$Param{EntityID} && !$Param{Name} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "EntityID or Name is required!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# return state name
|
||||
my $Result;
|
||||
if ( $Param{EntityID} ) {
|
||||
$Result = $Self->{StateList}->{ $Param{EntityID} };
|
||||
}
|
||||
|
||||
# return state entity ID
|
||||
else {
|
||||
my %ReversedStateList = reverse %{ $Self->{StateList} };
|
||||
$Result = $ReversedStateList{ $Param{Name} };
|
||||
}
|
||||
|
||||
return $Result;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
675
Perl OTRS/Kernel/System/ProcessManagement/DB/Transition.pm
Normal file
675
Perl OTRS/Kernel/System/ProcessManagement/DB/Transition.pm
Normal file
@@ -0,0 +1,675 @@
|
||||
# --
|
||||
# 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::ProcessManagement::DB::Transition;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::Cache',
|
||||
'Kernel::System::DB',
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::YAML',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::DB::Transition
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Process Management DB Transition backend
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $TransitionObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::Transition');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
# get the cache TTL (in seconds)
|
||||
$Self->{CacheTTL} = int( $Kernel::OM->Get('Kernel::Config')->Get('Process::CacheTTL') || 3600 );
|
||||
|
||||
# set lower if database is case sensitive
|
||||
$Self->{Lower} = '';
|
||||
if ( $Kernel::OM->Get('Kernel::System::DB')->GetDatabaseFunction('CaseSensitive') ) {
|
||||
$Self->{Lower} = 'LOWER';
|
||||
}
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 TransitionAdd()
|
||||
|
||||
add new Trnsition
|
||||
|
||||
returns the id of the created Transition if success or undef otherwise
|
||||
|
||||
my $ID = $TransitionObject->TransitionAdd(
|
||||
EntityID => 'T1' # mandatory, exportable unique identifier
|
||||
Name => 'NameOfTransition', # mandatory
|
||||
Config => $ConfigHashRef, # mandatory, transition configuration to be stored in
|
||||
# YAML format
|
||||
UserID => 123, # mandatory
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$ID = 567;
|
||||
|
||||
=cut
|
||||
|
||||
sub TransitionAdd {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Key (qw(EntityID Name Config UserID)) {
|
||||
if ( !$Param{$Key} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Key!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get database object
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# check if EntityID already exists
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => "
|
||||
SELECT id
|
||||
FROM pm_transition
|
||||
WHERE $Self->{Lower}(entity_id) = $Self->{Lower}(?)",
|
||||
Bind => [ \$Param{EntityID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
|
||||
my $EntityExists;
|
||||
while ( my @Data = $DBObject->FetchrowArray() ) {
|
||||
$EntityExists = 1;
|
||||
}
|
||||
|
||||
if ($EntityExists) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "The EntityID:$Param{EntityID} already exists for a transition!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# check config valid format (at least it must contain the description short, fields and field
|
||||
# order)
|
||||
if ( !IsHashRefWithData( $Param{Config} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Config needs to be a valid Hash reference!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
for my $Needed (qw(Condition)) {
|
||||
if ( !$Param{Config}->{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed in Config!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check config formats
|
||||
if ( ref $Param{Config}->{Condition} ne 'HASH' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Config Fields must be a Hash!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# dump layout and config as string
|
||||
my $Config = $Kernel::OM->Get('Kernel::System::YAML')->Dump( Data => $Param{Config} );
|
||||
|
||||
# Make sure the resulting string has the UTF-8 flag. YAML only sets it if
|
||||
# part of the data already had it.
|
||||
utf8::upgrade($Config);
|
||||
|
||||
# sql
|
||||
return if !$DBObject->Do(
|
||||
SQL => '
|
||||
INSERT INTO pm_transition ( entity_id, name, config, create_time,
|
||||
create_by, change_time, change_by )
|
||||
VALUES (?, ?, ?, current_timestamp, ?, current_timestamp, ?)',
|
||||
Bind => [
|
||||
\$Param{EntityID}, \$Param{Name}, \$Config, \$Param{UserID}, \$Param{UserID},
|
||||
],
|
||||
);
|
||||
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => 'SELECT id FROM pm_transition WHERE entity_id = ?',
|
||||
Bind => [ \$Param{EntityID} ],
|
||||
);
|
||||
|
||||
my $ID;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
$ID = $Row[0];
|
||||
}
|
||||
|
||||
# delete cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
|
||||
Type => 'ProcessManagement_Transition',
|
||||
);
|
||||
|
||||
return if !$ID;
|
||||
|
||||
return $ID;
|
||||
}
|
||||
|
||||
=head2 TransitionDelete()
|
||||
|
||||
delete an Transition
|
||||
|
||||
returns 1 if success or undef otherwise
|
||||
|
||||
my $Success = $TransitionObject->TransitionDelete(
|
||||
ID => 123,
|
||||
UserID => 123,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub TransitionDelete {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Key (qw(ID UserID)) {
|
||||
if ( !$Param{$Key} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Key!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check if exists
|
||||
my $Transition = $Self->TransitionGet(
|
||||
ID => $Param{ID},
|
||||
UserID => 1,
|
||||
);
|
||||
return if !IsHashRefWithData($Transition);
|
||||
|
||||
# delete transition
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => 'DELETE FROM pm_transition WHERE id = ?',
|
||||
Bind => [ \$Param{ID} ],
|
||||
);
|
||||
|
||||
# delete cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
|
||||
Type => 'ProcessManagement_Transition',
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 TransitionGet()
|
||||
|
||||
get Transition attributes
|
||||
|
||||
my $Transition = $TransitionObject->TransitionGet(
|
||||
ID => 123, # ID or EntityID is needed
|
||||
EntityID => 'T1',
|
||||
UserID => 123, # mandatory
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$Transition = {
|
||||
ID => 123,
|
||||
EntityID => 'T1',
|
||||
Name => 'some name',
|
||||
Config => $ConfigHashRef,
|
||||
CreateTime => '2012-07-04 15:08:00',
|
||||
ChangeTime => '2012-07-04 15:08:00',
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub TransitionGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
if ( !$Param{ID} && !$Param{EntityID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need ID or EntityID!'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need UserID!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get cache object
|
||||
my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');
|
||||
|
||||
# check cache
|
||||
my $CacheKey;
|
||||
if ( $Param{ID} ) {
|
||||
$CacheKey = 'TransitionGet::ID::' . $Param{ID};
|
||||
}
|
||||
else {
|
||||
$CacheKey = 'TransitionGet::EntityID::' . $Param{EntityID};
|
||||
}
|
||||
|
||||
my $Cache = $CacheObject->Get(
|
||||
Type => 'ProcessManagement_Transition',
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if $Cache;
|
||||
|
||||
# get database object
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# sql
|
||||
if ( $Param{ID} ) {
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT id, entity_id, name, config, create_time, change_time
|
||||
FROM pm_transition
|
||||
WHERE id = ?',
|
||||
Bind => [ \$Param{ID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
}
|
||||
else {
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT id, entity_id, name, config, create_time, change_time
|
||||
FROM pm_transition
|
||||
WHERE entity_id = ?',
|
||||
Bind => [ \$Param{EntityID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
}
|
||||
|
||||
# get yaml object
|
||||
my $YAMLObject = $Kernel::OM->Get('Kernel::System::YAML');
|
||||
|
||||
my %Data;
|
||||
while ( my @Data = $DBObject->FetchrowArray() ) {
|
||||
|
||||
my $Config = $YAMLObject->Load( Data => $Data[3] );
|
||||
|
||||
%Data = (
|
||||
ID => $Data[0],
|
||||
EntityID => $Data[1],
|
||||
Name => $Data[2],
|
||||
Config => $Config,
|
||||
CreateTime => $Data[4],
|
||||
ChangeTime => $Data[5],
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
return if !$Data{ID};
|
||||
|
||||
# set cache
|
||||
$CacheObject->Set(
|
||||
Type => 'ProcessManagement_Transition',
|
||||
Key => $CacheKey,
|
||||
Value => \%Data,
|
||||
TTL => $Self->{CacheTTL},
|
||||
);
|
||||
|
||||
return \%Data;
|
||||
}
|
||||
|
||||
=head2 TransitionUpdate()
|
||||
|
||||
update Transition attributes
|
||||
|
||||
returns 1 if success or undef otherwise
|
||||
|
||||
my $Success = $TransitionObject->TransitionUpdate(
|
||||
ID => 123, # mandatory
|
||||
EntityID => 'T1' # mandatory, exportable unique identifier
|
||||
Name => 'NameOfTransition', # mandatory
|
||||
Config => $ConfigHashRef, # mandatory, transition configuration to be stored in
|
||||
# YAML format
|
||||
UserID => 123, # mandatory
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub TransitionUpdate {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Key (qw(ID EntityID Name Config UserID)) {
|
||||
if ( !$Param{$Key} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Key!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get database object
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# check if EntityID already exists
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => "
|
||||
SELECT id FROM pm_transition
|
||||
WHERE $Self->{Lower}(entity_id) = $Self->{Lower}(?)
|
||||
AND id != ?",
|
||||
Bind => [ \$Param{EntityID}, \$Param{ID} ],
|
||||
LIMIT => 1,
|
||||
);
|
||||
|
||||
my $EntityExists;
|
||||
while ( my @Data = $DBObject->FetchrowArray() ) {
|
||||
$EntityExists = 1;
|
||||
}
|
||||
|
||||
if ($EntityExists) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "The EntityID:$Param{Name} already exists for a Transition!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# check config valid format (at least it must contain the condition
|
||||
if ( !IsHashRefWithData( $Param{Config} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Config needs to be a valid Hash reference!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
for my $Needed (qw(Condition)) {
|
||||
if ( !$Param{Config}->{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed in Config!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check config formats
|
||||
if ( ref $Param{Config}->{Condition} ne 'HASH' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Config Fields must be a Hash!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# dump layout and config as string
|
||||
my $Config = $Kernel::OM->Get('Kernel::System::YAML')->Dump( Data => $Param{Config} );
|
||||
|
||||
# Make sure the resulting string has the UTF-8 flag. YAML only sets it if
|
||||
# part of the data already had it.
|
||||
utf8::upgrade($Config);
|
||||
|
||||
# check if need to update db
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT entity_id, name, config
|
||||
FROM pm_transition
|
||||
WHERE id = ?',
|
||||
Bind => [ \$Param{ID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
|
||||
my $CurrentEntityID;
|
||||
my $CurrentName;
|
||||
my $CurrentConfig;
|
||||
while ( my @Data = $DBObject->FetchrowArray() ) {
|
||||
$CurrentEntityID = $Data[0];
|
||||
$CurrentName = $Data[1];
|
||||
$CurrentConfig = $Data[2];
|
||||
}
|
||||
|
||||
if ($CurrentEntityID) {
|
||||
|
||||
return 1 if $CurrentEntityID eq $Param{EntityID}
|
||||
&& $CurrentName eq $Param{Name}
|
||||
&& $CurrentConfig eq $Config;
|
||||
}
|
||||
|
||||
# sql
|
||||
return if !$DBObject->Do(
|
||||
SQL => '
|
||||
UPDATE pm_transition
|
||||
SET entity_id = ?, name = ?, config = ?, change_time = current_timestamp,
|
||||
change_by = ?
|
||||
WHERE id = ?',
|
||||
Bind => [
|
||||
\$Param{EntityID}, \$Param{Name}, \$Config, \$Param{UserID}, \$Param{ID},
|
||||
],
|
||||
);
|
||||
|
||||
# delete cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
|
||||
Type => 'ProcessManagement_Transition',
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 TransitionList()
|
||||
|
||||
get an Transition list
|
||||
|
||||
my $List = $TransitionObject->TransitionList(
|
||||
UseEntities => 0, # default 0, 1 || 0. if 0 the return hash keys are
|
||||
# the transition IDs otherwise keys are the
|
||||
# transition entity IDs
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$List = {
|
||||
1 => 'NameOfTransition',
|
||||
}
|
||||
|
||||
or
|
||||
|
||||
$List = {
|
||||
'T1' => 'NameOfTransition',
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub TransitionList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need UserID!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# check cache
|
||||
my $UseEntities = 0;
|
||||
if ( defined $Param{UseEntities} && $Param{UseEntities} ) {
|
||||
$UseEntities = 1;
|
||||
}
|
||||
|
||||
# get cache object
|
||||
my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');
|
||||
|
||||
my $CacheKey = 'TransitionList::UseEntities::' . $UseEntities;
|
||||
my $Cache = $CacheObject->Get(
|
||||
Type => 'ProcessManagement_Transition',
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if ref $Cache;
|
||||
|
||||
# get database object
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
my $SQL = '
|
||||
SELECT id, entity_id, name
|
||||
FROM pm_transition';
|
||||
|
||||
return if !$DBObject->Prepare( SQL => $SQL );
|
||||
|
||||
my %Data;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
if ( !$UseEntities ) {
|
||||
$Data{ $Row[0] } = $Row[2];
|
||||
}
|
||||
else {
|
||||
$Data{ $Row[1] } = $Row[2];
|
||||
}
|
||||
}
|
||||
|
||||
# set cache
|
||||
$CacheObject->Set(
|
||||
Type => 'ProcessManagement_Transition',
|
||||
Key => $CacheKey,
|
||||
Value => \%Data,
|
||||
TTL => $Self->{CacheTTL},
|
||||
);
|
||||
|
||||
return \%Data;
|
||||
}
|
||||
|
||||
=head2 TransitionListGet()
|
||||
|
||||
get a Transition list with all Transition details
|
||||
|
||||
my $List = $TransitionObject->TransitionListGet(
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$List = [
|
||||
{
|
||||
ID => 123,
|
||||
EntityID => 'T1',
|
||||
Name => 'some name',
|
||||
Config => $ConfigHashRef,
|
||||
CreateTime => '2012-07-04 15:08:00',
|
||||
ChangeTime => '2012-07-04 15:08:00',
|
||||
}
|
||||
{
|
||||
ID => 456,
|
||||
EntityID => 'T2',
|
||||
Name => 'some name',
|
||||
Config => $ConfigHashRef,
|
||||
CreateTime => '2012-07-04 15:09:00',
|
||||
ChangeTime => '2012-07-04 15:09:00',
|
||||
}
|
||||
];
|
||||
|
||||
=cut
|
||||
|
||||
sub TransitionListGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need UserID!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get cache object
|
||||
my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');
|
||||
|
||||
# check cache
|
||||
my $CacheKey = 'TransitionListGet';
|
||||
|
||||
my $Cache = $CacheObject->Get(
|
||||
Type => 'ProcessManagement_Transition',
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if $Cache;
|
||||
|
||||
# get database object
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# sql
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT id, entity_id
|
||||
FROM pm_transition
|
||||
ORDER BY id',
|
||||
);
|
||||
|
||||
my @TransitionIDs;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
push @TransitionIDs, $Row[0];
|
||||
}
|
||||
|
||||
my @Data;
|
||||
for my $ItemID (@TransitionIDs) {
|
||||
|
||||
my $TransitionData = $Self->TransitionGet(
|
||||
ID => $ItemID,
|
||||
UserID => 1,
|
||||
);
|
||||
push @Data, $TransitionData;
|
||||
}
|
||||
|
||||
# set cache
|
||||
$CacheObject->Set(
|
||||
Type => 'ProcessManagement_Transition',
|
||||
Key => $CacheKey,
|
||||
Value => \@Data,
|
||||
TTL => $Self->{CacheTTL},
|
||||
);
|
||||
|
||||
return \@Data;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
688
Perl OTRS/Kernel/System/ProcessManagement/DB/TransitionAction.pm
Normal file
688
Perl OTRS/Kernel/System/ProcessManagement/DB/TransitionAction.pm
Normal file
@@ -0,0 +1,688 @@
|
||||
# --
|
||||
# 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::ProcessManagement::DB::TransitionAction;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::Cache',
|
||||
'Kernel::System::DB',
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::YAML',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::DB::TransitionAction
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Process Management DB TransitionAction backend
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $TransitionActionObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::TransitionAction');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
# get the cache TTL (in seconds)
|
||||
$Self->{CacheTTL} = int( $Kernel::OM->Get('Kernel::Config')->Get('Process::CacheTTL') || 3600 );
|
||||
|
||||
# set lower if database is case sensitive
|
||||
$Self->{Lower} = '';
|
||||
if ( $Kernel::OM->Get('Kernel::System::DB')->GetDatabaseFunction('CaseSensitive') ) {
|
||||
$Self->{Lower} = 'LOWER';
|
||||
}
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 TransitionActionAdd()
|
||||
|
||||
add new TransitionAction
|
||||
|
||||
returns the id of the created TransitionAction if success or undef otherwise
|
||||
|
||||
my $ID = $TransitionActionObject->TransitionActionAdd(
|
||||
EntityID => 'TA1' # mandatory, exportable unique identifier
|
||||
Name => 'NameOfTransitionAction', # mandatory
|
||||
Config => $ConfigHashRef, # mandatory, transition action configuration to be
|
||||
# stored in YAML format
|
||||
UserID => 123, # mandatory
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$ID = 567;
|
||||
|
||||
=cut
|
||||
|
||||
sub TransitionActionAdd {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Key (qw(EntityID Name Config UserID)) {
|
||||
if ( !$Param{$Key} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Key!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get database object
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# check if EntityID already exists
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => "
|
||||
SELECT id
|
||||
FROM pm_transition_action
|
||||
WHERE $Self->{Lower}(entity_id) = $Self->{Lower}(?)",
|
||||
Bind => [ \$Param{EntityID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
|
||||
my $EntityExists;
|
||||
while ( my @Data = $DBObject->FetchrowArray() ) {
|
||||
$EntityExists = 1;
|
||||
}
|
||||
|
||||
if ($EntityExists) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "The EntityID:$Param{EntityID} already exists for a transition action!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# check config valid format (at least it must contain another config hash inside)
|
||||
if ( !IsHashRefWithData( $Param{Config} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Config needs to be a valid Hash reference!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
for my $Needed (qw(Module Config)) {
|
||||
if ( !$Param{Config}->{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed in Config!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check config formats
|
||||
if ( !IsStringWithData( $Param{Config}->{Module} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Config Module must be a non empty String!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
if ( ref $Param{Config}->{Config} ne 'HASH' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Config Config must be a Hash!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# dump layout and config as string
|
||||
my $Config = $Kernel::OM->Get('Kernel::System::YAML')->Dump( Data => $Param{Config} );
|
||||
|
||||
# Make sure the resulting string has the UTF-8 flag. YAML only sets it if
|
||||
# part of the data already had it.
|
||||
utf8::upgrade($Config);
|
||||
|
||||
# sql
|
||||
return if !$DBObject->Do(
|
||||
SQL => '
|
||||
INSERT INTO pm_transition_action ( entity_id, name, config, create_time,
|
||||
create_by, change_time, change_by )
|
||||
VALUES (?, ?, ?, current_timestamp, ?, current_timestamp, ?)',
|
||||
Bind => [
|
||||
\$Param{EntityID}, \$Param{Name}, \$Config, \$Param{UserID}, \$Param{UserID},
|
||||
],
|
||||
);
|
||||
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => 'SELECT id FROM pm_transition_action WHERE entity_id = ?',
|
||||
Bind => [ \$Param{EntityID} ],
|
||||
);
|
||||
|
||||
my $ID;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
$ID = $Row[0];
|
||||
}
|
||||
|
||||
# delete cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
|
||||
Type => 'ProcessManagement_TransitionAction',
|
||||
);
|
||||
|
||||
return if !$ID;
|
||||
|
||||
return $ID;
|
||||
}
|
||||
|
||||
=head2 TransitionActionDelete()
|
||||
|
||||
delete an TransitionAction
|
||||
|
||||
returns 1 if success or undef otherwise
|
||||
|
||||
my $Success = $TransitionActionObject->TransitionActionDelete(
|
||||
ID => 123,
|
||||
UserID => 123,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub TransitionActionDelete {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Key (qw(ID UserID)) {
|
||||
if ( !$Param{$Key} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Key!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check if exists
|
||||
my $TransitionAction = $Self->TransitionActionGet(
|
||||
ID => $Param{ID},
|
||||
UserID => 1,
|
||||
);
|
||||
return if !IsHashRefWithData($TransitionAction);
|
||||
|
||||
# delete transition action
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => 'DELETE FROM pm_transition_action WHERE id = ?',
|
||||
Bind => [ \$Param{ID} ],
|
||||
);
|
||||
|
||||
# delete cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
|
||||
Type => 'ProcessManagement_TransitionAction',
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 TransitionActionGet()
|
||||
|
||||
get TransitionAction attributes
|
||||
|
||||
my $TransitionAction = $TransitionActionObject->TransitionActionGet(
|
||||
ID => 123, # ID or EntityID is needed
|
||||
EntityID => 'P1',
|
||||
UserID => 123, # mandatory
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$TransitionAction = {
|
||||
ID => 123,
|
||||
EntityID => 'TA1',
|
||||
Name => 'some name',
|
||||
Config => $ConfigHashRef,
|
||||
CreateTime => '2012-07-04 15:08:00',
|
||||
ChangeTime => '2012-07-04 15:08:00',
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub TransitionActionGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
if ( !$Param{ID} && !$Param{EntityID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need ID or EntityID!'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need UserID!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get cache object
|
||||
my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');
|
||||
|
||||
# check cache
|
||||
my $CacheKey;
|
||||
if ( $Param{ID} ) {
|
||||
$CacheKey = 'TransitionActionGet::ID::' . $Param{ID};
|
||||
}
|
||||
else {
|
||||
$CacheKey = 'TransitionActionGet::EntityID::' . $Param{EntityID};
|
||||
}
|
||||
|
||||
my $Cache = $CacheObject->Get(
|
||||
Type => 'ProcessManagement_TransitionAction',
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if $Cache;
|
||||
|
||||
# get database object
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# sql
|
||||
if ( $Param{ID} ) {
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT id, entity_id, name, config, create_time, change_time
|
||||
FROM pm_transition_action
|
||||
WHERE id = ?',
|
||||
Bind => [ \$Param{ID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
}
|
||||
else {
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT id, entity_id, name, config, create_time, change_time
|
||||
FROM pm_transition_action
|
||||
WHERE entity_id = ?',
|
||||
Bind => [ \$Param{EntityID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
}
|
||||
|
||||
# get yaml object
|
||||
my $YAMLObject = $Kernel::OM->Get('Kernel::System::YAML');
|
||||
|
||||
my %Data;
|
||||
while ( my @Data = $DBObject->FetchrowArray() ) {
|
||||
|
||||
my $Config = $YAMLObject->Load( Data => $Data[3] );
|
||||
|
||||
%Data = (
|
||||
ID => $Data[0],
|
||||
EntityID => $Data[1],
|
||||
Name => $Data[2],
|
||||
Config => $Config,
|
||||
CreateTime => $Data[4],
|
||||
ChangeTime => $Data[5],
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
return if !$Data{ID};
|
||||
|
||||
# set cache
|
||||
$CacheObject->Set(
|
||||
Type => 'ProcessManagement_TransitionAction',
|
||||
Key => $CacheKey,
|
||||
Value => \%Data,
|
||||
TTL => $Self->{CacheTTL},
|
||||
);
|
||||
|
||||
return \%Data;
|
||||
}
|
||||
|
||||
=head2 TransitionActionUpdate()
|
||||
|
||||
update TransitionAction attributes
|
||||
|
||||
returns 1 if success or undef otherwise
|
||||
|
||||
my $Success = $TransitionActionObject->TransitionActionUpdate(
|
||||
ID => 123, # mandatory
|
||||
EntityID => 'TA1' # mandatory, exportable unique identifier
|
||||
Name => 'NameOfTransitionAction', # mandatory
|
||||
Config => $ConfigHashRef, # mandatory, actvity dialog configuration to be
|
||||
# stored in YAML format
|
||||
UserID => 123, # mandatory
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub TransitionActionUpdate {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Key (qw(ID EntityID Name Config UserID)) {
|
||||
if ( !$Param{$Key} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Key!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get database object
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# check if EntityID already exists
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => "
|
||||
SELECT id FROM pm_transition_action
|
||||
WHERE $Self->{Lower}(entity_id) = $Self->{Lower}(?)
|
||||
AND id != ?",
|
||||
Bind => [ \$Param{EntityID}, \$Param{ID} ],
|
||||
LIMIT => 1,
|
||||
);
|
||||
|
||||
my $EntityExists;
|
||||
while ( my @Data = $DBObject->FetchrowArray() ) {
|
||||
$EntityExists = 1;
|
||||
}
|
||||
|
||||
if ($EntityExists) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "The EntityID:$Param{Name} already exists for a TransitionAction!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# check config valid format (at least it must contain another config hash)
|
||||
if ( !IsHashRefWithData( $Param{Config} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Config needs to be a valid Hash reference!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
for my $Needed (qw(Module Config)) {
|
||||
if ( !$Param{Config}->{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed in Config!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check config formats
|
||||
if ( !IsStringWithData( $Param{Config}->{Module} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Config->Config must be a non empty string!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
if ( ref $Param{Config}->{Config} ne 'HASH' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Config->Config must be a Hash!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# dump layout and config as string
|
||||
my $Config = $Kernel::OM->Get('Kernel::System::YAML')->Dump( Data => $Param{Config} );
|
||||
|
||||
# Make sure the resulting string has the UTF-8 flag. YAML only sets it if
|
||||
# part of the data already had it.
|
||||
utf8::upgrade($Config);
|
||||
|
||||
# check if need to update db
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT entity_id, name, config
|
||||
FROM pm_transition_action
|
||||
WHERE id = ?',
|
||||
Bind => [ \$Param{ID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
|
||||
my $CurrentEntityID;
|
||||
my $CurrentName;
|
||||
my $CurrentConfig;
|
||||
while ( my @Data = $DBObject->FetchrowArray() ) {
|
||||
$CurrentEntityID = $Data[0];
|
||||
$CurrentName = $Data[1];
|
||||
$CurrentConfig = $Data[2];
|
||||
}
|
||||
|
||||
if ($CurrentEntityID) {
|
||||
|
||||
return 1 if $CurrentEntityID eq $Param{EntityID}
|
||||
&& $CurrentName eq $Param{Name}
|
||||
&& $CurrentConfig eq $Config;
|
||||
}
|
||||
|
||||
# sql
|
||||
return if !$DBObject->Do(
|
||||
SQL => '
|
||||
UPDATE pm_transition_action
|
||||
SET entity_id = ?, name = ?, config = ?, change_time = current_timestamp,
|
||||
change_by = ?
|
||||
WHERE id = ?',
|
||||
Bind => [
|
||||
\$Param{EntityID}, \$Param{Name}, \$Config, \$Param{UserID}, \$Param{ID},
|
||||
],
|
||||
);
|
||||
|
||||
# delete cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
|
||||
Type => 'ProcessManagement_TransitionAction',
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 TransitionActionList()
|
||||
|
||||
get an TransitionAction list
|
||||
|
||||
my $List = $TransitionActionObject->TransitionActionList(
|
||||
UseEntities => 0, # default 0, 1 || 0. if 0 the return hash keys are
|
||||
# the transition action IDs otherwise keys are
|
||||
# the transition action entity IDs
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$List = {
|
||||
1 => 'NameOfTransitionAction',
|
||||
}
|
||||
|
||||
or
|
||||
|
||||
$List = {
|
||||
'AD1' => 'NameOfTransitionAction',
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub TransitionActionList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need UserID!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# check cache
|
||||
my $UseEntities = 0;
|
||||
if ( defined $Param{UseEntities} && $Param{UseEntities} ) {
|
||||
$UseEntities = 1;
|
||||
}
|
||||
|
||||
# get cache object
|
||||
my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');
|
||||
|
||||
my $CacheKey = 'TransitionActionList::UseEntities::' . $UseEntities;
|
||||
my $Cache = $CacheObject->Get(
|
||||
Type => 'ProcessManagement_TransitionAction',
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if ref $Cache;
|
||||
|
||||
# get database object
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
my $SQL = '
|
||||
SELECT id, entity_id, name
|
||||
FROM pm_transition_action';
|
||||
|
||||
return if !$DBObject->Prepare( SQL => $SQL );
|
||||
|
||||
my %Data;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
if ( !$UseEntities ) {
|
||||
$Data{ $Row[0] } = $Row[2];
|
||||
}
|
||||
else {
|
||||
$Data{ $Row[1] } = $Row[2];
|
||||
}
|
||||
}
|
||||
|
||||
# set cache
|
||||
$CacheObject->Set(
|
||||
Type => 'ProcessManagement_TransitionAction',
|
||||
Key => $CacheKey,
|
||||
Value => \%Data,
|
||||
TTL => $Self->{CacheTTL},
|
||||
);
|
||||
|
||||
return \%Data;
|
||||
}
|
||||
|
||||
=head2 TransitionActionListGet()
|
||||
|
||||
get an Transition Action list with all Transition Action details
|
||||
|
||||
my $List = $TransitionActionObject->TransitionActionListGet(
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$List = [
|
||||
{
|
||||
ID => 123,
|
||||
EntityID => 'TA1',
|
||||
Name => 'some name',
|
||||
Config => $ConfigHashRef,
|
||||
CreateTime => '2012-07-04 15:08:00',
|
||||
ChangeTime => '2012-07-04 15:08:00',
|
||||
}
|
||||
{
|
||||
ID => 456,
|
||||
EntityID => 'TA2',
|
||||
Name => 'some name',
|
||||
Config => $ConfigHashRef,
|
||||
CreateTime => '2012-07-04 15:09:00',
|
||||
ChangeTime => '2012-07-04 15:09:00',
|
||||
}
|
||||
];
|
||||
|
||||
=cut
|
||||
|
||||
sub TransitionActionListGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need UserID!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get cache object
|
||||
my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');
|
||||
|
||||
# check cache
|
||||
my $CacheKey = 'TransitionActionListGet';
|
||||
|
||||
my $Cache = $CacheObject->Get(
|
||||
Type => 'ProcessManagement_TransitionAction',
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if $Cache;
|
||||
|
||||
# get database object
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# sql
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT id, entity_id
|
||||
FROM pm_transition_action
|
||||
ORDER BY id',
|
||||
);
|
||||
|
||||
my @TransitionActionIDs;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
push @TransitionActionIDs, $Row[0];
|
||||
}
|
||||
|
||||
my @Data;
|
||||
for my $ItemID (@TransitionActionIDs) {
|
||||
|
||||
my $TransitionActionData = $Self->TransitionActionGet(
|
||||
ID => $ItemID,
|
||||
UserID => 1,
|
||||
);
|
||||
push @Data, $TransitionActionData;
|
||||
}
|
||||
|
||||
# set cache
|
||||
$CacheObject->Set(
|
||||
Type => 'ProcessManagement_TransitionAction',
|
||||
Key => $CacheKey,
|
||||
Value => \@Data,
|
||||
TTL => $Self->{CacheTTL},
|
||||
);
|
||||
|
||||
return \@Data;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
822
Perl OTRS/Kernel/System/ProcessManagement/Process.pm
Normal file
822
Perl OTRS/Kernel/System/ProcessManagement/Process.pm
Normal file
@@ -0,0 +1,822 @@
|
||||
# --
|
||||
# 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::ProcessManagement::Process;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::DynamicField',
|
||||
'Kernel::System::DynamicField::Backend',
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::ProcessManagement::Activity',
|
||||
'Kernel::System::ProcessManagement::ActivityDialog',
|
||||
'Kernel::System::ProcessManagement::Transition',
|
||||
'Kernel::System::ProcessManagement::TransitionAction',
|
||||
'Kernel::System::Ticket',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::Process - process lib
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
All ProcessManagement Process functions.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $ProcessObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::Process');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
# 0=off; 1=on;
|
||||
$Self->{Debug} = $Param{Debug} || 0;
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 ProcessGet()
|
||||
|
||||
Get process info
|
||||
|
||||
my $Process = $ProcessObject->ProcessGet(
|
||||
ProcessEntityID => 'P1',
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$Process = {
|
||||
'Name' => 'Process1',
|
||||
'CreateBy' => '1',
|
||||
'CreateTime' => '16-02-2012 13:37:00',
|
||||
'ChangeBy' => '1',
|
||||
'ChangeTime' => '17-02-2012 13:37:00',
|
||||
'State' => 'Active',
|
||||
'StartActivityDialog' => 'AD1',
|
||||
'StartActivity' => 'A1',
|
||||
'Path' => {
|
||||
'A2' => {
|
||||
'T3' => {
|
||||
ActivityEntityID => 'A4',
|
||||
},
|
||||
},
|
||||
'A1' => {
|
||||
'T1' => {
|
||||
ActivityEntityID => 'A2',
|
||||
},
|
||||
'T2' => {
|
||||
ActivityEntityID => 'A3',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub ProcessGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(ProcessEntityID)) {
|
||||
if ( !defined $Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $Process = $Kernel::OM->Get('Kernel::Config')->Get('Process');
|
||||
|
||||
if ( !IsHashRefWithData($Process) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need Process config!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !IsHashRefWithData( $Process->{ $Param{ProcessEntityID} } ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "No Data for Process '$Param{ProcessEntityID}' found!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
return $Process->{ $Param{ProcessEntityID} };
|
||||
}
|
||||
|
||||
=head2 ProcessList()
|
||||
|
||||
Get a list of all Processes
|
||||
|
||||
my $ProcessList = $ProcessObject->ProcessList(
|
||||
ProcessState => ['Active'], # Active, FadeAway, Inactive
|
||||
Interface => ['AgentInterface'], # optional, ['AgentInterface'] or ['CustomerInterface'] or ['AgentInterface', 'CustomerInterface'] or 'all'
|
||||
Silent => 1 # optional, 1 || 0, default 0, if set to 1 does not log errors if there are no processes configured
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$ProcessList = {
|
||||
'P1' => 'Process 1',
|
||||
'P2' => 'Process 2',
|
||||
'P3' => '',
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub ProcessList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(ProcessState)) {
|
||||
if ( !defined $Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !IsArrayRefWithData( $Param{ProcessState} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need at least one ProcessState!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
my $Processes = $Kernel::OM->Get('Kernel::Config')->Get('Process');
|
||||
if ( !IsHashRefWithData($Processes) ) {
|
||||
|
||||
if ( !$Param{Silent} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need Process config!',
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
# get only processes with the requested ProcessState(s)
|
||||
my %ProcessList;
|
||||
for my $ProcessEntityID ( sort keys %{$Processes} ) {
|
||||
if ( grep { $_ eq $Processes->{$ProcessEntityID}->{State} } @{ $Param{ProcessState} } ) {
|
||||
$ProcessList{$ProcessEntityID} = $Processes->{$ProcessEntityID}->{Name} || '';
|
||||
}
|
||||
}
|
||||
|
||||
# set Interface parameter to 'all' by default if parameter was not set
|
||||
if ( !defined $Param{Interface} ) {
|
||||
$Param{Interface} = 'all';
|
||||
}
|
||||
|
||||
# if Interface is 'all' return all processes without interface restrictions
|
||||
if ( $Param{Interface} eq 'all' ) {
|
||||
return \%ProcessList;
|
||||
}
|
||||
|
||||
# get activity dialog object
|
||||
my $ActivityDialogObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::ActivityDialog');
|
||||
|
||||
# otherwise return only processes where the initial activity dialog matches given interface
|
||||
my %ReducedProcessList;
|
||||
PROCESS:
|
||||
for my $ProcessEntityID ( sort keys %ProcessList ) {
|
||||
|
||||
# get process start point for each process we already got
|
||||
my $Start = $Self->ProcessStartpointGet( ProcessEntityID => $ProcessEntityID );
|
||||
|
||||
# skip processes if they does not have a valid start point
|
||||
next PROCESS if !IsHashRefWithData($Start);
|
||||
next PROCESS if !IsStringWithData( $Start->{ActivityDialog} );
|
||||
|
||||
# try to get the start ActivityDialog for the given interface
|
||||
my $ActivityDialog = $ActivityDialogObject->ActivityDialogGet(
|
||||
ActivityDialogEntityID => $Start->{ActivityDialog},
|
||||
Interface => $Param{Interface},
|
||||
Silent => 1,
|
||||
);
|
||||
|
||||
# skip process if first activity dialog could not be got for the given interface
|
||||
next PROCESS if !IsHashRefWithData($ActivityDialog);
|
||||
|
||||
$ReducedProcessList{$ProcessEntityID} = $ProcessList{$ProcessEntityID};
|
||||
}
|
||||
|
||||
return \%ReducedProcessList;
|
||||
}
|
||||
|
||||
=head2 ProcessStartpointGet()
|
||||
|
||||
Get process startpoint
|
||||
|
||||
my $Start = $ProcessObject->ProcessStartpointGet(
|
||||
ProcessEntityID => 'P1',
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$Start = {
|
||||
Activity => 'A1',
|
||||
ActivityDialog => 'AD1',
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub ProcessStartpointGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(ProcessEntityID)) {
|
||||
if ( !defined $Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $Process = $Self->ProcessGet( ProcessEntityID => $Param{ProcessEntityID} );
|
||||
|
||||
# include FadeAway processes so they will be listed as available processes to continue working
|
||||
# with them
|
||||
if ( $Process->{State} ne 'Active' && $Process->{State} ne 'FadeAway' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Can't get 'StartActivity' for Process '$Param{ProcessEntityID}', State"
|
||||
. " is '$Process->{State}'!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !$Process->{StartActivity} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "No 'StartActivity' for Process '$Param{ProcessEntityID}' found!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !$Process->{StartActivity} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "No 'StartActivity' for Process '$Param{ProcessEntityID}' found!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !$Process->{StartActivityDialog} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "No 'StartActivityDialog' for Process '$Param{ProcessEntityID}' found!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
return {
|
||||
Activity => $Process->{StartActivity},
|
||||
ActivityDialog => $Process->{StartActivityDialog}
|
||||
};
|
||||
}
|
||||
|
||||
=head2 ProcessTransition()
|
||||
|
||||
Check valid Transitions and Change Ticket's Activity
|
||||
if a Transition was positively checked
|
||||
|
||||
my $ProcessTransition = $ProcessObject->ProcessTransition(
|
||||
ProcessEntityID => 'P1',
|
||||
ActivityEntityID => 'A1',
|
||||
TicketID => 123,
|
||||
UserID => 123,
|
||||
CheckOnly => 1, # optional
|
||||
Data => { # optional
|
||||
Queue => 'Raw',
|
||||
DynamicField1 => 'Value',
|
||||
Subject => 'Testsubject',
|
||||
#...
|
||||
},
|
||||
);
|
||||
|
||||
Returns:
|
||||
$Success = 1; # undef # if "CheckOnly" is NOT set
|
||||
1 if Transition was executed and Ticket->ActivityEntityID updated
|
||||
undef if no Transition matched or check failed otherwise
|
||||
|
||||
$ProcessTransition = { # if option "CheckOnly" is set
|
||||
'T1' => {
|
||||
ActivityEntityID => 'A1',
|
||||
TransitionAction => [
|
||||
'TA1',
|
||||
'TA2',
|
||||
'TA3',
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub ProcessTransition {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(ProcessEntityID ActivityEntityID TicketID UserID)) {
|
||||
if ( !defined $Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my %Data;
|
||||
|
||||
# Get Ticket object
|
||||
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
|
||||
|
||||
# Get Ticket Data
|
||||
%Data = $TicketObject->TicketGet(
|
||||
TicketID => $Param{TicketID},
|
||||
DynamicFields => 1,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# Check if we got a Ticket
|
||||
if ( !IsHashRefWithData( \%Data ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Invalid TicketID: $Param{TicketID}!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# If we have Data lay it over the current %Data
|
||||
# to check Ticket + Additional Data
|
||||
if ( $Param{Data} ) {
|
||||
%Data = ( %Data, %{ $Param{Data} } );
|
||||
}
|
||||
|
||||
my $Process = $Self->ProcessGet( ProcessEntityID => $Param{ProcessEntityID} );
|
||||
|
||||
if ( !$Process->{State} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Can't process Transition for Process '$Param{ProcessEntityID}', can't"
|
||||
. " get State out of the config!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $Process->{State} eq 'Inactive' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Can't process Transition for Process '$Param{ProcessEntityID}',"
|
||||
. " ProcessState is '$Process->{State}'!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# We need the Processes Config
|
||||
# and the Config for the process the Ticket is in
|
||||
# and the Process has to have the 'Path' Hash set
|
||||
if (
|
||||
!IsHashRefWithData($Process)
|
||||
|| !IsHashRefWithData( $Process->{Path} )
|
||||
)
|
||||
{
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need Path for ProcessEntityID $Param{ProcessEntityID}!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# Check if our ActivitySet has a path configured
|
||||
# if it hasn't we got nothing to do -> print debuglog if desired and return
|
||||
if ( !IsHashRefWithData( $Process->{Path}->{ $Param{ActivityEntityID} } ) ) {
|
||||
if ( $Self->{Debug} > 0 ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'debug',
|
||||
Message => 'No Path configured for Process with ID: '
|
||||
. "$Param{ProcessEntityID} and ActivityEntityID: $Param{ActivityEntityID}!",
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
# %Transitions Hash for easier reading
|
||||
# contains all possible Transitions for the current Activity
|
||||
my %Transitions = %{ $Process->{Path}->{ $Param{ActivityEntityID} } };
|
||||
|
||||
# get transition object
|
||||
my $TransitionObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::Transition');
|
||||
|
||||
# Handle all possible TransitionEntityID's for the Process->Path's->ActivityEntityID down to
|
||||
# Transition.pm's TransitionCheck for validation
|
||||
# will return undef if nothing matched or the first matching TransitionEntityID
|
||||
my $TransitionEntityID = $TransitionObject->TransitionCheck(
|
||||
TransitionEntityID => [ sort { $a cmp $b } keys %Transitions ],
|
||||
Data => \%Data,
|
||||
);
|
||||
|
||||
# if we didn't get a TransitionEntityID
|
||||
# no check was successful -> return nothing
|
||||
if ( !$TransitionEntityID || !length $TransitionEntityID ) {
|
||||
if ( $Self->{Debug} > 0 ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'debug',
|
||||
Message => 'No Transition matched for TicketID: '
|
||||
. "$Param{TicketID} ProcessEntityID: $Param{ProcessEntityID} "
|
||||
. "ActivityEntityID: $Param{ActivityEntityID}!",
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
# get activity object
|
||||
my $ActivityObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::Activity');
|
||||
|
||||
# If we have a Transition without valid FutureActivitySet we have to complain
|
||||
if (
|
||||
!IsHashRefWithData( $Transitions{$TransitionEntityID} )
|
||||
|| !$Transitions{$TransitionEntityID}->{ActivityEntityID}
|
||||
|| !IsHashRefWithData(
|
||||
$ActivityObject->ActivityGet(
|
||||
Interface => 'all',
|
||||
ActivityEntityID => $Transitions{$TransitionEntityID}->{ActivityEntityID}
|
||||
)
|
||||
)
|
||||
)
|
||||
{
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need Target Activity for Process with "
|
||||
. "ProcessEntityID: $Param{ProcessEntityID} ActivityEntityID:"
|
||||
. " $Param{ActivityEntityID} TransitionEntityID: $TransitionEntityID!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# If we should just check what Transition matched
|
||||
# return a hash containing
|
||||
# { TransitionEntityID => FutureActivityEntityID }
|
||||
if ( $Param{CheckOnly} ) {
|
||||
if ( $Self->{Debug} > 0 ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'debug',
|
||||
Message => "Transition with ID $TransitionEntityID matched for "
|
||||
. "TicketID: $Param{TicketID} ProcessEntityID: $Param{ProcessEntityID} "
|
||||
. "ActivityEntityID: $Param{ActivityEntityID}!",
|
||||
);
|
||||
}
|
||||
return { $TransitionEntityID => $Transitions{$TransitionEntityID} };
|
||||
}
|
||||
|
||||
# Set the new ActivityEntityID on the Ticket
|
||||
my $Success = $Self->ProcessTicketActivitySet(
|
||||
ProcessEntityID => $Param{ProcessEntityID},
|
||||
ActivityEntityID => $Transitions{$TransitionEntityID}->{ActivityEntityID},
|
||||
TicketID => $Param{TicketID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Failed setting ActivityEntityID of Ticket: $Param{TicketID} to "
|
||||
. $Transitions{$TransitionEntityID}->{ActivityEntityID}
|
||||
. " after successful Transition: $TransitionEntityID!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# if we don't have Transition Actions on that transition,
|
||||
# return 1 for successful transition
|
||||
if (
|
||||
!$Transitions{$TransitionEntityID}->{TransitionAction}
|
||||
|| (
|
||||
ref $Transitions{$TransitionEntityID}->{TransitionAction} eq 'ARRAY'
|
||||
&& !@{ $Transitions{$TransitionEntityID}->{TransitionAction} }
|
||||
)
|
||||
)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
# if we have Transition Action and it isn't an array return
|
||||
if ( !IsArrayRefWithData( $Transitions{$TransitionEntityID}->{TransitionAction} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Defective Process configuration: 'TrasitionAction' must be an array in "
|
||||
. "Process: $Param{ProcessEntityID} -> Path -> "
|
||||
. "ActivityEntityID: $Param{ActivityEntityID} -> Transition: $TransitionEntityID!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get transition action object
|
||||
my $TransitionActionObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::TransitionAction');
|
||||
|
||||
my $TransitionActions = $TransitionActionObject->TransitionActionList(
|
||||
TransitionActionEntityID => $Transitions{$TransitionEntityID}->{TransitionAction},
|
||||
);
|
||||
|
||||
if ( !IsArrayRefWithData($TransitionActions) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Getting TransitionActionList for Process: $Param{ProcessEntityID},"
|
||||
. " Transition: $TransitionEntityID failed.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
for my $TransitionAction ( @{$TransitionActions} ) {
|
||||
|
||||
# Refresh ticket data, as transition actions could already had modified the ticket
|
||||
# e.g TicketServiceSet -> TicketSLASet, SLA needs to already have a Service,
|
||||
# see bug#12147.
|
||||
%Data = $TicketObject->TicketGet(
|
||||
TicketID => $Param{TicketID},
|
||||
DynamicFields => 1,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
my $TransitionActionModuleObject = $TransitionAction->{Module}->new();
|
||||
|
||||
# Transition actions could replace configuration tags with actual ticket values,
|
||||
# copying the configuration prevents unwanted results if same Transition action is called
|
||||
# for multiple tickets, see bug#12179
|
||||
my %Config = %{ $TransitionAction->{Config} || {} };
|
||||
|
||||
my $Success = $TransitionActionModuleObject->Run(
|
||||
UserID => $Param{UserID},
|
||||
Ticket => \%Data,
|
||||
ProcessEntityID => $Param{ProcessEntityID},
|
||||
ActivityEntityID => $Param{ActivityEntityID},
|
||||
TransitionEntityID => $TransitionEntityID,
|
||||
TransitionActionEntityID => $TransitionAction->{TransitionActionEntityID},
|
||||
Config => \%Config,
|
||||
);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
=head2 ProcessTicketActivitySet()
|
||||
|
||||
Set Ticket's ActivityEntityID
|
||||
|
||||
my $Success = $ProcessObject->ProcessTicketActivitySet(
|
||||
ProcessEntityID => 'P1',
|
||||
ActivityEntityID => 'A1',
|
||||
TicketID => 123,
|
||||
UserID => 123,
|
||||
);
|
||||
|
||||
Returns:
|
||||
$Success = 1; # undef
|
||||
1 if setting the Activity was executed
|
||||
undef if setting failed
|
||||
|
||||
=cut
|
||||
|
||||
sub ProcessTicketActivitySet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(ProcessEntityID ActivityEntityID TicketID UserID)) {
|
||||
if ( !defined $Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get activity object
|
||||
my $ActivityObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::Activity');
|
||||
|
||||
# check on valid ActivityEntityID
|
||||
my $Success = $ActivityObject->ActivityGet(
|
||||
Interface => 'all',
|
||||
ActivityEntityID => $Param{ActivityEntityID},
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Process->ProcessTicketActivitySet called on "
|
||||
. "non existing ActivityEntityID: $Param{ActivityEntityID}!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# Check on valid State
|
||||
my $Process = $Self->ProcessGet( ProcessEntityID => $Param{ProcessEntityID} );
|
||||
|
||||
if ( !$Process->{State} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Can't set ActivitySet for Process '$Param{ProcessEntityID}', cat get"
|
||||
. " State out of the config!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $Process->{State} eq 'Inactive' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Can't set ActivitySet for Process '$Param{ProcessEntityID}', State is"
|
||||
. " '$Process->{State}'!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# Get DynamicField Name that's used for storing the ActivityEntityID per ticket
|
||||
my $DynamicFieldTicketActivityEntityID
|
||||
= $Kernel::OM->Get('Kernel::Config')->Get('Process::DynamicFieldProcessManagementActivityID');
|
||||
if ( !$DynamicFieldTicketActivityEntityID ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need DynamicFieldProcessManagementActivityID config "
|
||||
. "for storing of ActivityEntityID on TicketID: $Param{TicketID}!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get dynamic field objects
|
||||
my $DynamicFieldObject = $Kernel::OM->Get('Kernel::System::DynamicField');
|
||||
my $DynamicFieldBackendObject = $Kernel::OM->Get('Kernel::System::DynamicField::Backend');
|
||||
|
||||
# get the dynamic fields for this screen
|
||||
my $DynamicFieldList = $DynamicFieldObject->DynamicFieldListGet(
|
||||
Valid => 1,
|
||||
ObjectType => 'Ticket',
|
||||
);
|
||||
|
||||
# Grep the Field out of the config of all Ticket DynamicFields
|
||||
my @DynamicFieldConfig = grep { $_->{Name} eq $DynamicFieldTicketActivityEntityID } @{$DynamicFieldList};
|
||||
|
||||
# if the DynamicField isn't there, return 0 and log
|
||||
if ( !IsHashRefWithData( $DynamicFieldConfig[0] ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "DynamicField: $DynamicFieldTicketActivityEntityID not configured!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# If Ticket Update to the new ActivityEntityID was successful return 1
|
||||
if (
|
||||
$DynamicFieldBackendObject->ValueSet(
|
||||
DynamicFieldConfig => $DynamicFieldConfig[0],
|
||||
ObjectID => $Param{TicketID},
|
||||
Value => $Param{ActivityEntityID},
|
||||
UserID => $Param{UserID}
|
||||
)
|
||||
)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
=head2 ProcessTicketProcessSet()
|
||||
|
||||
Set Ticket's ProcessEntityID
|
||||
|
||||
my $Success = $ProcessObject->ProcessTicketProcessSet(
|
||||
ProcessEntityID => 'P1',
|
||||
TicketID => 123,
|
||||
UserID => 123,
|
||||
);
|
||||
|
||||
Returns:
|
||||
$Success = 1; # undef
|
||||
1 if setting the Activity was executed
|
||||
undef if setting failed
|
||||
|
||||
=cut
|
||||
|
||||
sub ProcessTicketProcessSet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(ProcessEntityID TicketID UserID)) {
|
||||
if ( !defined $Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# Check on valid ProcessEntityID
|
||||
my $Process = $Self->ProcessGet( ProcessEntityID => $Param{ProcessEntityID} );
|
||||
|
||||
if ( !$Process->{State} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Can't set Process '$Param{ProcessEntityID}' for TicketID"
|
||||
. " '$Param{TicketID}', cat get State out of the config!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $Process->{State} ne 'Active' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Can't set Process '$Param{ProcessEntityID}' for TicketID"
|
||||
. " '$Param{TicketID}', State is '$Process->{State}'!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# Get DynamicField Name that's used for storing the ActivityEntityID per ticket
|
||||
my $DynamicFieldTicketProcessID
|
||||
= $Kernel::OM->Get('Kernel::Config')->Get('Process::DynamicFieldProcessManagementProcessID');
|
||||
|
||||
if ( !$DynamicFieldTicketProcessID ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need DynamicFieldProcessManagementProcessID config "
|
||||
. "for storing of ProcesID on TicketID: $Param{TicketID}!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get dynamic field objects
|
||||
my $DynamicFieldObject = $Kernel::OM->Get('Kernel::System::DynamicField');
|
||||
my $DynamicFieldBackendObject = $Kernel::OM->Get('Kernel::System::DynamicField::Backend');
|
||||
|
||||
# get the dynamic fields for this screen
|
||||
my $DynamicFieldList = $DynamicFieldObject->DynamicFieldListGet(
|
||||
Valid => 1,
|
||||
ObjectType => 'Ticket',
|
||||
);
|
||||
|
||||
# Grep the Field out of the config of all Ticket DynamicFields
|
||||
my @DynamicFieldConfig = grep { $_->{Name} eq $DynamicFieldTicketProcessID } @{$DynamicFieldList};
|
||||
|
||||
# if the DynamicField isn't there, return 0 and log
|
||||
if ( !IsHashRefWithData( $DynamicFieldConfig[0] ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "DynamicField: $DynamicFieldTicketProcessID not configured!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# If Ticket Update to the new ActivityEntityID was successful return 1
|
||||
if (
|
||||
$DynamicFieldBackendObject->ValueSet(
|
||||
DynamicFieldConfig => $DynamicFieldConfig[0],
|
||||
ObjectID => $Param{TicketID},
|
||||
Value => $Param{ProcessEntityID},
|
||||
UserID => $Param{UserID},
|
||||
)
|
||||
)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
1100
Perl OTRS/Kernel/System/ProcessManagement/Transition.pm
Normal file
1100
Perl OTRS/Kernel/System/ProcessManagement/Transition.pm
Normal file
File diff suppressed because it is too large
Load Diff
246
Perl OTRS/Kernel/System/ProcessManagement/TransitionAction.pm
Normal file
246
Perl OTRS/Kernel/System/ProcessManagement/TransitionAction.pm
Normal file
@@ -0,0 +1,246 @@
|
||||
# --
|
||||
# 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::ProcessManagement::TransitionAction;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::Main',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::TransitionAction - action lib
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
All Process Management Transition Action functions.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $TransitionActionObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::TransitionAction');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 TransitionActionGet()
|
||||
|
||||
Get transition action info
|
||||
|
||||
my $TransitionAction = $TransitionActionObject->TransitionActionGet(
|
||||
TransitionActionEntityID => 'TA1',
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$TransitionAction = {
|
||||
'Name' => 'TransitionAction 1'
|
||||
'CreateBy' => '2',
|
||||
'CreateTime' => '07-02-2012 13:37:00',
|
||||
'ChangeBy' => '3',
|
||||
'ChangeTime' => '08-02-2012 13:37:00',
|
||||
'Module' => 'Kernel::System::ProcessManagement::TransitionAction::QueueMove',
|
||||
'Config' => {
|
||||
# Config hash including all parameters
|
||||
# that can submitted to that module
|
||||
},
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub TransitionActionGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(TransitionActionEntityID)) {
|
||||
if ( !defined $Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $TransitionAction = $Kernel::OM->Get('Kernel::Config')->Get('Process::TransitionAction');
|
||||
|
||||
if ( !IsHashRefWithData($TransitionAction) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need TransitionAction config!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !IsHashRefWithData( $TransitionAction->{ $Param{TransitionActionEntityID} } ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "No Data for TransitionAction '$Param{TransitionActionEntityID}' found!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
!$TransitionAction->{ $Param{TransitionActionEntityID} }->{Module}
|
||||
|| !$Kernel::OM->Get('Kernel::System::Main')->Require(
|
||||
$TransitionAction->{ $Param{TransitionActionEntityID} }->{Module}
|
||||
)
|
||||
)
|
||||
{
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Module for TransitionAction: $Param{TransitionActionEntityID} missing or"
|
||||
. " not found!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
return $TransitionAction->{ $Param{TransitionActionEntityID} };
|
||||
}
|
||||
|
||||
=head2 TransitionActionList()
|
||||
|
||||
Get action config for dedicated TransitionActionEntityIDs
|
||||
|
||||
my $TransitionActionList = $TransitionActionObject->TransitionActionList(
|
||||
TransitionActionEntityID => ['TA1', 'TA2', 'TA3',],
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$TransitionActions = [
|
||||
{
|
||||
'TransitionActionEntityID' => 'TA1',
|
||||
'Name' => 'TransitionAction1'
|
||||
'CreateBy' => '2',
|
||||
'ChangeBy' => '3',
|
||||
'CreateTime' => '25-04-2012 13:37:00',
|
||||
'ChangeTime' => '24-04-2012 13:37:00',
|
||||
'Module' => 'Kernel::System::ProcessManagement::TransitionAction::QueueMove',
|
||||
'Config' => {
|
||||
# Config hash including all parameters
|
||||
# that can submitted to that module
|
||||
},
|
||||
},
|
||||
{
|
||||
'TransitionActionEntityID' => 'TA2',
|
||||
'Name' => 'TransitionAction2'
|
||||
'CreateBy' => '2',
|
||||
'ChangeBy' => '3',
|
||||
'CreateTime' => '25-04-2012 13:37:00',
|
||||
'ChangeTime' => '24-04-2012 13:37:00',
|
||||
'Module' => 'Kernel::System::ProcessManagement::TransitionAction::StatusUpdate',
|
||||
'Config' => {
|
||||
# Config hash including all parameters
|
||||
# that can submitted to that module
|
||||
},
|
||||
},
|
||||
{
|
||||
'TransitionActionEntityID' => 'TA3',
|
||||
'Name' => 'TransitionAction3'
|
||||
'CreateBy' => '2',
|
||||
'ChangeBy' => '3',
|
||||
'CreateTime' => '25-04-2012 13:37:00',
|
||||
'ChangeTime' => '24-04-2012 13:37:00',
|
||||
'Module' => 'Kernel::System::ProcessManagement::TransitionAction::NotifyOwner',
|
||||
'Config' => {
|
||||
# Config hash including all parameters
|
||||
# that can submitted to that module
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
=cut
|
||||
|
||||
sub TransitionActionList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(TransitionActionEntityID)) {
|
||||
if ( !defined $Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !IsArrayRefWithData( $Param{TransitionActionEntityID} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'No TransitionActionEntityID Array submitted calling TransitionActionList!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
my $TransitionAction = $Kernel::OM->Get('Kernel::Config')->Get('Process::TransitionAction');
|
||||
|
||||
my $TransitionActionConfigs;
|
||||
for my $TransitionActionEntityID ( @{ $Param{TransitionActionEntityID} } ) {
|
||||
if ( !IsHashRefWithData( $TransitionAction->{$TransitionActionEntityID} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "No Data for TransitionAction '$TransitionActionEntityID'"
|
||||
. " found!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
!$TransitionAction->{$TransitionActionEntityID}->{Module}
|
||||
|| !$Kernel::OM->Get('Kernel::System::Main')->Require(
|
||||
$TransitionAction->{$TransitionActionEntityID}->{Module}
|
||||
)
|
||||
)
|
||||
{
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Module for TransitionAction: $TransitionActionEntityID"
|
||||
. " missing or not found!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
push @{$TransitionActionConfigs}, {
|
||||
TransitionActionEntityID => $TransitionActionEntityID,
|
||||
%{ $TransitionAction->{$TransitionActionEntityID} },
|
||||
};
|
||||
}
|
||||
|
||||
return $TransitionActionConfigs;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,356 @@
|
||||
# --
|
||||
# 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::ProcessManagement::TransitionAction::Base;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use utf8;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::DynamicField',
|
||||
'Kernel::System::DynamicField::Backend',
|
||||
'Kernel::System::Encode',
|
||||
'Kernel::System::HTMLUtils',
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::TemplateGenerator',
|
||||
'Kernel::System::Ticket::Article',
|
||||
'Kernel::System::User',
|
||||
);
|
||||
|
||||
sub _CheckParams {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $CommonMessage = $Param{CommonMessage};
|
||||
|
||||
for my $Needed (
|
||||
qw(UserID Ticket ProcessEntityID ActivityEntityID TransitionEntityID
|
||||
TransitionActionEntityID Config
|
||||
)
|
||||
)
|
||||
{
|
||||
if ( !defined $Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# Check if we have Ticket to deal with
|
||||
if ( !IsHashRefWithData( $Param{Ticket} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage . "Ticket has no values!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# Check if we have a ConfigHash
|
||||
if ( !IsHashRefWithData( $Param{Config} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage . "Config has no values!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub _OverrideUserID {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( IsNumber( $Param{Config}->{UserID} ) ) {
|
||||
$Param{UserID} = $Param{Config}->{UserID};
|
||||
delete $Param{Config}->{UserID};
|
||||
}
|
||||
|
||||
return $Param{UserID};
|
||||
}
|
||||
|
||||
sub _ReplaceTicketAttributes {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# get needed objects
|
||||
my $DynamicFieldObject = $Kernel::OM->Get('Kernel::System::DynamicField');
|
||||
my $DynamicFieldBackendObject = $Kernel::OM->Get('Kernel::System::DynamicField::Backend');
|
||||
|
||||
for my $Attribute ( sort keys %{ $Param{Config} } ) {
|
||||
|
||||
# Replace ticket attributes such as
|
||||
# <OTRS_Ticket_DynamicField_Name1> or <OTRS_TICKET_DynamicField_Name1>
|
||||
# or
|
||||
# <OTRS_TICKET_DynamicField_Name1_Value> or <OTRS_Ticket_DynamicField_Name1_Value>.
|
||||
# <OTRS_Ticket_*> is deprecated and should be removed in further versions of OTRS.
|
||||
my $Count = 0;
|
||||
REPLACEMENT:
|
||||
while (
|
||||
$Param{Config}->{$Attribute}
|
||||
&& $Param{Config}->{$Attribute} =~ m{<OTRS_TICKET_([A-Za-z0-9_]+)>}msxi
|
||||
&& $Count++ < 1000
|
||||
)
|
||||
{
|
||||
my $TicketAttribute = $1;
|
||||
|
||||
if ( $TicketAttribute =~ m{DynamicField_(\S+?)_Value} ) {
|
||||
my $DynamicFieldName = $1;
|
||||
|
||||
my $DynamicFieldConfig = $DynamicFieldObject->DynamicFieldGet(
|
||||
Name => $DynamicFieldName,
|
||||
);
|
||||
next REPLACEMENT if !$DynamicFieldConfig;
|
||||
|
||||
# Get the display value for each dynamic field.
|
||||
my $DisplayValue = $DynamicFieldBackendObject->ValueLookup(
|
||||
DynamicFieldConfig => $DynamicFieldConfig,
|
||||
Key => $Param{Ticket}->{"DynamicField_$DynamicFieldName"},
|
||||
);
|
||||
|
||||
my $DisplayValueStrg = $DynamicFieldBackendObject->ReadableValueRender(
|
||||
DynamicFieldConfig => $DynamicFieldConfig,
|
||||
Value => $DisplayValue,
|
||||
);
|
||||
|
||||
$Param{Config}->{$Attribute}
|
||||
=~ s{<OTRS_TICKET_$TicketAttribute>}{$DisplayValueStrg->{Value} // ''}ige;
|
||||
|
||||
next REPLACEMENT;
|
||||
}
|
||||
elsif ( $TicketAttribute =~ m{DynamicField_(\S+)} ) {
|
||||
my $DynamicFieldName = $1;
|
||||
|
||||
my $DynamicFieldConfig = $DynamicFieldObject->DynamicFieldGet(
|
||||
Name => $DynamicFieldName,
|
||||
);
|
||||
next REPLACEMENT if !$DynamicFieldConfig;
|
||||
|
||||
# Get the readable value (key) for each dynamic field.
|
||||
my $ValueStrg = $DynamicFieldBackendObject->ReadableValueRender(
|
||||
DynamicFieldConfig => $DynamicFieldConfig,
|
||||
Value => $Param{Ticket}->{"DynamicField_$DynamicFieldName"},
|
||||
);
|
||||
|
||||
$Param{Config}->{$Attribute}
|
||||
=~ s{<OTRS_TICKET_$TicketAttribute>}{$ValueStrg->{Value} // ''}ige;
|
||||
|
||||
next REPLACEMENT;
|
||||
}
|
||||
|
||||
# if ticket value is scalar substitute all instances (as strings)
|
||||
# this will allow replacements for "<OTRS_TICKET_Title> <OTRS_TICKET_Queue"
|
||||
if ( !ref $Param{Ticket}->{$TicketAttribute} ) {
|
||||
$Param{Config}->{$Attribute}
|
||||
=~ s{<OTRS_TICKET_$TicketAttribute>}{$Param{Ticket}->{$TicketAttribute} // ''}ige;
|
||||
}
|
||||
else {
|
||||
|
||||
# if the vale is an array (e.g. a multiselect dynamic field) set the value directly
|
||||
# this unfortunately will not let a combination of values to be replaced
|
||||
$Param{Config}->{$Attribute} = $Param{Ticket}->{$TicketAttribute};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub _ReplaceAdditionalAttributes {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# get system default language
|
||||
my %User;
|
||||
if ( $Param{UserID} ) {
|
||||
%User = $Kernel::OM->Get('Kernel::System::User')->GetUserData(
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
|
||||
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
|
||||
my $DefaultLanguage = $ConfigObject->Get('DefaultLanguage') || 'en';
|
||||
my $Language = $User{UserLanguage} || $DefaultLanguage;
|
||||
|
||||
# get and store richtext information
|
||||
my $RichText = $ConfigObject->Get('Frontend::RichText');
|
||||
|
||||
# Determine if RichText (text/html) is used in the config as well.
|
||||
# If not, we have to deactivate it, otherwise HTML content and plain text are mixed up (see bug#13764).
|
||||
if ($RichText) {
|
||||
|
||||
# Check for ContentType or MimeType.
|
||||
if (
|
||||
( IsStringWithData( $Param{Config}->{ContentType} ) && $Param{Config}->{ContentType} !~ m{text/html}i )
|
||||
|| ( IsStringWithData( $Param{Config}->{MimeType} ) && $Param{Config}->{MimeType} !~ m{text/html}i )
|
||||
)
|
||||
{
|
||||
$RichText = 0;
|
||||
}
|
||||
}
|
||||
|
||||
my $ArticleObject = $Kernel::OM->Get('Kernel::System::Ticket::Article');
|
||||
|
||||
# get last customer article
|
||||
my @ArticleListCustomer = $ArticleObject->ArticleList(
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
SenderType => 'customer',
|
||||
OnlyLast => 1,
|
||||
);
|
||||
|
||||
my %ArticleCustomer;
|
||||
if (@ArticleListCustomer) {
|
||||
%ArticleCustomer = $ArticleObject->BackendForArticle( %{ $ArticleListCustomer[0] } )->ArticleGet(
|
||||
%{ $ArticleListCustomer[0] },
|
||||
DynamicFields => 0,
|
||||
);
|
||||
}
|
||||
|
||||
# get last agent article
|
||||
my @ArticleListAgent = $ArticleObject->ArticleList(
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
SenderType => 'agent',
|
||||
OnlyLast => 1,
|
||||
);
|
||||
|
||||
my %ArticleAgent;
|
||||
if (@ArticleListAgent) {
|
||||
%ArticleAgent = $ArticleObject->BackendForArticle( %{ $ArticleListAgent[0] } )->ArticleGet(
|
||||
%{ $ArticleListAgent[0] },
|
||||
DynamicFields => 0,
|
||||
);
|
||||
}
|
||||
|
||||
my $HTMLUtilsObject = $Kernel::OM->Get('Kernel::System::HTMLUtils');
|
||||
|
||||
# set the accounted time as part of the article information
|
||||
ARTICLEDATA:
|
||||
for my $ArticleData ( \%ArticleCustomer, \%ArticleAgent ) {
|
||||
|
||||
next ARTICLEDATA if !$ArticleData->{ArticleID};
|
||||
|
||||
my $AccountedTime = $ArticleObject->ArticleAccountedTimeGet(
|
||||
ArticleID => $ArticleData->{ArticleID},
|
||||
);
|
||||
|
||||
$ArticleData->{TimeUnit} = $AccountedTime;
|
||||
|
||||
my $ArticleBackendObject = $ArticleObject->BackendForArticle(
|
||||
ArticleID => $ArticleData->{ArticleID},
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
);
|
||||
|
||||
# get richtext body for customer and agent article
|
||||
if ($RichText) {
|
||||
|
||||
# check if there are HTML body attachments
|
||||
my %AttachmentIndexHTMLBody = $ArticleBackendObject->ArticleAttachmentIndex(
|
||||
ArticleID => $ArticleData->{ArticleID},
|
||||
OnlyHTMLBody => 1,
|
||||
);
|
||||
|
||||
my @HTMLBodyAttachmentIDs = sort keys %AttachmentIndexHTMLBody;
|
||||
|
||||
if ( $HTMLBodyAttachmentIDs[0] ) {
|
||||
|
||||
my %AttachmentHTML = $ArticleBackendObject->ArticleAttachment(
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
ArticleID => $ArticleData->{ArticleID},
|
||||
FileID => $HTMLBodyAttachmentIDs[0],
|
||||
);
|
||||
|
||||
my $Charset = $AttachmentHTML{ContentType} || '';
|
||||
$Charset =~ s/.+?charset=("|'|)(\w+)/$2/gi;
|
||||
$Charset =~ s/"|'//g;
|
||||
$Charset =~ s/(.+?);.*/$1/g;
|
||||
|
||||
# convert html body to correct charset
|
||||
my $Body = $Kernel::OM->Get('Kernel::System::Encode')->Convert(
|
||||
Text => $AttachmentHTML{Content},
|
||||
From => $Charset,
|
||||
To => 'utf-8',
|
||||
Check => 1,
|
||||
);
|
||||
|
||||
$Body = $HTMLUtilsObject->LinkQuote(
|
||||
String => $Body,
|
||||
);
|
||||
|
||||
$Body = $HTMLUtilsObject->DocumentStrip(
|
||||
String => $Body,
|
||||
);
|
||||
|
||||
$ArticleData->{Body} = $Body;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my $TemplateGeneratorObject = $Kernel::OM->Get('Kernel::System::TemplateGenerator');
|
||||
|
||||
# start replacing of OTRS smart tags
|
||||
for my $Attribute ( sort keys %{ $Param{Config} } ) {
|
||||
|
||||
my $ConfigValue = $Param{Config}->{$Attribute};
|
||||
|
||||
if ( $ConfigValue && $ConfigValue =~ m{<OTRS_[A-Za-z0-9_]+(?:\[(?:.+?)\])?>}smxi ) {
|
||||
|
||||
if ($RichText) {
|
||||
$ConfigValue = $HTMLUtilsObject->ToHTML(
|
||||
String => $ConfigValue,
|
||||
);
|
||||
}
|
||||
|
||||
$ConfigValue = $TemplateGeneratorObject->_Replace(
|
||||
RichText => $RichText,
|
||||
Text => $ConfigValue,
|
||||
Data => \%ArticleCustomer,
|
||||
DataAgent => \%ArticleAgent,
|
||||
TicketData => $Param{Ticket},
|
||||
UserID => $Param{UserID},
|
||||
Language => $Language,
|
||||
);
|
||||
|
||||
if ($RichText) {
|
||||
$ConfigValue = $HTMLUtilsObject->ToAscii(
|
||||
String => $ConfigValue,
|
||||
);
|
||||
|
||||
# For body, create a completed html doc for correct displaying.
|
||||
if ( $Attribute eq 'Body' ) {
|
||||
$ConfigValue = $HTMLUtilsObject->DocumentComplete(
|
||||
String => $ConfigValue,
|
||||
Charset => 'utf-8',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$Param{Config}->{$Attribute} = $ConfigValue;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub _ConvertScalar2ArrayRef {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my @Data = split /,/, $Param{Data};
|
||||
|
||||
# remove any possible heading and tailing white spaces
|
||||
for my $Item (@Data) {
|
||||
$Item =~ s{\A\s+}{};
|
||||
$Item =~ s{\s+\z}{};
|
||||
}
|
||||
|
||||
return \@Data;
|
||||
}
|
||||
|
||||
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::ProcessManagement::TransitionAction::DynamicFieldSet;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::ProcessManagement::TransitionAction::Base);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::DynamicField',
|
||||
'Kernel::System::DynamicField::Backend',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::TransitionAction::DynamicFieldSet - A module to set a new ticket owner
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
All DynamicFieldSet functions.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $DynamicFieldSetObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::TransitionAction::DynamicFieldSet');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Run()
|
||||
|
||||
Run Data
|
||||
|
||||
my $DynamicFieldSetResult = $DynamicFieldSetActionObject->Run(
|
||||
UserID => 123,
|
||||
Ticket => \%Ticket, # required
|
||||
ProcessEntityID => 'P123',
|
||||
ActivityEntityID => 'A123',
|
||||
TransitionEntityID => 'T123',
|
||||
TransitionActionEntityID => 'TA123',
|
||||
Config => {
|
||||
MasterSlave => 'Master',
|
||||
Approved => '1',
|
||||
UserID => 123, # optional, to override the UserID from the logged user
|
||||
}
|
||||
);
|
||||
Ticket contains the result of TicketGet including DynamicFields
|
||||
Config is the Config Hash stored in a Process::TransitionAction's Config key
|
||||
|
||||
If a Dynamic Field is named UserID (to avoid conflicts) it must be set in the config as:
|
||||
DynamicField_UserID => $Value,
|
||||
|
||||
Returns:
|
||||
|
||||
$DynamicFieldSetResult = 1; # 0
|
||||
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# define a common message to output in case of any error
|
||||
my $CommonMessage = "Process: $Param{ProcessEntityID} Activity: $Param{ActivityEntityID}"
|
||||
. " Transition: $Param{TransitionEntityID}"
|
||||
. " TransitionAction: $Param{TransitionActionEntityID} - ";
|
||||
|
||||
# check for missing or wrong params
|
||||
my $Success = $Self->_CheckParams(
|
||||
%Param,
|
||||
CommonMessage => $CommonMessage,
|
||||
);
|
||||
return if !$Success;
|
||||
|
||||
# override UserID if specified as a parameter in the TA config
|
||||
$Param{UserID} = $Self->_OverrideUserID(%Param);
|
||||
|
||||
# special case for DyanmicField UserID, convert form DynamicField_UserID to UserID
|
||||
if ( defined $Param{Config}->{DynamicField_UserID} ) {
|
||||
$Param{Config}->{UserID} = $Param{Config}->{DynamicField_UserID};
|
||||
delete $Param{Config}->{DynamicField_UserID};
|
||||
}
|
||||
|
||||
# use ticket attributes if needed
|
||||
$Self->_ReplaceTicketAttributes(%Param);
|
||||
$Self->_ReplaceAdditionalAttributes(%Param);
|
||||
|
||||
# get dynamic field objects
|
||||
my $DynamicFieldObject = $Kernel::OM->Get('Kernel::System::DynamicField');
|
||||
my $DynamicFieldBackendObject = $Kernel::OM->Get('Kernel::System::DynamicField::Backend');
|
||||
|
||||
for my $CurrentDynamicField ( sort keys %{ $Param{Config} } ) {
|
||||
|
||||
# get required DynamicField config
|
||||
my $DynamicFieldConfig = $DynamicFieldObject->DynamicFieldGet(
|
||||
Name => $CurrentDynamicField,
|
||||
);
|
||||
|
||||
# check if we have a valid DynamicField
|
||||
if ( !IsHashRefWithData($DynamicFieldConfig) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. "Can't get DynamicField config for DynamicField: '$CurrentDynamicField'!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# try to set the configured value
|
||||
my $Success = $DynamicFieldBackendObject->ValueSet(
|
||||
DynamicFieldConfig => $DynamicFieldConfig,
|
||||
ObjectID => $Param{Ticket}->{TicketID},
|
||||
Value => $Param{Config}->{$CurrentDynamicField},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check if everything went right
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. "Can't set value '"
|
||||
. $Param{Config}->{$CurrentDynamicField}
|
||||
. "' for DynamicField '$CurrentDynamicField',"
|
||||
. "TicketID '" . $Param{Ticket}->{TicketID} . "'!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,326 @@
|
||||
# --
|
||||
# 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::ProcessManagement::TransitionAction::TicketArticleCreate;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::ProcessManagement::TransitionAction::Base);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::Ticket',
|
||||
'Kernel::System::Ticket::Article',
|
||||
'Kernel::System::DynamicField',
|
||||
'Kernel::System::DynamicField::Backend',
|
||||
'Kernel::System::User',
|
||||
'Kernel::System::HTMLUtils',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::TransitionAction::TicketArticleCreate - A module to create an article
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
All TicketArticleCreate functions.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $TicketArticleCreateObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::TransitionAction::TicketArticleCreate');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Run()
|
||||
|
||||
Run Data
|
||||
|
||||
my $TicketArticleCreateResult = $TicketArticleCreateActionObject->Run(
|
||||
UserID => 123,
|
||||
Ticket => \%Ticket, # required
|
||||
ProcessEntityID => 'P123',
|
||||
ActivityEntityID => 'A123',
|
||||
TransitionEntityID => 'T123',
|
||||
TransitionActionEntityID => 'TA123',
|
||||
Config => {
|
||||
SenderType => 'agent', # (required) agent|system|customer
|
||||
IsVisibleForCustomer => 1, # 0 or 1
|
||||
CommunicationChannel => 'Internal', # Internal|Phone|Email|..., default: Internal
|
||||
|
||||
%DataPayload, # some parameters depending of each communication channel, please check ArticleCreate() on each
|
||||
# communication channel for the full list of optional and mandatory parameters
|
||||
|
||||
TimeUnit => 123, # optional, to set the accounting time
|
||||
UserID => 123, # optional, to override the UserID from the logged user
|
||||
},
|
||||
);
|
||||
|
||||
Ticket contains the result of TicketGet including DynamicFields
|
||||
Config is the Config Hash stored in a Process::TransitionAction's Config key
|
||||
Returns:
|
||||
|
||||
$TicketArticleCreateResult = 1; # 0
|
||||
|
||||
Internal article example:
|
||||
|
||||
my $TicketArticleCreateResult = $TicketArticleCreateActionObject->Run(
|
||||
UserID => 123,
|
||||
Ticket => {
|
||||
TicketNumber => '20101027000001',
|
||||
Title => 'some title',
|
||||
TicketID => 123,
|
||||
State => 'some state',
|
||||
# ... (all ticket properties)
|
||||
},
|
||||
ProcessEntityID => 'P123',
|
||||
ActivityEntityID => 'A123',
|
||||
TransitionEntityID => 'T123',
|
||||
TransitionActionEntityID => 'TA123',
|
||||
Config => {
|
||||
SenderType => 'agent',
|
||||
IsVisibleForCustomer => 1,
|
||||
CommunicationChannel => 'Internal',
|
||||
|
||||
# Internal article data payload.
|
||||
From => 'Some Agent <email@example.com>',
|
||||
To => 'Some Customer A <customer-a@example.com>',
|
||||
Subject => 'some short description',
|
||||
Body => 'the message text',
|
||||
Charset => 'ISO-8859-15',
|
||||
MimeType => 'text/plain',
|
||||
HistoryType => 'OwnerUpdate',
|
||||
HistoryComment => 'Some free text!',
|
||||
UnlockOnAway => 1,
|
||||
},
|
||||
);
|
||||
|
||||
Chat article example:
|
||||
|
||||
my $TicketArticleCreateResult = $TicketArticleCreateActionObject->Run(
|
||||
UserID => 123,
|
||||
Ticket => {
|
||||
TicketNumber => '20101027000001',
|
||||
Title => 'some title',
|
||||
TicketID => 123,
|
||||
State => 'some state',
|
||||
# ... (all ticket properties, as the result from Kernel::System::Ticket::TicketGet)
|
||||
},
|
||||
ProcessEntityID => 'P123',
|
||||
ActivityEntityID => 'A123',
|
||||
TransitionEntityID => 'T123',
|
||||
TransitionActionEntityID => 'TA123',
|
||||
Config => {
|
||||
SenderType => 'agent',
|
||||
IsVisibleForCustomer => 1,
|
||||
CommunicationChannel => 'Internal',
|
||||
|
||||
# Internal article data payload.
|
||||
From => 'Some Agent <email@example.com>',
|
||||
To => 'Some Customer A <customer-a@example.com>',
|
||||
Subject => 'some short description',
|
||||
Body => 'the message text',
|
||||
Charset => 'ISO-8859-15',
|
||||
MimeType => 'text/plain',
|
||||
HistoryType => 'OwnerUpdate',
|
||||
HistoryComment => 'Some free text!',
|
||||
UnlockOnAway => 1,
|
||||
},
|
||||
);
|
||||
|
||||
Chat article example:
|
||||
|
||||
my $TicketArticleCreateResult = $TicketArticleCreateActionObject->Run(
|
||||
UserID => 123,
|
||||
Ticket => {
|
||||
TicketNumber => '20101027000001',
|
||||
Title => 'some title',
|
||||
TicketID => 123,
|
||||
State => 'some state',
|
||||
# ... (all ticket properties, as the result from Kernel::System::Ticket::TicketGet)
|
||||
},
|
||||
ProcessEntityID => 'P123',
|
||||
ActivityEntityID => 'A123',
|
||||
SequenceFlowEntityID => 'T123',
|
||||
SequenceFlowActionEntityID => 'TA123',
|
||||
Config => {
|
||||
SenderType => 'agent',
|
||||
IsVisibleForCustomer => 1,
|
||||
CommunicationChannel => 'Internal',
|
||||
|
||||
# Chat article data payload.
|
||||
ChatMessageList => [
|
||||
{
|
||||
ID => 1,
|
||||
MessageText => 'My chat message',
|
||||
CreateTime => '2014-04-04 10:10:10',
|
||||
SystemGenerated => 0,
|
||||
ChatterID => '123',
|
||||
ChatterType => 'User',
|
||||
ChatterName => 'John Doe',
|
||||
},
|
||||
# ...
|
||||
],
|
||||
HistoryType => 'OwnerUpdate',
|
||||
HistoryComment => 'Some free text!',
|
||||
},
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Define a common message to output in case of any error.
|
||||
my $CommonMessage = "Process: $Param{ProcessEntityID} Activity: $Param{ActivityEntityID}"
|
||||
. " Transition: $Param{TransitionEntityID}"
|
||||
. " TransitionAction: $Param{TransitionActionEntityID} - ";
|
||||
|
||||
# Check for missing or wrong params.
|
||||
my $Success = $Self->_CheckParams(
|
||||
%Param,
|
||||
CommonMessage => $CommonMessage,
|
||||
);
|
||||
return if !$Success;
|
||||
|
||||
$Param{Config}->{CommunicationChannel} ||= 'Internal';
|
||||
|
||||
if ( !defined $Param{Config}->{IsVisibleForCustomer} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need Config -> IsVisibleForCustomer",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
# Override UserID if specified as a parameter in the TA config.
|
||||
$Param{UserID} = $Self->_OverrideUserID(%Param);
|
||||
|
||||
my $DynamicFieldObject = $Kernel::OM->Get('Kernel::System::DynamicField');
|
||||
my $DynamicFieldBackendObject = $Kernel::OM->Get('Kernel::System::DynamicField::Backend');
|
||||
|
||||
# Convert DynamicField value to HTML string, see bug#14229.
|
||||
my $HTMLUtilsObject = $Kernel::OM->Get('Kernel::System::HTMLUtils');
|
||||
if ( $Param{Config}->{Body} =~ /OTRS_TICKET_DynamicField_/ ) {
|
||||
MATCH:
|
||||
for my $Match ( sort keys %{ $Param{Ticket} } ) {
|
||||
if ( $Match =~ m/DynamicField_(.*)/ && $Param{Ticket}->{$Match} ) {
|
||||
|
||||
my $DynamicFieldConfig = $DynamicFieldObject->DynamicFieldGet(
|
||||
Name => $1,
|
||||
);
|
||||
|
||||
# Check if there is HTML content.
|
||||
my $IsHTMLContent = $DynamicFieldBackendObject->HasBehavior(
|
||||
DynamicFieldConfig => $DynamicFieldConfig,
|
||||
Behavior => 'IsHTMLContent',
|
||||
);
|
||||
|
||||
# Avoid duble conversion to HTML for dynamic fields with HTML content.
|
||||
next MATCH if $IsHTMLContent;
|
||||
$Param{Ticket}->{$Match} = $HTMLUtilsObject->ToHTML(
|
||||
String => $Param{Ticket}->{$Match},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Use ticket attributes if needed.
|
||||
$Self->_ReplaceTicketAttributes(%Param);
|
||||
$Self->_ReplaceAdditionalAttributes(%Param);
|
||||
|
||||
# Convert scalar items into array references.
|
||||
for my $Attribute (
|
||||
qw(ForceNotificationToUserID ExcludeNotificationToUserID ExcludeMuteNotificationToUserID)
|
||||
)
|
||||
{
|
||||
if ( IsStringWithData( $Param{Config}->{$Attribute} ) ) {
|
||||
$Param{Config}->{$Attribute} = $Self->_ConvertScalar2ArrayRef(
|
||||
Data => $Param{Config}->{$Attribute},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
# If "From" is not set and MIME based article is to be created.
|
||||
if (
|
||||
!$Param{Config}->{From}
|
||||
&& $Param{Config}->{CommunicationChannel} =~ m{\AEmail|Internal|Phone\z}msxi
|
||||
)
|
||||
{
|
||||
|
||||
# Get current user data
|
||||
my %User = $Kernel::OM->Get('Kernel::System::User')->GetUserData(
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# Set "From" field according to user - UserFullname <UserEmail>.
|
||||
$Param{Config}->{From} = $User{UserFullname} . ' <' . $User{UserEmail} . '>';
|
||||
}
|
||||
|
||||
my $ArticleBackendObject = $Kernel::OM->Get('Kernel::System::Ticket::Article')->BackendForChannel(
|
||||
ChannelName => $Param{Config}->{CommunicationChannel}
|
||||
);
|
||||
|
||||
my $ArticleID = $ArticleBackendObject->ArticleCreate(
|
||||
%{ $Param{Config} },
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
if ( !$ArticleID ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. "Couldn't create article for Ticket: "
|
||||
. $Param{Ticket}->{TicketID} . '!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# Set time units.
|
||||
if ( $Param{Config}->{TimeUnit} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Ticket')->TicketAccountTime(
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
ArticleID => $ArticleID,
|
||||
TimeUnit => $Param{Config}->{TimeUnit},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,455 @@
|
||||
# --
|
||||
# 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::ProcessManagement::TransitionAction::TicketCreate;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::ProcessManagement::TransitionAction::Base);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::DynamicField',
|
||||
'Kernel::System::DynamicField::Backend',
|
||||
'Kernel::System::LinkObject',
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::State',
|
||||
'Kernel::System::Ticket',
|
||||
'Kernel::System::Ticket::Article',
|
||||
'Kernel::System::DateTime',
|
||||
'Kernel::System::User',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::TransitionAction::TicketCreate - A module to create a ticket
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
All TicketCreate functions.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $TicketCreateObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::TransitionAction::TicketCreate');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Run()
|
||||
|
||||
Run Data
|
||||
|
||||
my $TicketCreateResult = $TicketCreateActionObject->Run(
|
||||
UserID => 123,
|
||||
Ticket => \%Ticket, # required
|
||||
ProcessEntityID => 'P123',
|
||||
ActivityEntityID => 'A123',
|
||||
TransitionEntityID => 'T123',
|
||||
TransitionActionEntityID => 'TA123',
|
||||
Config => {
|
||||
# ticket required:
|
||||
Title => 'Some Ticket Title',
|
||||
Queue => 'Raw', # or QueueID => 123,
|
||||
Lock => 'unlock',
|
||||
Priority => '3 normal', # or PriorityID => 2,
|
||||
State => 'new', # or StateID => 5,
|
||||
CustomerID => '123465',
|
||||
CustomerUser => 'customer@example.com',
|
||||
Owner => 'someuserlogin', # or OwnerID => 123
|
||||
|
||||
# ticket optional:
|
||||
TN => $TicketObject->TicketCreateNumber(), # optional
|
||||
Type => 'Incident', # or TypeID => 1, not required
|
||||
Service => 'Service A', # or ServiceID => 1, not required
|
||||
SLA => 'SLA A', # or SLAID => 1, not required
|
||||
ResponsibleID => 123, # not required
|
||||
ArchiveFlag => 'y', # (y|n) not required
|
||||
PendingTime => '2011-12-23 23:05:00', # optional (for pending states)
|
||||
PendingTimeDiff => 123 , # optional (for pending states)
|
||||
|
||||
# article required: (if one of them is not present, article will not be created without any error message)
|
||||
SenderType => 'agent', # agent|system|customer
|
||||
IsVisibleForCustomer => 1, # required
|
||||
CommunicationChannel => 'Internal', # Internal|Phone|Email|..., default: Internal
|
||||
|
||||
%DataPayload, # some parameters depending of each communication channel
|
||||
|
||||
# article optional:
|
||||
TimeUnit => 123
|
||||
|
||||
# other:
|
||||
DynamicField_NameX => $Value,
|
||||
LinkAs => $LinkType, # Normal, Parent, Child, etc. (respective original ticket)
|
||||
UserID => 123, # optional, to override the UserID from the logged user
|
||||
}
|
||||
);
|
||||
Ticket contains the result of TicketGet including DynamicFields
|
||||
Config is the Config Hash stored in a Process::TransitionAction's Config key
|
||||
Returns:
|
||||
|
||||
$TicketCreateResult = 1; # 0
|
||||
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# define a common message to output in case of any error
|
||||
my $CommonMessage = "Process: $Param{ProcessEntityID} Activity: $Param{ActivityEntityID}"
|
||||
. " Transition: $Param{TransitionEntityID}"
|
||||
. " TransitionAction: $Param{TransitionActionEntityID} - ";
|
||||
|
||||
# check for missing or wrong params
|
||||
my $Success = $Self->_CheckParams(
|
||||
%Param,
|
||||
CommonMessage => $CommonMessage,
|
||||
);
|
||||
return if !$Success;
|
||||
|
||||
# override UserID if specified as a parameter in the TA config
|
||||
$Param{UserID} = $Self->_OverrideUserID(%Param);
|
||||
|
||||
# use ticket attributes if needed
|
||||
$Self->_ReplaceTicketAttributes(%Param);
|
||||
$Self->_ReplaceAdditionalAttributes(%Param);
|
||||
|
||||
# convert scalar items into array references
|
||||
for my $Attribute (
|
||||
qw(ForceNotificationToUserID ExcludeNotificationToUserID
|
||||
ExcludeMuteNotificationToUserID
|
||||
)
|
||||
)
|
||||
{
|
||||
if ( IsStringWithData( $Param{Config}->{$Attribute} ) ) {
|
||||
$Param{Config}->{$Attribute} = $Self->_ConvertScalar2ArrayRef(
|
||||
Data => $Param{Config}->{$Attribute},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
# collect ticket params
|
||||
my %TicketParam;
|
||||
for my $Attribute (
|
||||
qw( Title Queue QueueID Lock LockID Priority PriorityID State StateID
|
||||
CustomerID CustomerUser Owner OwnerID TN Type TypeID Service ServiceID SLA SLAID
|
||||
Responsible ResponsibleID ArchiveFlag
|
||||
)
|
||||
)
|
||||
{
|
||||
if ( defined $Param{Config}->{$Attribute} ) {
|
||||
$TicketParam{$Attribute} = $Param{Config}->{$Attribute};
|
||||
}
|
||||
}
|
||||
|
||||
# get default values from system configuration
|
||||
for my $Attribute (qw(Queue State Lock Priority)) {
|
||||
|
||||
if ( !$TicketParam{$Attribute} && !$TicketParam{ $Attribute . "ID" } ) {
|
||||
$TicketParam{$Attribute} = $Kernel::OM->Get('Kernel::Config')->Get("Process::Default$Attribute") || '';
|
||||
}
|
||||
}
|
||||
|
||||
# Get OwnerID from Owner
|
||||
if ( $TicketParam{Owner} && !$TicketParam{OwnerID} ) {
|
||||
$TicketParam{OwnerID} = $Kernel::OM->Get('Kernel::System::User')->UserLookup(
|
||||
UserLogin => $TicketParam{Owner},
|
||||
);
|
||||
}
|
||||
|
||||
# get ticket object
|
||||
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
|
||||
|
||||
# create ticket
|
||||
my $TicketID = $TicketObject->TicketCreate(
|
||||
%TicketParam,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
if ( !$TicketID ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. "Couldn't create New Ticket from Ticket: "
|
||||
. $Param{Ticket}->{TicketID} . '!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get state information
|
||||
my %StateData;
|
||||
if ( $TicketParam{StateID} ) {
|
||||
%StateData = $Kernel::OM->Get('Kernel::System::State')->StateGet(
|
||||
ID => $TicketParam{StateID},
|
||||
);
|
||||
}
|
||||
else {
|
||||
%StateData = $Kernel::OM->Get('Kernel::System::State')->StateGet(
|
||||
Name => $TicketParam{State},
|
||||
);
|
||||
}
|
||||
|
||||
# closed tickets get unlocked
|
||||
if ( $StateData{TypeName} =~ /^close/i ) {
|
||||
|
||||
# set lock
|
||||
$TicketObject->TicketLockSet(
|
||||
TicketID => $TicketID,
|
||||
Lock => 'unlock',
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
|
||||
# set pending time
|
||||
elsif ( $StateData{TypeName} =~ /^pending/i ) {
|
||||
|
||||
if ( $Param{Config}->{PendingTime} ) {
|
||||
|
||||
# get datetime object
|
||||
my $DateTimeObject = $Kernel::OM->Create(
|
||||
'Kernel::System::DateTime',
|
||||
ObjectParams => {
|
||||
String => $Param{Config}->{PendingTime}
|
||||
}
|
||||
);
|
||||
my $TimeStamp = $DateTimeObject->ToString();
|
||||
|
||||
# set pending time
|
||||
$TicketObject->TicketPendingTimeSet(
|
||||
UserID => $Param{UserID},
|
||||
TicketID => $TicketID,
|
||||
String => $TimeStamp,
|
||||
);
|
||||
}
|
||||
elsif ( $Param{Config}->{PendingTimeDiff} ) {
|
||||
|
||||
# set pending time
|
||||
$TicketObject->TicketPendingTimeSet(
|
||||
UserID => $Param{UserID},
|
||||
TicketID => $TicketID,
|
||||
Diff => $Param{Config}->{PendingTimeDiff},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$Param{Config}->{CommunicationChannel} ||= 'Internal';
|
||||
|
||||
# check if article can be created
|
||||
my $ArticleCreate = 1;
|
||||
for my $Needed (qw(SenderType IsVisibleForCustomer)) {
|
||||
if ( !defined $Param{Config}->{$Needed} ) {
|
||||
$ArticleCreate = 0;
|
||||
}
|
||||
}
|
||||
|
||||
my $ArticleID;
|
||||
|
||||
if ($ArticleCreate) {
|
||||
|
||||
# If "From" is not set and MIME based article is to be created.
|
||||
if (
|
||||
!$Param{Config}->{From}
|
||||
&& $Param{Config}->{CommunicationChannel} =~ m{\AEmail|Internal|Phone\z}msxi
|
||||
)
|
||||
{
|
||||
|
||||
# Get current user data.
|
||||
my %User = $Kernel::OM->Get('Kernel::System::User')->GetUserData(
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# Set "From" field according to user - UserFullname <UserEmail>.
|
||||
$Param{Config}->{From} = $User{UserFullname} . ' <' . $User{UserEmail} . '>';
|
||||
}
|
||||
|
||||
my $ArticleBackendObject = $Kernel::OM->Get('Kernel::System::Ticket::Article')->BackendForChannel(
|
||||
ChannelName => $Param{Config}->{CommunicationChannel},
|
||||
);
|
||||
|
||||
# Create article for the new ticket.
|
||||
$ArticleID = $ArticleBackendObject->ArticleCreate(
|
||||
%{ $Param{Config} },
|
||||
TicketID => $TicketID,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
if ( !$ArticleID ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. "Couldn't create Article on Ticket: $TicketID from Ticket: "
|
||||
. $Param{Ticket}->{TicketID} . '!',
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
||||
# set time units
|
||||
if ( $Param{Config}->{TimeUnit} ) {
|
||||
$TicketObject->TicketAccountTime(
|
||||
TicketID => $TicketID,
|
||||
ArticleID => $ArticleID,
|
||||
TimeUnit => $Param{Config}->{TimeUnit},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# set dynamic fields for ticket and article
|
||||
|
||||
# set a field filter (all valid dynamic fields have to have set to 1 like NameX => 1)
|
||||
my %FieldFilter;
|
||||
for my $Attribute ( sort keys %{ $Param{Config} } ) {
|
||||
if ( $Attribute =~ m{\A DynamicField_ ( [a-zA-Z0-9]+ ) \z}msx ) {
|
||||
$FieldFilter{$1} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
# get dynamic field objects
|
||||
my $DynamicFieldObject = $Kernel::OM->Get('Kernel::System::DynamicField');
|
||||
my $DynamicFieldBackendObject = $Kernel::OM->Get('Kernel::System::DynamicField::Backend');
|
||||
|
||||
# get the dynamic fields for ticket
|
||||
my $DynamicFieldList = $DynamicFieldObject->DynamicFieldListGet(
|
||||
Valid => 1,
|
||||
ObjectType => [ 'Ticket', 'Article' ],
|
||||
FieldFilter => \%FieldFilter,
|
||||
);
|
||||
|
||||
# cycle through the activated Dynamic Fields for this screen
|
||||
DYNAMICFIELD:
|
||||
for my $DynamicFieldConfig ( @{$DynamicFieldList} ) {
|
||||
next DYNAMICFIELD if !IsHashRefWithData($DynamicFieldConfig);
|
||||
|
||||
my $ObjectID = $TicketID;
|
||||
if ( $DynamicFieldConfig->{ObjectType} ne 'Ticket' ) {
|
||||
|
||||
# skip article dynamic fields if Article was not created
|
||||
next DYNAMICFIELD if !$ArticleCreate || !$ArticleID;
|
||||
|
||||
$ObjectID = $ArticleID;
|
||||
}
|
||||
|
||||
# set the value
|
||||
my $Success = $DynamicFieldBackendObject->ValueSet(
|
||||
DynamicFieldConfig => $DynamicFieldConfig,
|
||||
ObjectID => $ObjectID,
|
||||
Value => $Param{Config}->{ 'DynamicField_' . $DynamicFieldConfig->{Name} },
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. "Couldn't set DynamicField Value on $DynamicFieldConfig->{ObjectType}:"
|
||||
. " $ObjectID from Ticket: "
|
||||
. $Param{Ticket}->{TicketID} . '!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# link ticket
|
||||
if ( $Param{Config}->{LinkAs} ) {
|
||||
|
||||
# get link object
|
||||
my $LinkObject = $Kernel::OM->Get('Kernel::System::LinkObject');
|
||||
|
||||
# get config of all types
|
||||
my %ConfiguredTypes = $LinkObject->TypeList(
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
my $SelectedType;
|
||||
my $SelectedDirection;
|
||||
|
||||
TYPE:
|
||||
for my $Type ( sort keys %ConfiguredTypes ) {
|
||||
if (
|
||||
$Param{Config}->{LinkAs} ne $ConfiguredTypes{$Type}->{SourceName}
|
||||
&& $Param{Config}->{LinkAs} ne $ConfiguredTypes{$Type}->{TargetName}
|
||||
)
|
||||
{
|
||||
next TYPE;
|
||||
}
|
||||
$SelectedType = $Type;
|
||||
$SelectedDirection = 'Source';
|
||||
if ( $Param{Config}->{LinkAs} eq $ConfiguredTypes{$Type}->{TargetName} ) {
|
||||
$SelectedDirection = 'Target';
|
||||
}
|
||||
last TYPE;
|
||||
}
|
||||
|
||||
if ( !$SelectedType ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. "LinkAs $Param{LinkAs} is invalid!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
my $SourceObjectID = $TicketID;
|
||||
my $TargetObjectID = $Param{Ticket}->{TicketID};
|
||||
if ( $SelectedDirection eq 'Target' ) {
|
||||
$SourceObjectID = $Param{Ticket}->{TicketID};
|
||||
$TargetObjectID = $TicketID;
|
||||
}
|
||||
|
||||
my $Success = $LinkObject->LinkAdd(
|
||||
SourceObject => 'Ticket',
|
||||
SourceKey => $SourceObjectID,
|
||||
TargetObject => 'Ticket',
|
||||
TargetKey => $TargetObjectID,
|
||||
Type => $SelectedType,
|
||||
State => 'Valid',
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. "Couldn't Link Tickets $SourceObjectID with $TargetObjectID as $Param{LinkAs}!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,203 @@
|
||||
# --
|
||||
# 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::ProcessManagement::TransitionAction::TicketCustomerSet;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::ProcessManagement::TransitionAction::Base);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::Ticket',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::TransitionAction::TicketCustomerSet - A module to set a new ticket customer
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
All TicketCustomerSet functions.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $TicketCustomerSetObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::TransitionAction::TicketCustomerSet');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Run()
|
||||
|
||||
Run Data
|
||||
|
||||
my $TicketCustomerSetResult = $TicketCustomerSetActionObject->Run(
|
||||
UserID => 123,
|
||||
Ticket => \%Ticket, # required
|
||||
ProcessEntityID => 'P123',
|
||||
ActivityEntityID => 'A123',
|
||||
TransitionEntityID => 'T123',
|
||||
TransitionActionEntityID => 'TA123',
|
||||
Config => {
|
||||
CustomerID => 'client123',
|
||||
# or
|
||||
CustomerUserID => 'client-user-123',
|
||||
|
||||
#OR (Framework wording)
|
||||
No => 'client123',
|
||||
# or
|
||||
User => 'client-user-123',
|
||||
|
||||
UserID => 123, # optional, to override the UserID from the logged user
|
||||
}
|
||||
);
|
||||
Ticket contains the result of TicketGet including DynamicFields
|
||||
Config is the Config Hash stored in a Process::TransitionAction's Config key
|
||||
Returns:
|
||||
|
||||
$TicketCustomerSetResult = 1; # 0
|
||||
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# define a common message to output in case of any error
|
||||
my $CommonMessage = "Process: $Param{ProcessEntityID} Activity: $Param{ActivityEntityID}"
|
||||
. " Transition: $Param{TransitionEntityID}"
|
||||
. " TransitionAction: $Param{TransitionActionEntityID} - ";
|
||||
|
||||
# check for missing or wrong params
|
||||
my $Success = $Self->_CheckParams(
|
||||
%Param,
|
||||
CommonMessage => $CommonMessage,
|
||||
);
|
||||
return if !$Success;
|
||||
|
||||
# override UserID if specified as a parameter in the TA config
|
||||
$Param{UserID} = $Self->_OverrideUserID(%Param);
|
||||
|
||||
# use ticket attributes if needed
|
||||
$Self->_ReplaceTicketAttributes(%Param);
|
||||
|
||||
if (
|
||||
!$Param{Config}->{CustomerID}
|
||||
&& !$Param{Config}->{No}
|
||||
&& !$Param{Config}->{CustomerUserID}
|
||||
&& !$Param{Config}->{User}
|
||||
)
|
||||
{
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage . "No CustomerID/No or CustomerUserID/User configured!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !$Param{Config}->{CustomerID} && $Param{Config}->{No} ) {
|
||||
$Param{Config}->{CustomerID} = $Param{Config}->{No};
|
||||
}
|
||||
if ( !$Param{Config}->{CustomerUserID} && $Param{Config}->{User} ) {
|
||||
$Param{Config}->{CustomerUserID} = $Param{Config}->{User};
|
||||
}
|
||||
|
||||
if (
|
||||
defined $Param{Config}->{CustomerID}
|
||||
&&
|
||||
(
|
||||
!defined $Param{Ticket}->{CustomerID}
|
||||
|| $Param{Config}->{CustomerID} ne $Param{Ticket}->{CustomerID}
|
||||
)
|
||||
)
|
||||
{
|
||||
# get ticket object
|
||||
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
|
||||
|
||||
my $Success = $TicketObject->TicketCustomerSet(
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
No => $Param{Config}->{CustomerID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. 'Ticket CustomerID: '
|
||||
. $Param{Config}->{CustomerID}
|
||||
. ' could not be updated for Ticket: '
|
||||
. $Param{Ticket}->{TicketID} . '!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
defined $Param{Config}->{CustomerUserID}
|
||||
&&
|
||||
(
|
||||
!defined $Param{Ticket}->{CustomerUserID}
|
||||
|| $Param{Config}->{CustomerUserID} ne $Param{Ticket}->{CustomerUserID}
|
||||
)
|
||||
)
|
||||
{
|
||||
# get ticket object
|
||||
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
|
||||
|
||||
my $Success = $TicketObject->TicketCustomerSet(
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
User => $Param{Config}->{CustomerUserID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. 'Ticket CustomerUserID: '
|
||||
. $Param{Config}->{CustomerUserID}
|
||||
. ' could not be updated for Ticket: '
|
||||
. $Param{Ticket}->{TicketID} . '!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,207 @@
|
||||
# --
|
||||
# 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::ProcessManagement::TransitionAction::TicketLockSet;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::ProcessManagement::TransitionAction::Base);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::Ticket',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::TransitionAction::TicketLockSet - A module to unlock a ticket
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
All TicketLockSet functions.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $TicketLockSetObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::TransitionAction::TicketLockSet');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Run()
|
||||
|
||||
Run Data
|
||||
|
||||
my $TicketLockSetResult = $TicketLockSetActionObject->Run(
|
||||
UserID => 123,
|
||||
Ticket => \%Ticket, # required
|
||||
ProcessEntityID => 'P123',
|
||||
ActivityEntityID => 'A123',
|
||||
TransitionEntityID => 'T123',
|
||||
TransitionActionEntityID => 'TA123',
|
||||
Config => {
|
||||
Lock => 'lock',
|
||||
# or
|
||||
LockID => 1,
|
||||
UserID => 123, # optional, to override the UserID from the logged user
|
||||
}
|
||||
);
|
||||
Ticket contains the result of TicketGet including DynamicFields
|
||||
Config is the Config Hash stored in a Process::TransitionAction's Config key
|
||||
Returns:
|
||||
|
||||
$TicketLockSetResult = 1; # 0
|
||||
|
||||
=cut
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# define a common message to output in case of any error
|
||||
my $CommonMessage = "Process: $Param{ProcessEntityID} Activity: $Param{ActivityEntityID}"
|
||||
. " Transition: $Param{TransitionEntityID}"
|
||||
. " TransitionAction: $Param{TransitionActionEntityID} - ";
|
||||
|
||||
# check for missing or wrong params
|
||||
my $Success = $Self->_CheckParams(
|
||||
%Param,
|
||||
CommonMessage => $CommonMessage,
|
||||
);
|
||||
return if !$Success;
|
||||
|
||||
# override UserID if specified as a parameter in the TA config
|
||||
$Param{UserID} = $Self->_OverrideUserID(%Param);
|
||||
|
||||
# use ticket attributes if needed
|
||||
$Self->_ReplaceTicketAttributes(%Param);
|
||||
|
||||
if ( !$Param{Config}->{LockID} && !$Param{Config}->{Lock} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage . "No Lock or LockID configured!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$Success = 0;
|
||||
|
||||
# If Ticket's LockID is already the same as the Value we
|
||||
# should set it to, we got nothing to do and return success
|
||||
if (
|
||||
defined $Param{Config}->{LockID}
|
||||
&& $Param{Config}->{LockID} eq $Param{Ticket}->{LockID}
|
||||
)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
# If Ticket's LockID is not the same as the Value we
|
||||
# should set it to, set the LockID
|
||||
elsif (
|
||||
defined $Param{Config}->{LockID}
|
||||
&& $Param{Config}->{LockID} ne $Param{Ticket}->{LockID}
|
||||
)
|
||||
{
|
||||
|
||||
# get ticket object
|
||||
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
|
||||
|
||||
$Success = $TicketObject->TicketLockSet(
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
LockID => $Param{Config}->{LockID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. 'Ticket LockID '
|
||||
. $Param{Config}->{LockID}
|
||||
. ' could not be updated for Ticket: '
|
||||
. $Param{Ticket}->{TicketID} . '!',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
# If Ticket's Lock is already the same as the Value we
|
||||
# should set it to, we got nothing to do and return success
|
||||
elsif (
|
||||
defined $Param{Config}->{Lock}
|
||||
&& $Param{Config}->{Lock} eq $Param{Ticket}->{Lock}
|
||||
)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
# If Ticket's Lock is not the same as the Value we
|
||||
# should set it to, set the Lock
|
||||
elsif (
|
||||
defined $Param{Config}->{Lock}
|
||||
&& $Param{Config}->{Lock} ne $Param{Ticket}->{Lock}
|
||||
)
|
||||
{
|
||||
# get ticket object
|
||||
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
|
||||
|
||||
$Success = $TicketObject->TicketLockSet(
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
Lock => $Param{Config}->{Lock},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. 'Ticket Lock '
|
||||
. $Param{Config}->{Lock}
|
||||
. ' could not be updated for Ticket: '
|
||||
. $Param{Ticket}->{TicketID} . '!',
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. "Couldn't update Ticket Lock - can't find valid Lock parameter!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
return $Success;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,171 @@
|
||||
# --
|
||||
# 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::ProcessManagement::TransitionAction::TicketOwnerSet;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::ProcessManagement::TransitionAction::Base);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::Ticket',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::TransitionAction::TicketOwnerSet - A module to set a new ticket owner
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
All TicketOwnerSet functions.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $TicketOwnerSetObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::TransitionAction::TicketOwnerSet');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Run()
|
||||
|
||||
Run Data
|
||||
|
||||
my $TicketOwnerSetResult = $TicketOwnerSetActionObject->Run(
|
||||
UserID => 123,
|
||||
Ticket => \%Ticket, # required
|
||||
ProcessEntityID => 'P123',
|
||||
ActivityEntityID => 'A123',
|
||||
TransitionEntityID => 'T123',
|
||||
TransitionActionEntityID => 'TA123',
|
||||
Config => {
|
||||
Owner => 'root@localhost',
|
||||
# or
|
||||
OwnerID => 1,
|
||||
UserID => 123, # optional, to override the UserID from the logged user
|
||||
}
|
||||
);
|
||||
Ticket contains the result of TicketGet including DynamicFields
|
||||
Config is the Config Hash stored in a Process::TransitionAction's Config key
|
||||
Returns:
|
||||
|
||||
$TicketOwnerSetResult = 1; # 0
|
||||
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# define a common message to output in case of any error
|
||||
my $CommonMessage = "Process: $Param{ProcessEntityID} Activity: $Param{ActivityEntityID}"
|
||||
. " Transition: $Param{TransitionEntityID}"
|
||||
. " TransitionAction: $Param{TransitionActionEntityID} - ";
|
||||
|
||||
# check for missing or wrong params
|
||||
my $Success = $Self->_CheckParams(
|
||||
%Param,
|
||||
CommonMessage => $CommonMessage,
|
||||
);
|
||||
return if !$Success;
|
||||
|
||||
# override UserID if specified as a parameter in the TA config
|
||||
$Param{UserID} = $Self->_OverrideUserID(%Param);
|
||||
|
||||
# use ticket attributes if needed
|
||||
$Self->_ReplaceTicketAttributes(%Param);
|
||||
$Self->_ReplaceAdditionalAttributes(%Param);
|
||||
|
||||
if ( !$Param{Config}->{OwnerID} && !$Param{Config}->{Owner} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage . "No Owner or OwnerID configured!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$Success = 0;
|
||||
|
||||
if (
|
||||
defined $Param{Config}->{Owner}
|
||||
&& $Param{Config}->{Owner} ne $Param{Ticket}->{Owner}
|
||||
)
|
||||
{
|
||||
$Success = $Kernel::OM->Get('Kernel::System::Ticket')->TicketOwnerSet(
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
NewUser => $Param{Config}->{Owner},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
elsif (
|
||||
defined $Param{Config}->{OwnerID}
|
||||
&& $Param{Config}->{OwnerID} ne $Param{Ticket}->{OwnerID}
|
||||
)
|
||||
{
|
||||
$Success = $Kernel::OM->Get('Kernel::System::Ticket')->TicketOwnerSet(
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
NewUserID => $Param{Config}->{OwnerID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
||||
# data is the same as in ticket nothing to do
|
||||
$Success = 1;
|
||||
}
|
||||
|
||||
if ( !$Success ) {
|
||||
my $CustomMessage;
|
||||
if ( defined $Param{Config}->{Owner} ) {
|
||||
$CustomMessage = "Owner: $Param{Config}->{Owner},";
|
||||
}
|
||||
else {
|
||||
$CustomMessage = "OwnerID: $Param{Config}->{OwnerID},";
|
||||
}
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. 'Ticket owner could not be updated to '
|
||||
. $CustomMessage
|
||||
. ' for Ticket: '
|
||||
. $Param{Ticket}->{TicketID} . '!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,170 @@
|
||||
# --
|
||||
# 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::ProcessManagement::TransitionAction::TicketQueueSet;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::ProcessManagement::TransitionAction::Base);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::Ticket',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::TransitionAction::TicketQueueSet - A Module to move a Ticket from to a new queue
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
All TicketQueueSet functions.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $TicketQueueSetObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::TransitionAction::TicketQueueSet');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Run()
|
||||
|
||||
Run Data
|
||||
|
||||
my $TicketQueueSetResult = $TicketQueueSetActionObject->Run(
|
||||
UserID => 123,
|
||||
Ticket => \%Ticket, # required
|
||||
ProcessEntityID => 'P123',
|
||||
ActivityEntityID => 'A123',
|
||||
TransitionEntityID => 'T123',
|
||||
TransitionActionEntityID => 'TA123',
|
||||
Config => {
|
||||
Queue => 'Misc',
|
||||
# or
|
||||
QueueID => 1,
|
||||
UserID => 123, # optional, to override the UserID from the logged user
|
||||
}
|
||||
);
|
||||
Ticket contains the result of TicketGet including DynamicFields
|
||||
Config is the Config Hash stored in a Process::TransitionAction's Config key
|
||||
Returns:
|
||||
|
||||
$TicketQueueSetResult = 1; # 0
|
||||
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# define a common message to output in case of any error
|
||||
my $CommonMessage = "Process: $Param{ProcessEntityID} Activity: $Param{ActivityEntityID}"
|
||||
. " Transition: $Param{TransitionEntityID}"
|
||||
. " TransitionAction: $Param{TransitionActionEntityID} - ";
|
||||
|
||||
# check for missing or wrong params
|
||||
my $Success = $Self->_CheckParams(
|
||||
%Param,
|
||||
CommonMessage => $CommonMessage,
|
||||
);
|
||||
return if !$Success;
|
||||
|
||||
# override UserID if specified as a parameter in the TA config
|
||||
$Param{UserID} = $Self->_OverrideUserID(%Param);
|
||||
|
||||
# use ticket attributes if needed
|
||||
$Self->_ReplaceTicketAttributes(%Param);
|
||||
|
||||
if ( !$Param{Config}->{QueueID} && !$Param{Config}->{Queue} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage . "No Queue or QueueID configured!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$Success = 0;
|
||||
|
||||
if (
|
||||
defined $Param{Config}->{Queue}
|
||||
&& $Param{Config}->{Queue} ne $Param{Ticket}->{Queue}
|
||||
)
|
||||
{
|
||||
$Success = $Kernel::OM->Get('Kernel::System::Ticket')->TicketQueueSet(
|
||||
Queue => $Param{Config}->{Queue},
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
elsif (
|
||||
defined $Param{Config}->{QueueID}
|
||||
&& $Param{Config}->{QueueID} ne $Param{Ticket}->{QueueID}
|
||||
)
|
||||
{
|
||||
$Success = $Kernel::OM->Get('Kernel::System::Ticket')->TicketQueueSet(
|
||||
QueueID => $Param{Config}->{QueueID},
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
||||
# data is the same as in ticket nothing to do
|
||||
$Success = 1;
|
||||
}
|
||||
|
||||
if ( !$Success ) {
|
||||
my $CustomMessage;
|
||||
if ( defined $Param{Config}->{Queue} ) {
|
||||
$CustomMessage = "Queue: $Param{Config}->{Queue},";
|
||||
}
|
||||
else {
|
||||
$CustomMessage = "QueueID: $Param{Config}->{QueueID},";
|
||||
}
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. 'Ticket queue could not be updated to '
|
||||
. $CustomMessage
|
||||
. ' for Ticket: '
|
||||
. $Param{Ticket}->{TicketID} . '!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,172 @@
|
||||
# --
|
||||
# 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::ProcessManagement::TransitionAction::TicketResponsibleSet;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::ProcessManagement::TransitionAction::Base);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::Ticket',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::TransitionAction::TicketResponsibleSet - A module to set a new ticket
|
||||
responsible
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
All TicketResponsibleSet functions.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $TicketResponsibleSetObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::TransitionAction::TicketResponsibleSet');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Run()
|
||||
|
||||
Run Data
|
||||
|
||||
my $TicketResponsibleSetResult = $TicketResponsibleSetActionObject->Run(
|
||||
UserID => 123,
|
||||
Ticket => \%Ticket, # required
|
||||
ProcessEntityID => 'P123',
|
||||
ActivityEntityID => 'A123',
|
||||
TransitionEntityID => 'T123',
|
||||
TransitionActionEntityID => 'TA123',
|
||||
Config => {
|
||||
Responsible => 'root@localhost',
|
||||
# or
|
||||
ResponsibleID => 1,
|
||||
UserID => 123, # optional, to override the UserID from the logged user
|
||||
}
|
||||
);
|
||||
Ticket contains the result of TicketGet including DynamicFields
|
||||
Config is the Config Hash stored in a Process::TransitionAction's Config key
|
||||
Returns:
|
||||
|
||||
$TicketResponsibleSetResult = 1; # 0
|
||||
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# define a common message to output in case of any error
|
||||
my $CommonMessage = "Process: $Param{ProcessEntityID} Activity: $Param{ActivityEntityID}"
|
||||
. " Transition: $Param{TransitionEntityID}"
|
||||
. " TransitionAction: $Param{TransitionActionEntityID} - ";
|
||||
|
||||
# check for missing or wrong params
|
||||
my $Success = $Self->_CheckParams(
|
||||
%Param,
|
||||
CommonMessage => $CommonMessage,
|
||||
);
|
||||
return if !$Success;
|
||||
|
||||
# override UserID if specified as a parameter in the TA config
|
||||
$Param{UserID} = $Self->_OverrideUserID(%Param);
|
||||
|
||||
# use ticket attributes if needed
|
||||
$Self->_ReplaceTicketAttributes(%Param);
|
||||
$Self->_ReplaceAdditionalAttributes(%Param);
|
||||
|
||||
if ( !$Param{Config}->{ResponsibleID} && !$Param{Config}->{Responsible} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage . "No Responsible or ResponsibleID configured!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$Success = 0;
|
||||
|
||||
if (
|
||||
defined $Param{Config}->{Responsible}
|
||||
&& $Param{Config}->{Responsible} ne $Param{Ticket}->{Responsible}
|
||||
)
|
||||
{
|
||||
$Success = $Kernel::OM->Get('Kernel::System::Ticket')->TicketResponsibleSet(
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
NewUser => $Param{Config}->{Responsible},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
elsif (
|
||||
defined $Param{Config}->{ResponsibleID}
|
||||
&& $Param{Config}->{ResponsibleID} ne $Param{Ticket}->{ResponsibleID}
|
||||
)
|
||||
{
|
||||
$Success = $Kernel::OM->Get('Kernel::System::Ticket')->TicketResponsibleSet(
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
NewUserID => $Param{Config}->{ResponsibleID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
||||
# data is the same as in ticket nothing to do
|
||||
$Success = 1;
|
||||
}
|
||||
|
||||
if ( !$Success ) {
|
||||
my $CustomMessage;
|
||||
if ( defined $Param{Config}->{Responsible} ) {
|
||||
$CustomMessage = "Responsible: $Param{Config}->{Responsible},";
|
||||
}
|
||||
else {
|
||||
$CustomMessage = "ResponsibleID: $Param{Config}->{ResponsibleID},";
|
||||
}
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. 'Ticket responsible could not be updated to '
|
||||
. $CustomMessage
|
||||
. ' for Ticket: '
|
||||
. $Param{Ticket}->{TicketID} . '!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,312 @@
|
||||
# --
|
||||
# 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::ProcessManagement::TransitionAction::TicketSLASet;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::ProcessManagement::TransitionAction::Base);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::SLA',
|
||||
'Kernel::System::Ticket',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::TransitionAction::TicketSLASet - A module to set the ticket SLA
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
All TicketSLASet functions.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $TicketSLASetObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::TransitionAction::TicketSLASet');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Run()
|
||||
|
||||
Run Data
|
||||
|
||||
my $TicketSLASetResult = $TicketSLASetActionObject->Run(
|
||||
UserID => 123,
|
||||
Ticket => \%Ticket, # required
|
||||
ProcessEntityID => 'P123',
|
||||
ActivityEntityID => 'A123',
|
||||
TransitionEntityID => 'T123',
|
||||
TransitionActionEntityID => 'TA123',
|
||||
Config => {
|
||||
SLA => 'MySLA',
|
||||
# or
|
||||
SLAID => 123,
|
||||
UserID => 123, # optional, to override the UserID from the logged user
|
||||
}
|
||||
);
|
||||
Ticket contains the result of TicketGet including DynamicFields
|
||||
Config is the Config Hash stored in a Process::TransitionAction's Config key
|
||||
Returns:
|
||||
|
||||
$TicketSLASetResult = 1; # 0
|
||||
|
||||
=cut
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# define a common message to output in case of any error
|
||||
my $CommonMessage = "Process: $Param{ProcessEntityID} Activity: $Param{ActivityEntityID}"
|
||||
. " Transition: $Param{TransitionEntityID}"
|
||||
. " TransitionAction: $Param{TransitionActionEntityID} - ";
|
||||
|
||||
# check for missing or wrong params
|
||||
my $Success = $Self->_CheckParams(
|
||||
%Param,
|
||||
CommonMessage => $CommonMessage,
|
||||
);
|
||||
return if !$Success;
|
||||
|
||||
# override UserID if specified as a parameter in the TA config
|
||||
$Param{UserID} = $Self->_OverrideUserID(%Param);
|
||||
|
||||
# use ticket attributes if needed
|
||||
$Self->_ReplaceTicketAttributes(%Param);
|
||||
|
||||
if ( !$Param{Config}->{SLAID} && !$Param{Config}->{SLA} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage . "No SLA or SLAID configured!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !$Param{Ticket}->{ServiceID} && !$Param{Ticket}->{Service} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage . "To set a SLA the ticket requires a service!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$Success = 0;
|
||||
|
||||
# If Ticket's SLAID is already the same as the Value we
|
||||
# should set it to, we got nothing to do and return success
|
||||
if (
|
||||
defined $Param{Config}->{SLAID}
|
||||
&& defined $Param{Ticket}->{SLAID}
|
||||
&& $Param{Config}->{SLAID} eq $Param{Ticket}->{SLAID}
|
||||
)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
# If Ticket's SLAID is not the same as the Value we
|
||||
# should set it to, set the SLAID
|
||||
elsif (
|
||||
(
|
||||
defined $Param{Config}->{SLAID}
|
||||
&& defined $Param{Ticket}->{SLAID}
|
||||
&& $Param{Config}->{SLAID} ne $Param{Ticket}->{SLAID}
|
||||
)
|
||||
|| !defined $Param{Ticket}->{SLAID}
|
||||
)
|
||||
{
|
||||
|
||||
# check if serivce is assigned to Service otherwise return
|
||||
$Success = $Self->_CheckSLA(
|
||||
ServiceID => $Param{Ticket}->{ServiceID},
|
||||
SLAID => $Param{Config}->{SLAID},
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. 'SLAID '
|
||||
. $Param{Config}->{SLAID}
|
||||
. ' is not assigned to Service '
|
||||
. $Param{Ticket}->{Service}
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# set ticket SLA
|
||||
$Success = $Kernel::OM->Get('Kernel::System::Ticket')->TicketSLASet(
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
SLAID => $Param{Config}->{SLAID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. 'Ticket SLAID '
|
||||
. $Param{Config}->{SLAID}
|
||||
. ' could not be updated for Ticket: '
|
||||
. $Param{Ticket}->{TicketID} . '!',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
# If Ticket's SLA is already the same as the Value we
|
||||
# should set it to, we got nothing to do and return success
|
||||
elsif (
|
||||
defined $Param{Config}->{SLA}
|
||||
&& defined $Param{Ticket}->{SLA}
|
||||
&& $Param{Config}->{SLA} eq $Param{Ticket}->{SLA}
|
||||
)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
# If Ticket's SLA is not the same as the Value we
|
||||
# should set it to, set the SLA
|
||||
elsif (
|
||||
(
|
||||
defined $Param{Config}->{SLA}
|
||||
&& defined $Param{Ticket}->{SLA}
|
||||
&& $Param{Config}->{SLA} ne $Param{Ticket}->{SLA}
|
||||
)
|
||||
|| !defined $Param{Ticket}->{SLA}
|
||||
)
|
||||
{
|
||||
|
||||
my $SLAID = $Kernel::OM->Get('Kernel::System::SLA')->SLALookup(
|
||||
Name => $Param{Config}->{SLA},
|
||||
);
|
||||
|
||||
if ( !$SLAID ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. 'SLA '
|
||||
. $Param{Config}->{SLA}
|
||||
. ' is invalid!'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# check if SLA is assigned to Service, otherwise return
|
||||
$Success = $Self->_CheckSLA(
|
||||
ServiceID => $Param{Ticket}->{ServiceID},
|
||||
SLAID => $SLAID,
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. 'SLA '
|
||||
. $Param{Config}->{SLA}
|
||||
. ' is not assigned to Service '
|
||||
. $Param{Ticket}->{Service}
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# set ticket SLA
|
||||
$Success = $Kernel::OM->Get('Kernel::System::Ticket')->TicketSLASet(
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
SLA => $Param{Config}->{SLA},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. 'Ticket SLA '
|
||||
. $Param{Config}->{SLA}
|
||||
. ' could not be updated for Ticket: '
|
||||
. $Param{Ticket}->{TicketID} . '!',
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. "Couldn't update Ticket SLA - can't find valid SLA parameter!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
return $Success;
|
||||
}
|
||||
|
||||
=begin Internal:
|
||||
|
||||
=head2 _CheckSLA()
|
||||
|
||||
checks if a SLA is assigned to a Service
|
||||
|
||||
my $Success = _CheckSLA(
|
||||
ServiceID => 123,
|
||||
SLAID => 123,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$Success = 1; # or undef
|
||||
|
||||
=cut
|
||||
|
||||
sub _CheckSLA {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# get a list of assigned SLAs to the Service
|
||||
my %SLAs = $Kernel::OM->Get('Kernel::System::SLA')->SLAList(
|
||||
ServiceID => $Param{ServiceID},
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
# return failure if there are no assigned SLAs for this Service
|
||||
return if !IsHashRefWithData( \%SLAs );
|
||||
|
||||
# return failure if the the SLA is not assigned to the Service
|
||||
return if !$SLAs{ $Param{SLAID} };
|
||||
|
||||
# otherwise return success
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=end Internal:
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,319 @@
|
||||
# --
|
||||
# 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::ProcessManagement::TransitionAction::TicketServiceSet;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::ProcessManagement::TransitionAction::Base);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::Service',
|
||||
'Kernel::System::Ticket',
|
||||
'Kernel::Config',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::TransitionAction::TicketServiceSet - A module to set the ticket Service
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
All TicketServiceSet functions.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $TicketServiceSetObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::TransitionAction::TicketServiceSet');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Run()
|
||||
|
||||
Run Data
|
||||
|
||||
my $TicketServiceSetResult = $TicketServiceSetActionObject->Run(
|
||||
UserID => 123,
|
||||
Ticket => \%Ticket, # required
|
||||
ProcessEntityID => 'P123',
|
||||
ActivityEntityID => 'A123',
|
||||
TransitionEntityID => 'T123',
|
||||
TransitionActionEntityID => 'TA123',
|
||||
Config => {
|
||||
Service => 'MyService::Subservice',
|
||||
# or
|
||||
ServiceID => 123,
|
||||
UserID => 123, # optional, to override the UserID from the logged user
|
||||
}
|
||||
);
|
||||
Ticket contains the result of TicketGet including DynamicFields
|
||||
Config is the Config Hash stored in a Process::TransitionAction's Config key
|
||||
Returns:
|
||||
|
||||
$TicketServiceSetResult = 1; # 0
|
||||
|
||||
=cut
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# define a common message to output in case of any error
|
||||
my $CommonMessage = "Process: $Param{ProcessEntityID} Activity: $Param{ActivityEntityID}"
|
||||
. " Transition: $Param{TransitionEntityID}"
|
||||
. " TransitionAction: $Param{TransitionActionEntityID} - ";
|
||||
|
||||
# check for missing or wrong params
|
||||
my $Success = $Self->_CheckParams(
|
||||
%Param,
|
||||
CommonMessage => $CommonMessage,
|
||||
);
|
||||
return if !$Success;
|
||||
|
||||
# override UserID if specified as a parameter in the TA config
|
||||
$Param{UserID} = $Self->_OverrideUserID(%Param);
|
||||
|
||||
# use ticket attributes if needed
|
||||
$Self->_ReplaceTicketAttributes(%Param);
|
||||
|
||||
if ( !$Param{Config}->{ServiceID} && !$Param{Config}->{Service} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage . "No Service or ServiceID configured!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
!$Param{Ticket}->{CustomerUserID}
|
||||
&& !$Kernel::OM->Get('Kernel::Config')->Get('Ticket::Service::Default::UnknownCustomer')
|
||||
)
|
||||
{
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage . "To set a service the ticket requires a customer!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$Success = 0;
|
||||
|
||||
# If Ticket's ServiceID is already the same as the Value we
|
||||
# should set it to, we got nothing to do and return success
|
||||
if (
|
||||
defined $Param{Config}->{ServiceID}
|
||||
&& defined $Param{Ticket}->{ServiceID}
|
||||
&& $Param{Config}->{ServiceID} eq $Param{Ticket}->{ServiceID}
|
||||
)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
# If Ticket's ServiceID is not the same as the Value we
|
||||
# should set it to, set the ServiceID
|
||||
elsif (
|
||||
(
|
||||
defined $Param{Config}->{ServiceID}
|
||||
&& defined $Param{Ticket}->{ServiceID}
|
||||
&& $Param{Config}->{ServiceID} ne $Param{Ticket}->{ServiceID}
|
||||
)
|
||||
|| !defined $Param{Ticket}->{ServiceID}
|
||||
)
|
||||
{
|
||||
|
||||
# check if serivce is assigned to Customer User otherwise return
|
||||
$Success = $Self->_CheckService(
|
||||
UserLogin => $Param{Ticket}->{CustomerUserID},
|
||||
ServiceID => $Param{Config}->{ServiceID}
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. 'ServiceID '
|
||||
. $Param{Config}->{ServiceID}
|
||||
. ' is not assigned to Customer User '
|
||||
. $Param{Ticket}->{CustomerUserID}
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# set ticket service
|
||||
$Success = $Kernel::OM->Get('Kernel::System::Ticket')->TicketServiceSet(
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
ServiceID => $Param{Config}->{ServiceID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. 'Ticket ServiceID '
|
||||
. $Param{Config}->{ServiceID}
|
||||
. ' could not be updated for Ticket: '
|
||||
. $Param{Ticket}->{TicketID} . '!',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
# If Ticket's Service is already the same as the Value we
|
||||
# should set it to, we got nothing to do and return success
|
||||
elsif (
|
||||
defined $Param{Config}->{Service}
|
||||
&& defined $Param{Ticket}->{Service}
|
||||
&& $Param{Config}->{Service} eq $Param{Ticket}->{Service}
|
||||
)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
# If Ticket's Service is not the same as the Value we
|
||||
# should set it to, set the Service
|
||||
elsif (
|
||||
(
|
||||
defined $Param{Config}->{Service}
|
||||
&& defined $Param{Ticket}->{Service}
|
||||
&& $Param{Config}->{Service} ne $Param{Ticket}->{Service}
|
||||
)
|
||||
|| !defined $Param{Ticket}->{Service}
|
||||
|
||||
)
|
||||
{
|
||||
|
||||
my $ServiceID = $Kernel::OM->Get('Kernel::System::Service')->ServiceLookup(
|
||||
Name => $Param{Config}->{Service},
|
||||
);
|
||||
|
||||
if ( !$ServiceID ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. 'Service '
|
||||
. $Param{Config}->{Service}
|
||||
. ' is invalid!'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# check if service is assigned to Customer User, otherwise return
|
||||
$Success = $Self->_CheckService(
|
||||
UserLogin => $Param{Ticket}->{CustomerUserID},
|
||||
ServiceID => $ServiceID,
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. 'Service '
|
||||
. $Param{Config}->{Service}
|
||||
. ' is not assigned to Customer User '
|
||||
. $Param{Ticket}->{CustomerUserID}
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# set ticket service
|
||||
$Success = $Kernel::OM->Get('Kernel::System::Ticket')->TicketServiceSet(
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
Service => $Param{Config}->{Service},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. 'Ticket Service '
|
||||
. $Param{Config}->{Service}
|
||||
. ' could not be updated for Ticket: '
|
||||
. $Param{Ticket}->{TicketID} . '!',
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. "Couldn't update Ticket Service - can't find valid Service parameter!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
return $Success;
|
||||
}
|
||||
|
||||
=begin Internal:
|
||||
|
||||
=head2 _CheckService()
|
||||
|
||||
checks if a service is assigned to a customer user
|
||||
|
||||
my $Success = _CheckService(
|
||||
UserLogin => 'some user',
|
||||
ServiceID => 123,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$Success = 1; # or undef
|
||||
|
||||
=cut
|
||||
|
||||
sub _CheckService {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# get a list of assigned services to the customer user
|
||||
my %Services = $Kernel::OM->Get('Kernel::System::Service')->CustomerUserServiceMemberList(
|
||||
CustomerUserLogin => $Param{UserLogin},
|
||||
Result => 'HASH',
|
||||
DefaultServices => 1,
|
||||
);
|
||||
|
||||
# return failure if there are no assigned services for this customer user
|
||||
return if !IsHashRefWithData( \%Services );
|
||||
|
||||
# return failure if the the service is not assigned to the customer
|
||||
return if !$Services{ $Param{ServiceID} };
|
||||
|
||||
# otherwise return success
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=end Internal:
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,222 @@
|
||||
# --
|
||||
# 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::ProcessManagement::TransitionAction::TicketStateSet;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::ProcessManagement::TransitionAction::Base);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::State',
|
||||
'Kernel::System::Ticket',
|
||||
'Kernel::System::DateTime',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::TransitionAction::TicketStateSet - A module to set the ticket state
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
All TicketStateSet functions.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $TicketStateSetObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::TransitionAction::TicketStateSet');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Run()
|
||||
|
||||
Run Data
|
||||
|
||||
my $TicketStateSetResult = $TicketStateSetActionObject->Run(
|
||||
UserID => 123,
|
||||
Ticket => \%Ticket, # required
|
||||
ProcessEntityID => 'P123',
|
||||
ActivityEntityID => 'A123',
|
||||
TransitionEntityID => 'T123',
|
||||
TransitionActionEntityID => 'TA123',
|
||||
Config => {
|
||||
State => 'open',
|
||||
# or
|
||||
StateID => 3,
|
||||
|
||||
PendingTimeDiff => 123, # optional, used for pending states, difference in seconds from
|
||||
# current time to desired pending time (e.g. a value of 3600 means
|
||||
# that the pending time will be 1 hr after the Transition Action is
|
||||
# executed)
|
||||
UserID => 123, # optional, to override the UserID from the logged user
|
||||
}
|
||||
);
|
||||
Ticket contains the result of TicketGet including DynamicFields
|
||||
Config is the Config Hash stored in a Process::TransitionAction's Config key
|
||||
Returns:
|
||||
|
||||
$TicketStateSetResult = 1; # 0
|
||||
|
||||
=cut
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# define a common message to output in case of any error
|
||||
my $CommonMessage = "Process: $Param{ProcessEntityID} Activity: $Param{ActivityEntityID}"
|
||||
. " Transition: $Param{TransitionEntityID}"
|
||||
. " TransitionAction: $Param{TransitionActionEntityID} - ";
|
||||
|
||||
# check for missing or wrong params
|
||||
my $Success = $Self->_CheckParams(
|
||||
%Param,
|
||||
CommonMessage => $CommonMessage,
|
||||
);
|
||||
return if !$Success;
|
||||
|
||||
# override UserID if specified as a parameter in the TA config
|
||||
$Param{UserID} = $Self->_OverrideUserID(%Param);
|
||||
|
||||
# use ticket attributes if needed
|
||||
$Self->_ReplaceTicketAttributes(%Param);
|
||||
|
||||
if ( !$Param{Config}->{StateID} && !$Param{Config}->{State} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage . "No State or StateID configured!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$Success = 0;
|
||||
my %StateData;
|
||||
|
||||
if ( defined $Param{Config}->{StateID} ) {
|
||||
|
||||
%StateData = $Kernel::OM->Get('Kernel::System::State')->StateGet(
|
||||
ID => $Param{Config}->{StateID},
|
||||
);
|
||||
|
||||
if ( $Param{Config}->{StateID} ne $Param{Ticket}->{StateID} ) {
|
||||
|
||||
$Success = $Kernel::OM->Get('Kernel::System::Ticket')->TicketStateSet(
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
StateID => $Param{Config}->{StateID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. 'Ticket StateID '
|
||||
. $Param{Config}->{StateID}
|
||||
. ' could not be updated for Ticket: '
|
||||
. $Param{Ticket}->{TicketID} . '!',
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
# Data is the same as in ticket nothing to do.
|
||||
$Success = 1;
|
||||
}
|
||||
|
||||
}
|
||||
elsif ( $Param{Config}->{State} ) {
|
||||
|
||||
%StateData = $Kernel::OM->Get('Kernel::System::State')->StateGet(
|
||||
Name => $Param{Config}->{State},
|
||||
);
|
||||
if ( $Param{Config}->{State} ne $Param{Ticket}->{State} ) {
|
||||
|
||||
$Success = $Kernel::OM->Get('Kernel::System::Ticket')->TicketStateSet(
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
State => $Param{Config}->{State},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. 'Ticket State '
|
||||
. $Param{Config}->{State}
|
||||
. ' could not be updated for Ticket: '
|
||||
. $Param{Ticket}->{TicketID} . '!',
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
# Data is the same as in ticket nothing to do.
|
||||
$Success = 1;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. "Couldn't update Ticket State - can't find valid State parameter!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# set pending time
|
||||
if (
|
||||
IsHashRefWithData( \%StateData )
|
||||
&& $StateData{TypeName} =~ m{\A pending}msxi
|
||||
&& IsNumber( $Param{Config}->{PendingTimeDiff} )
|
||||
)
|
||||
{
|
||||
|
||||
# get datetime object
|
||||
my $DateTimeObject = $Kernel::OM->Create('Kernel::System::DateTime');
|
||||
$DateTimeObject->Add( Seconds => $Param{Config}->{PendingTimeDiff} );
|
||||
|
||||
# set pending time
|
||||
$Kernel::OM->Get('Kernel::System::Ticket')->TicketPendingTimeSet(
|
||||
UserID => $Param{UserID},
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
String => $DateTimeObject->ToString(),
|
||||
);
|
||||
}
|
||||
|
||||
return $Success;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,147 @@
|
||||
# --
|
||||
# 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::ProcessManagement::TransitionAction::TicketTitleSet;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::ProcessManagement::TransitionAction::Base);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::Ticket',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::TransitionAction::TicketTitleSet - A Module to set the title of a Ticket
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
All TicketTitleSet functions.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $TicketTitleSetObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::TransitionAction::TicketTitleSet');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Run()
|
||||
|
||||
Run Data
|
||||
|
||||
my $TicketTitleSetResult = $TicketTitleSetActionObject->Run(
|
||||
UserID => 123,
|
||||
Ticket => \%Ticket, # required
|
||||
ProcessEntityID => 'P123',
|
||||
ActivityEntityID => 'A123',
|
||||
TransitionEntityID => 'T123',
|
||||
TransitionActionEntityID => 'TA123',
|
||||
Config => {
|
||||
Title => 'Some ticket title',
|
||||
UserID => 123, # optional, to override the UserID from the logged user
|
||||
|
||||
}
|
||||
);
|
||||
Ticket contains the result of TicketGet including DynamicFields
|
||||
Config is the Config Hash stored in a Process::TransitionAction's Config key
|
||||
Returns:
|
||||
|
||||
$TicketTitleSetResult = 1; # 0
|
||||
|
||||
=cut
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# define a common message to output in case of any error
|
||||
my $CommonMessage = "Process: $Param{ProcessEntityID} Activity: $Param{ActivityEntityID}"
|
||||
. " Transition: $Param{TransitionEntityID}"
|
||||
. " TransitionAction: $Param{TransitionActionEntityID} - ";
|
||||
|
||||
# check for missing or wrong params
|
||||
my $Success = $Self->_CheckParams(
|
||||
%Param,
|
||||
CommonMessage => $CommonMessage,
|
||||
);
|
||||
return if !$Success;
|
||||
|
||||
# override UserID if specified as a parameter in the TA config
|
||||
$Param{UserID} = $Self->_OverrideUserID(%Param);
|
||||
|
||||
# use ticket attributes if needed
|
||||
$Self->_ReplaceTicketAttributes(%Param);
|
||||
|
||||
# Check for required parameters in ConfigHash
|
||||
if ( !defined $Param{Config}->{Title} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage . "No Title configured!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$Success = 0;
|
||||
if (
|
||||
$Param{Config}->{Title} ne $Param{Ticket}->{Title}
|
||||
)
|
||||
{
|
||||
$Success = $Kernel::OM->Get('Kernel::System::Ticket')->TicketTitleUpdate(
|
||||
Title => $Param{Config}->{Title},
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
||||
# data is the same as in ticket nothing to do
|
||||
$Success = 1;
|
||||
}
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. 'Ticket title could not be updated for Ticket: '
|
||||
. $Param{Ticket}->{TicketID} . '!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,179 @@
|
||||
# --
|
||||
# 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::ProcessManagement::TransitionAction::TicketTypeSet;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::ProcessManagement::TransitionAction::Base);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::Ticket',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::TransitionAction::TicketTypeSet - A Module to set the type of a Ticket
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
All TicketTypeSet functions.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $TicketTypeSetObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::TransitionAction::TicketTypeSet');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Run()
|
||||
|
||||
Run Data
|
||||
|
||||
my $TicketTypeSetResult = $TicketTypeSetActionObject->Run(
|
||||
UserID => 123,
|
||||
Ticket => \%Ticket, # required
|
||||
ProcessEntityID => 'P123',
|
||||
ActivityEntityID => 'A123',
|
||||
TransitionEntityID => 'T123',
|
||||
TransitionActionEntityID => 'TA123',
|
||||
Config => {
|
||||
Type => 'Default',
|
||||
# or
|
||||
TypeID => 1,
|
||||
UserID => 123, # optional, to override the UserID from the logged user
|
||||
|
||||
}
|
||||
);
|
||||
Ticket contains the result of TicketGet including DynamicFields
|
||||
Config is the Config Hash stored in a Process::TransitionAction's Config key
|
||||
Returns:
|
||||
|
||||
$TicketTypeSetResult = 1; # 0
|
||||
|
||||
=cut
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# define a common message to output in case of any error
|
||||
my $CommonMessage = "Process: $Param{ProcessEntityID} Activity: $Param{ActivityEntityID}"
|
||||
. " Transition: $Param{TransitionEntityID}"
|
||||
. " TransitionAction: $Param{TransitionActionEntityID} - ";
|
||||
|
||||
# check for missing or wrong params
|
||||
my $Success = $Self->_CheckParams(
|
||||
%Param,
|
||||
CommonMessage => $CommonMessage,
|
||||
);
|
||||
return if !$Success;
|
||||
|
||||
# override UserID if specified as a parameter in the TA config
|
||||
$Param{UserID} = $Self->_OverrideUserID(%Param);
|
||||
|
||||
# use ticket attributes if needed
|
||||
$Self->_ReplaceTicketAttributes(%Param);
|
||||
|
||||
if ( !$Param{Config}->{TypeID} && !$Param{Config}->{Type} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage . "No Type or TypeID configured!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !$Kernel::OM->Get('Kernel::Config')->Get('Ticket::Type') ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage . "Ticket::Type SysConfig setting is not enabled!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$Success = 0;
|
||||
|
||||
if (
|
||||
defined $Param{Config}->{Type}
|
||||
&& $Param{Config}->{Type} ne $Param{Ticket}->{Type}
|
||||
)
|
||||
{
|
||||
$Success = $Kernel::OM->Get('Kernel::System::Ticket')->TicketTypeSet(
|
||||
Type => $Param{Config}->{Type},
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
elsif (
|
||||
defined $Param{Config}->{TypeID}
|
||||
&& $Param{Config}->{TypeID} ne $Param{Ticket}->{TypeID}
|
||||
)
|
||||
{
|
||||
$Success = $Kernel::OM->Get('Kernel::System::Ticket')->TicketTypeSet(
|
||||
TypeID => $Param{Config}->{TypeID},
|
||||
TicketID => $Param{Ticket}->{TicketID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
||||
# data is the same as in ticket nothing to do
|
||||
$Success = 1;
|
||||
}
|
||||
|
||||
if ( !$Success ) {
|
||||
my $CustomMessage;
|
||||
if ( defined $Param{Config}->{Type} ) {
|
||||
$CustomMessage = "Type: $Param{Config}->{Type},";
|
||||
}
|
||||
else {
|
||||
$CustomMessage = "TypeID: $Param{Config}->{TypeID},";
|
||||
}
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => $CommonMessage
|
||||
. 'Ticket type could not be updated to '
|
||||
. $CustomMessage
|
||||
. ' for Ticket: '
|
||||
. $Param{Ticket}->{TicketID} . '!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,106 @@
|
||||
# --
|
||||
# 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::ProcessManagement::TransitionValidation::ValidateDemo;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ProcessManagement::TransitionValidation::ValidateDemo - Demo for Transition Validation Module
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
All ValidateDemo functions.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $ValidateDemoObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::TransitionValidation::ValidateDemo');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Validate()
|
||||
|
||||
Validate Data
|
||||
|
||||
my $ValidateResult = $ValidateModuleObject->Validate(
|
||||
Data => {
|
||||
Queue => 'Raw',
|
||||
# ...
|
||||
},
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$ValidateResult = 1; # or undef, only returns 1 if Queue is 'Raw'
|
||||
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub Validate {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(Data)) {
|
||||
if ( !defined $Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# Check if we have Data to check against transitions conditions
|
||||
if ( !IsHashRefWithData( $Param{Data} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Data has no values!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $Param{Data}->{Queue} && $Param{Data}->{Queue} eq 'Raw' ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
Reference in New Issue
Block a user