init III
This commit is contained in:
896
Perl OTRS/Kernel/System/ITSMChange/ITSMCondition/Action.pm
Normal file
896
Perl OTRS/Kernel/System/ITSMChange/ITSMCondition/Action.pm
Normal file
@@ -0,0 +1,896 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::ITSMChange::ITSMCondition::Action;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our $ObjectManagerDisabled = 1;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ITSMChange::ITSMCondition::Action - condition action lib
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 ActionAdd()
|
||||
|
||||
Add a new condition action.
|
||||
|
||||
my $ActionID = $ConditionObject->ActionAdd(
|
||||
ConditionID => 123,
|
||||
ActionNumber => 5,
|
||||
ObjectID => 234,
|
||||
AttributeID => 345,
|
||||
OperatorID => 456,
|
||||
Selector => 1234,
|
||||
ActionValue => 'rejected',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ActionAdd {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(ConditionID ObjectID AttributeID OperatorID Selector UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# handle 'ActionValue' in a special way
|
||||
if ( !exists $Param{ActionValue} || !defined $Param{ActionValue} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need ActionValue!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get condition for event handler
|
||||
my $Condition = $Self->ConditionGet(
|
||||
ConditionID => $Param{ConditionID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check condition
|
||||
return if !$Condition;
|
||||
|
||||
# trigger ActionAddPre-Event
|
||||
$Self->EventHandler(
|
||||
Event => 'ActionAddPre',
|
||||
Data => {
|
||||
%Param,
|
||||
ChangeID => $Condition->{ChangeID},
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# get default action number if not given
|
||||
my $ActionNumber = delete $Param{ActionNumber};
|
||||
if ( !$ActionNumber ) {
|
||||
$ActionNumber = $Self->_CreateNewActionNumber(%Param);
|
||||
}
|
||||
|
||||
# add new action name to database
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => 'INSERT INTO condition_action '
|
||||
. '(condition_id, action_number, object_id, '
|
||||
. 'attribute_id, operator_id, selector, '
|
||||
. ' action_value) '
|
||||
. 'VALUES (?, ?, ?, ?, ?, ?, ?)',
|
||||
Bind => [
|
||||
\$Param{ConditionID}, \$ActionNumber, \$Param{ObjectID},
|
||||
\$Param{AttributeID}, \$Param{OperatorID}, \$Param{Selector},
|
||||
\$Param{ActionValue},
|
||||
],
|
||||
);
|
||||
|
||||
# prepare SQL statement
|
||||
my $ActionID;
|
||||
|
||||
# this is important for oracle for which an empty string and NULL is the same!
|
||||
if ( $Self->{DBType} eq 'oracle' && $Param{ActionValue} eq '' ) {
|
||||
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Prepare(
|
||||
SQL => 'SELECT id FROM condition_action '
|
||||
. 'WHERE condition_id = ? AND action_number = ? AND object_id = ? '
|
||||
. 'AND attribute_id = ? AND operator_id = ? AND selector = ? '
|
||||
. 'AND action_value IS NULL',
|
||||
Bind => [
|
||||
\$Param{ConditionID}, \$ActionNumber, \$Param{ObjectID},
|
||||
\$Param{AttributeID}, \$Param{OperatorID}, \$Param{Selector},
|
||||
],
|
||||
Limit => 1,
|
||||
);
|
||||
}
|
||||
|
||||
# for all other databases AND for oracle IF the action value is NOT an empty string
|
||||
else {
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Prepare(
|
||||
SQL => 'SELECT id FROM condition_action '
|
||||
. 'WHERE condition_id = ? AND action_number = ? AND object_id = ? '
|
||||
. 'AND attribute_id = ? AND operator_id = ? AND selector = ? '
|
||||
. 'AND action_value = ?',
|
||||
Bind => [
|
||||
\$Param{ConditionID}, \$ActionNumber, \$Param{ObjectID},
|
||||
\$Param{AttributeID}, \$Param{OperatorID}, \$Param{Selector},
|
||||
\$Param{ActionValue},
|
||||
],
|
||||
Limit => 1,
|
||||
);
|
||||
}
|
||||
|
||||
# get id of created action
|
||||
while ( my @Row = $Kernel::OM->Get('Kernel::System::DB')->FetchrowArray() ) {
|
||||
$ActionID = $Row[0];
|
||||
}
|
||||
|
||||
# check if action could be added
|
||||
if ( !$ActionID ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "ActionAdd() failed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# delete cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Delete(
|
||||
Type => $Self->{CacheType},
|
||||
Key => 'ActionList::ConditionID::' . $Param{ConditionID},
|
||||
);
|
||||
|
||||
# trigger ActionAddPost-Event
|
||||
$Self->EventHandler(
|
||||
Event => 'ActionAddPost',
|
||||
Data => {
|
||||
%Param,
|
||||
ChangeID => $Condition->{ChangeID},
|
||||
ActionID => $ActionID,
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
return $ActionID;
|
||||
}
|
||||
|
||||
=head2 ActionUpdate()
|
||||
|
||||
Update a condition action.
|
||||
|
||||
my $Success = $ConditionObject->ActionUpdate(
|
||||
ActionID => 1234,
|
||||
ActionNumber => 1, # (optional)
|
||||
ObjectID => 234, # (optional)
|
||||
AttributeID => 345, # (optional)
|
||||
OperatorID => 456, # (optional)
|
||||
Selector => 1234', # (optional)
|
||||
ActionValue => 'rejected', # (optional)
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ActionUpdate {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(ActionID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get action
|
||||
my $Action = $Self->ActionGet(
|
||||
ActionID => $Param{ActionID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check action
|
||||
return if !$Action;
|
||||
|
||||
# get condition for event handler
|
||||
my $Condition = $Self->ConditionGet(
|
||||
ConditionID => $Action->{ConditionID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check condition
|
||||
return if !$Condition;
|
||||
|
||||
# trigger ActionUpdatePre-Event
|
||||
$Self->EventHandler(
|
||||
Event => 'ActionUpdatePre',
|
||||
Data => {
|
||||
%Param,
|
||||
ChangeID => $Condition->{ChangeID},
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# map update attributes to column names
|
||||
my %Attribute = (
|
||||
ActionNumber => 'action_number',
|
||||
ObjectID => 'object_id',
|
||||
AttributeID => 'attribute_id',
|
||||
OperatorID => 'operator_id',
|
||||
Selector => 'selector',
|
||||
ActionValue => 'action_value',
|
||||
);
|
||||
|
||||
# build SQL to update action
|
||||
my $SQL = 'UPDATE condition_action SET ';
|
||||
my @Bind;
|
||||
|
||||
ATTRIBUTE:
|
||||
for my $Attribute ( sort keys %Attribute ) {
|
||||
|
||||
# preserve the old value, when the column isn't in function parameters
|
||||
next ATTRIBUTE if !exists $Param{$Attribute};
|
||||
next ATTRIBUTE if !defined $Param{$Attribute};
|
||||
|
||||
# param checking has already been done, so this is safe
|
||||
$SQL .= "$Attribute{$Attribute} = ?, ";
|
||||
push @Bind, \$Param{$Attribute};
|
||||
}
|
||||
|
||||
# set condition ID to allow trailing comma of previous loop
|
||||
$SQL .= ' condition_id = condition_id ';
|
||||
|
||||
# set matching of SQL statement
|
||||
$SQL .= 'WHERE id = ?';
|
||||
push @Bind, \$Param{ActionID};
|
||||
|
||||
# update action
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => $SQL,
|
||||
Bind => \@Bind,
|
||||
);
|
||||
|
||||
# delete cache
|
||||
for my $Key (
|
||||
'ActionList::ConditionID::' . $Action->{ConditionID},
|
||||
'ActionGet::' . $Param{ActionID},
|
||||
)
|
||||
{
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Delete(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $Key,
|
||||
);
|
||||
}
|
||||
|
||||
# trigger ActionUpdatePost-Event
|
||||
$Self->EventHandler(
|
||||
Event => 'ActionUpdatePost',
|
||||
Data => {
|
||||
%Param,
|
||||
ChangeID => $Condition->{ChangeID},
|
||||
OldActionData => $Action,
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 ActionGet()
|
||||
|
||||
Get a condition action for a given action id.
|
||||
Returns a hash reference of the action data.
|
||||
|
||||
my $ConditionActionRef = $ConditionObject->ActionGet(
|
||||
ActionID => 1234,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
The returned hash reference contains following elements:
|
||||
|
||||
$ConditionAction{ActionID}
|
||||
$ConditionAction{ConditionID}
|
||||
$ConditionAction{ActionNumber}
|
||||
$ConditionAction{ObjectID}
|
||||
$ConditionAction{AttributeID}
|
||||
$ConditionAction{OperatorID}
|
||||
$ConditionAction{Selector}
|
||||
$ConditionAction{ActionValue}
|
||||
|
||||
=cut
|
||||
|
||||
sub ActionGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(ActionID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check cache
|
||||
my $CacheKey = 'ActionGet::' . $Param{ActionID};
|
||||
my $Cache = $Kernel::OM->Get('Kernel::System::Cache')->Get(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if $Cache;
|
||||
|
||||
# prepare SQL statement
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Prepare(
|
||||
SQL => 'SELECT id, condition_id, action_number, object_id, '
|
||||
. 'attribute_id, operator_id, selector, action_value '
|
||||
. 'FROM condition_action WHERE id = ?',
|
||||
Bind => [ \$Param{ActionID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
|
||||
# fetch the result
|
||||
my %ActionData;
|
||||
while ( my @Row = $Kernel::OM->Get('Kernel::System::DB')->FetchrowArray() ) {
|
||||
$ActionData{ActionID} = $Row[0];
|
||||
$ActionData{ConditionID} = $Row[1];
|
||||
$ActionData{ActionNumber} = $Row[2];
|
||||
$ActionData{ObjectID} = $Row[3];
|
||||
$ActionData{AttributeID} = $Row[4];
|
||||
$ActionData{OperatorID} = $Row[5];
|
||||
$ActionData{Selector} = $Row[6];
|
||||
|
||||
# this is important for oracle for which an empty string and NULL is the same!
|
||||
$ActionData{ActionValue} = $Row[7] // '';
|
||||
}
|
||||
|
||||
# check error
|
||||
if ( !%ActionData ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "ActionID $Param{ActionID} does not exist!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# set cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Set(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $CacheKey,
|
||||
Value => \%ActionData,
|
||||
TTL => $Self->{CacheTTL},
|
||||
);
|
||||
|
||||
return \%ActionData;
|
||||
}
|
||||
|
||||
=head2 ActionList()
|
||||
|
||||
Returns a sorted list of all condition action
|
||||
ids for a given ConditionID as array reference.
|
||||
|
||||
my $ConditionActionIDsRef = $ConditionObject->ActionList(
|
||||
ConditionID => 1234,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ActionList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(ConditionID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check cache
|
||||
my $CacheKey = 'ActionList::ConditionID::' . $Param{ConditionID};
|
||||
my $Cache = $Kernel::OM->Get('Kernel::System::Cache')->Get(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if $Cache;
|
||||
|
||||
# prepare SQL statement
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Prepare(
|
||||
SQL => 'SELECT id FROM condition_action '
|
||||
. 'WHERE condition_id = ? '
|
||||
. 'ORDER BY action_number ASC',
|
||||
Bind => [ \$Param{ConditionID} ],
|
||||
);
|
||||
|
||||
# fetch the result
|
||||
my @ActionList;
|
||||
while ( my @Row = $Kernel::OM->Get('Kernel::System::DB')->FetchrowArray() ) {
|
||||
push @ActionList, $Row[0];
|
||||
}
|
||||
|
||||
# set cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Set(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $CacheKey,
|
||||
Value => \@ActionList,
|
||||
TTL => $Self->{CacheTTL},
|
||||
);
|
||||
|
||||
return \@ActionList;
|
||||
}
|
||||
|
||||
=head2 ActionDelete()
|
||||
|
||||
Deletes a condition action.
|
||||
|
||||
my $Success = $ConditionObject->ActionDelete(
|
||||
ActionID => 123,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ActionDelete {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(ActionID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get action
|
||||
my $Action = $Self->ActionGet(
|
||||
ActionID => $Param{ActionID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check action
|
||||
return if !$Action;
|
||||
|
||||
# get condition for event handler
|
||||
my $Condition = $Self->ConditionGet(
|
||||
ConditionID => $Action->{ConditionID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check condition
|
||||
return if !$Condition;
|
||||
|
||||
# trigger ActionDeletePre-Event
|
||||
$Self->EventHandler(
|
||||
Event => 'ActionDeletePre',
|
||||
Data => {
|
||||
%Param,
|
||||
ChangeID => $Condition->{ChangeID},
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# delete condition action from database
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => 'DELETE FROM condition_action '
|
||||
. 'WHERE id = ?',
|
||||
Bind => [ \$Param{ActionID} ],
|
||||
);
|
||||
|
||||
# delete cache
|
||||
for my $Key (
|
||||
'ActionList::ConditionID::' . $Action->{ConditionID},
|
||||
'ActionGet::' . $Param{ActionID},
|
||||
)
|
||||
{
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Delete(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $Key,
|
||||
);
|
||||
}
|
||||
|
||||
# trigger ActionDeletePost-Event
|
||||
$Self->EventHandler(
|
||||
Event => 'ActionDeletePost',
|
||||
Data => {
|
||||
%Param,
|
||||
ChangeID => $Condition->{ChangeID},
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 ActionDeleteAll()
|
||||
|
||||
Deletes all condition actions for a given condition id.
|
||||
|
||||
my $Success = $ConditionObject->ActionDeleteAll(
|
||||
ConditionID => 123,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ActionDeleteAll {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(ConditionID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get condition for event handler
|
||||
my $Condition = $Self->ConditionGet(
|
||||
ConditionID => $Param{ConditionID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check condition
|
||||
return if !$Condition;
|
||||
|
||||
# get all actions for the given condition id
|
||||
my $ActionIDsRef = $Self->ActionList(
|
||||
ConditionID => $Param{ConditionID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# trigger ActionDeleteAllPre-Event
|
||||
$Self->EventHandler(
|
||||
Event => 'ActionDeleteAllPre',
|
||||
Data => {
|
||||
%Param,
|
||||
ChangeID => $Condition->{ChangeID},
|
||||
ConditionID => $Param{ConditionID},
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# delete condition actions from database
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => 'DELETE FROM condition_action '
|
||||
. 'WHERE condition_id = ?',
|
||||
Bind => [ \$Param{ConditionID} ],
|
||||
);
|
||||
|
||||
# delete cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Delete(
|
||||
Type => $Self->{CacheType},
|
||||
Key => 'ActionList::ConditionID::' . $Param{ConditionID},
|
||||
);
|
||||
|
||||
# delete cache
|
||||
if ( $ActionIDsRef && @{$ActionIDsRef} ) {
|
||||
for my $ActionID ( @{$ActionIDsRef} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Delete(
|
||||
Type => $Self->{CacheType},
|
||||
Key => 'ActionGet::' . $ActionID,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
# trigger ActionDeleteAllPost-Event
|
||||
$Self->EventHandler(
|
||||
Event => 'ActionDeleteAllPost',
|
||||
Data => {
|
||||
%Param,
|
||||
ChangeID => $Condition->{ChangeID},
|
||||
ConditionID => $Param{ConditionID},
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 ActionExecute()
|
||||
|
||||
Returns the success value of the execution of an action.
|
||||
|
||||
my $Success = $ConditionObject->ActionExecute(
|
||||
ActionID => 123,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ActionExecute {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(ActionID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get action content
|
||||
my $Action = $Self->ActionGet(
|
||||
ActionID => $Param{ActionID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check action content
|
||||
return if !$Action;
|
||||
|
||||
# get condition for event handler
|
||||
my $Condition = $Self->ConditionGet(
|
||||
ConditionID => $Action->{ConditionID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check condition
|
||||
return if !$Condition;
|
||||
|
||||
# get action attributes
|
||||
my $ActionData = $Self->_ActionExecuteInit(
|
||||
Action => $Action,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check action attributes
|
||||
return if !$ActionData;
|
||||
|
||||
# do not execute 'lock' actions, they are passive!
|
||||
my @OmitActions = qw( lock );
|
||||
return 0 if grep { $ActionData->{Operator}->{Name} eq $_ } @OmitActions;
|
||||
|
||||
# trigger ActionExecutePre-Event
|
||||
$Self->EventHandler(
|
||||
Event => 'ActionExecutePre',
|
||||
Data => {
|
||||
%Param,
|
||||
%{$Condition},
|
||||
ConditionName => $Condition->{Name},
|
||||
ChangeID => $Condition->{ChangeID},
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# get object name
|
||||
my $ObjectName = $ActionData->{Object}->{Name};
|
||||
|
||||
# get object data
|
||||
my $ActionObjectData = $Self->ObjectDataGet(
|
||||
ConditionID => $Action->{ConditionID},
|
||||
ObjectName => $ObjectName,
|
||||
Selector => $Action->{Selector},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check for action object data
|
||||
# no need to execute operator if it is an empty array ref
|
||||
if (
|
||||
!$ActionObjectData
|
||||
|| ref $ActionObjectData ne 'ARRAY'
|
||||
|| ref $ActionObjectData eq 'ARRAY' && !@{$ActionObjectData}
|
||||
)
|
||||
{
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "No object data for $ObjectName ($Action->{Selector}) found!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get attribute type
|
||||
my $AttributeType = $ActionData->{Attribute}->{Name};
|
||||
|
||||
# check attribute type
|
||||
if ( !$AttributeType ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "No attribute $ObjectName ($Action->{Selector}) found!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# check for object attribute
|
||||
for my $ActionObject ( @{$ActionObjectData} ) {
|
||||
if ( !exists $ActionObject->{$AttributeType} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "No object attribute for $ObjectName ($AttributeType) found!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# define operator values
|
||||
my %OperatorExecute = (
|
||||
OperatorName => $ActionData->{Operator}->{Name},
|
||||
ObjectData => $ActionObjectData,
|
||||
ObjectName => $ObjectName,
|
||||
Selector => $Action->{Selector},
|
||||
Attribute => $AttributeType,
|
||||
ActionValue => $Action->{ActionValue},
|
||||
ActionID => $Action->{ActionID},
|
||||
);
|
||||
|
||||
# return result of the actions execution
|
||||
my $Result = $Self->OperatorExecute(
|
||||
%OperatorExecute,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# get nice action result
|
||||
my $ActionResult = ($Result) ? 'successfully' : 'unsuccessfully';
|
||||
|
||||
# trigger ActionExecutePost-Event
|
||||
$Self->EventHandler(
|
||||
Event => 'ActionExecutePost',
|
||||
Data => {
|
||||
%Param,
|
||||
%{$Condition},
|
||||
ConditionName => $Condition->{Name},
|
||||
%OperatorExecute,
|
||||
ChangeID => $Condition->{ChangeID},
|
||||
ActionResult => $ActionResult,
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# return result of the actions execution
|
||||
return $Result;
|
||||
}
|
||||
|
||||
=head1 PRIVATE INTERFACE
|
||||
|
||||
=head2 _ActionExecuteInit()
|
||||
|
||||
Returns object, attribute and operator of a given action.
|
||||
|
||||
my $ActionData = $ConditionObject->_ActionExecuteInit(
|
||||
Action => $ActionRef,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub _ActionExecuteInit {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# extract action
|
||||
my $Action = $Param{Action};
|
||||
|
||||
# declare action data
|
||||
my %ActionData;
|
||||
|
||||
# get object data
|
||||
$ActionData{Object} = $Self->ObjectGet(
|
||||
ObjectID => $Action->{ObjectID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check for object data
|
||||
if ( !$ActionData{Object} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "No value for 'Object' with ID '$Action->{ObjectID}'!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get attribute data
|
||||
$ActionData{Attribute} = $Self->AttributeGet(
|
||||
AttributeID => $Action->{AttributeID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check for attribute data
|
||||
if ( !$ActionData{Attribute} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "No value for 'Attribute' with ID '$Action->{AttributeID}'!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get operator data
|
||||
$ActionData{Operator} = $Self->OperatorGet(
|
||||
OperatorID => $Action->{OperatorID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check for operator data
|
||||
if ( !$ActionData{Operator} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "No value for 'Operator' with ID '$Action->{OperatorID}'!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
return \%ActionData;
|
||||
}
|
||||
|
||||
=head2 _CreateNewActionNumber()
|
||||
|
||||
Create a new unused action number for the given condition.
|
||||
The highest current action number for the given condition is
|
||||
looked up and incremented by one.
|
||||
|
||||
my $ActionNumber = $ConditionObject->_CreateNewActionNumber(
|
||||
ConditionID => 123,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub _CreateNewActionNumber {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
if ( !$Param{ConditionID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need ConditionID!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get the largest action number
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Prepare(
|
||||
SQL => 'SELECT MAX(action_number) '
|
||||
. 'FROM condition_action '
|
||||
. 'WHERE condition_id = ?',
|
||||
Bind => [ \$Param{ConditionID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
|
||||
# fetch the result, default to 0 when there are no actions yet
|
||||
my $ActionNumber;
|
||||
while ( my @Row = $Kernel::OM->Get('Kernel::System::DB')->FetchrowArray() ) {
|
||||
$ActionNumber = $Row[0];
|
||||
}
|
||||
$ActionNumber ||= 0;
|
||||
|
||||
# increment number to get a non-existent action number
|
||||
$ActionNumber++;
|
||||
|
||||
return $ActionNumber;
|
||||
}
|
||||
|
||||
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
|
||||
459
Perl OTRS/Kernel/System/ITSMChange/ITSMCondition/Attribute.pm
Normal file
459
Perl OTRS/Kernel/System/ITSMChange/ITSMCondition/Attribute.pm
Normal file
@@ -0,0 +1,459 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::ITSMChange::ITSMCondition::Attribute;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
# IMPORTANT!
|
||||
# Do not delete this line! This prevents the "Frontend/Basic" UnitTest from failing
|
||||
# on opensuse 11.3 and 11.4 (64bit) if mod_perl is used!
|
||||
## nofilter(TidyAll::Plugin::OTRS::Common::RemoveCVSIDs)
|
||||
use vars qw($VERSION);
|
||||
|
||||
our $ObjectManagerDisabled = 1;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ITSMChange::ITSMCondition::Attribute - condition attribute lib
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 AttributeAdd()
|
||||
|
||||
Add a new condition attribute.
|
||||
|
||||
my $AttributeID = $ConditionObject->AttributeAdd(
|
||||
Name => 'AttributeName',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub AttributeAdd {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Name UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# make lookup with given name for checks
|
||||
my $AttributeID = $Self->AttributeLookup(
|
||||
Name => $Param{Name},
|
||||
);
|
||||
|
||||
# check if attribute name already exists
|
||||
if ($AttributeID) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Condition attribute ($Param{Name}) already exists!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# add new attribute name to database
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => 'INSERT INTO condition_attribute '
|
||||
. '(name) '
|
||||
. 'VALUES (?)',
|
||||
Bind => [ \$Param{Name} ],
|
||||
);
|
||||
|
||||
# get id of created attribute
|
||||
$AttributeID = $Self->AttributeLookup(
|
||||
Name => $Param{Name},
|
||||
);
|
||||
|
||||
# check if attribute could be added
|
||||
if ( !$AttributeID ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "AttributeAdd() failed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# delete cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Delete(
|
||||
Type => $Self->{CacheType},
|
||||
Key => 'AttributeList',
|
||||
);
|
||||
|
||||
return $AttributeID;
|
||||
}
|
||||
|
||||
=head2 AttributeUpdate()
|
||||
|
||||
Update a condition attribute.
|
||||
|
||||
my $Success = $ConditionObject->AttributeUpdate(
|
||||
AttributeID => 1234,
|
||||
Name => 'NewAttributeName',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub AttributeUpdate {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(AttributeID Name UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get attribute data
|
||||
my $AttributeData = $Self->AttributeGet(
|
||||
AttributeID => $Param{AttributeID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check attribute data
|
||||
if ( !$AttributeData ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "AttributeUpdate of $Param{AttributeID} failed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# update attribute in database
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => 'UPDATE condition_attribute '
|
||||
. 'SET name = ? '
|
||||
. 'WHERE id = ?',
|
||||
Bind => [
|
||||
\$Param{Name},
|
||||
\$Param{AttributeID},
|
||||
],
|
||||
);
|
||||
|
||||
# delete cache
|
||||
for my $Key (
|
||||
'AttributeList',
|
||||
'AttributeGet::AttributeID::' . $Param{AttributeID},
|
||||
'AttributeLookup::AttributeID::' . $Param{AttributeID},
|
||||
'AttributeLookup::Name::' . $AttributeData->{Name}, # use the old name
|
||||
)
|
||||
{
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Delete(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $Key,
|
||||
);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 AttributeGet()
|
||||
|
||||
Get a condition attribute for a given attribute id.
|
||||
Returns a hash reference of the attribute data.
|
||||
|
||||
my $ConditionAttributeRef = $ConditionObject->AttributeGet(
|
||||
AttributeID => 1234,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
The returned hash reference contains following elements:
|
||||
|
||||
$ConditionAttribute{AttributeID}
|
||||
$ConditionAttribute{Name}
|
||||
|
||||
=cut
|
||||
|
||||
sub AttributeGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(AttributeID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check cache
|
||||
my $CacheKey = 'AttributeGet::AttributeID::' . $Param{AttributeID};
|
||||
my $Cache = $Kernel::OM->Get('Kernel::System::Cache')->Get(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if $Cache;
|
||||
|
||||
# prepare SQL statement
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Prepare(
|
||||
SQL => 'SELECT id, name FROM condition_attribute WHERE id = ?',
|
||||
Bind => [ \$Param{AttributeID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
|
||||
# fetch the result
|
||||
my %AttributeData;
|
||||
while ( my @Row = $Kernel::OM->Get('Kernel::System::DB')->FetchrowArray() ) {
|
||||
$AttributeData{AttributeID} = $Row[0];
|
||||
$AttributeData{Name} = $Row[1];
|
||||
}
|
||||
|
||||
# check error
|
||||
if ( !%AttributeData ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "AttributeID $Param{AttributeID} does not exist!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# set cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Set(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $CacheKey,
|
||||
Value => \%AttributeData,
|
||||
TTL => $Self->{CacheTTL},
|
||||
);
|
||||
|
||||
return \%AttributeData;
|
||||
}
|
||||
|
||||
=head2 AttributeLookup()
|
||||
|
||||
This method does a lookup for a condition attribute. If an attribute
|
||||
id is given, it returns the name of the attribute. If the name of the
|
||||
attribute is given, the appropriate id is returned.
|
||||
|
||||
my $AttributeName = $ConditionObject->AttributeLookup(
|
||||
AttributeID => 4321,
|
||||
);
|
||||
|
||||
my $AttributeID = $ConditionObject->AttributeLookup(
|
||||
Name => 'AttributeName',
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub AttributeLookup {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check if both parameters are given
|
||||
if ( $Param{AttributeID} && $Param{Name} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need AttributeID or Name - not both!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# check if both parameters are not given
|
||||
if ( !$Param{AttributeID} && !$Param{Name} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need AttributeID or Name - none is given!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# check if AttributeID is a number
|
||||
if ( $Param{AttributeID} && $Param{AttributeID} !~ m{ \A \d+ \z }xms ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "AttributeID must be a number! (AttributeID: $Param{AttributeID})",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
my $CacheKey;
|
||||
|
||||
# prepare SQL statements
|
||||
if ( $Param{AttributeID} ) {
|
||||
|
||||
# check cache
|
||||
$CacheKey = 'AttributeLookup::AttributeID::' . $Param{AttributeID};
|
||||
my $Cache = $Kernel::OM->Get('Kernel::System::Cache')->Get(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if $Cache;
|
||||
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Prepare(
|
||||
SQL => 'SELECT name FROM condition_attribute WHERE id = ?',
|
||||
Bind => [ \$Param{AttributeID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
}
|
||||
elsif ( $Param{Name} ) {
|
||||
|
||||
# check cache
|
||||
$CacheKey = 'AttributeLookup::Name::' . $Param{Name};
|
||||
my $Cache = $Kernel::OM->Get('Kernel::System::Cache')->Get(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if $Cache;
|
||||
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Prepare(
|
||||
SQL => 'SELECT id FROM condition_attribute WHERE name = ?',
|
||||
Bind => [ \$Param{Name} ],
|
||||
Limit => 1,
|
||||
);
|
||||
}
|
||||
|
||||
# fetch the result
|
||||
my $Lookup = '';
|
||||
while ( my @Row = $Kernel::OM->Get('Kernel::System::DB')->FetchrowArray() ) {
|
||||
$Lookup = $Row[0];
|
||||
}
|
||||
|
||||
# set cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Set(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $CacheKey,
|
||||
Value => $Lookup,
|
||||
TTL => $Self->{CacheTTL},
|
||||
);
|
||||
|
||||
return $Lookup;
|
||||
}
|
||||
|
||||
=head2 AttributeList()
|
||||
|
||||
Returns a list of all condition attributes as hash reference
|
||||
|
||||
my $ConditionAttributesRef = $ConditionObject->AttributeList(
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
The returned hash reference contains entries like this:
|
||||
|
||||
$ConditionAttribute{AttributeID} = 'AttributeName'
|
||||
|
||||
=cut
|
||||
|
||||
sub AttributeList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need UserID!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# check cache
|
||||
my $CacheKey = 'AttributeList';
|
||||
my $Cache = $Kernel::OM->Get('Kernel::System::Cache')->Get(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if $Cache;
|
||||
|
||||
# prepare SQL statement
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Prepare(
|
||||
SQL => 'SELECT id, name FROM condition_attribute',
|
||||
);
|
||||
|
||||
# fetch the result
|
||||
my %AttributeList;
|
||||
while ( my @Row = $Kernel::OM->Get('Kernel::System::DB')->FetchrowArray() ) {
|
||||
$AttributeList{ $Row[0] } = $Row[1];
|
||||
}
|
||||
|
||||
# set cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Set(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $CacheKey,
|
||||
Value => \%AttributeList,
|
||||
TTL => $Self->{CacheTTL},
|
||||
);
|
||||
|
||||
return \%AttributeList;
|
||||
}
|
||||
|
||||
=head2 AttributeDelete()
|
||||
|
||||
Deletes a condition attribute.
|
||||
|
||||
my $Success = $ConditionObject->AttributeDelete(
|
||||
AttributeID => 123,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub AttributeDelete {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(AttributeID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# lookup attribute name
|
||||
my $AttributeName = $Self->AttributeLookup(
|
||||
AttributeID => $Param{AttributeID},
|
||||
);
|
||||
|
||||
# delete condition attribute from database
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => 'DELETE FROM condition_attribute '
|
||||
. 'WHERE id = ?',
|
||||
Bind => [ \$Param{AttributeID} ],
|
||||
);
|
||||
|
||||
# delete cache
|
||||
for my $Key (
|
||||
'AttributeList',
|
||||
'AttributeGet::AttributeID::' . $Param{AttributeID},
|
||||
'AttributeLookup::AttributeID::' . $Param{AttributeID},
|
||||
'AttributeLookup::Name::' . $AttributeName,
|
||||
)
|
||||
{
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Delete(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $Key,
|
||||
);
|
||||
}
|
||||
|
||||
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
|
||||
822
Perl OTRS/Kernel/System/ITSMChange/ITSMCondition/Expression.pm
Normal file
822
Perl OTRS/Kernel/System/ITSMChange/ITSMCondition/Expression.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::ITSMChange::ITSMCondition::Expression;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our $ObjectManagerDisabled = 1;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ITSMChange::ITSMCondition::Expression - condition expression lib
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 ExpressionAdd()
|
||||
|
||||
Add a new condition expression.
|
||||
|
||||
my $ExpressionID = $ConditionObject->ExpressionAdd(
|
||||
ConditionID => 123,
|
||||
ObjectID => 234,
|
||||
AttributeID => 345,
|
||||
OperatorID => 456,
|
||||
Selector => 1234,
|
||||
CompareValue => 'rejected',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ExpressionAdd {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(ConditionID ObjectID AttributeID OperatorID Selector UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# handle 'CompareValue' in a special way
|
||||
if ( !exists $Param{CompareValue} || !defined $Param{CompareValue} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need CompareValue!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get condition for event handler
|
||||
my $Condition = $Self->ConditionGet(
|
||||
ConditionID => $Param{ConditionID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check condition
|
||||
return if !$Condition;
|
||||
|
||||
# trigger ExpressionAddPre-Event
|
||||
$Self->EventHandler(
|
||||
Event => 'ExpressionAddPre',
|
||||
Data => {
|
||||
%Param,
|
||||
ChangeID => $Condition->{ChangeID},
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# add new expression name to database
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => 'INSERT INTO condition_expression '
|
||||
. '(condition_id, object_id, attribute_id, '
|
||||
. 'operator_id, selector, compare_value) '
|
||||
. 'VALUES (?, ?, ?, ?, ?, ?)',
|
||||
Bind => [
|
||||
\$Param{ConditionID}, \$Param{ObjectID}, \$Param{AttributeID},
|
||||
\$Param{OperatorID}, \$Param{Selector}, \$Param{CompareValue},
|
||||
],
|
||||
);
|
||||
|
||||
# prepare SQL statement
|
||||
my $ExpressionID;
|
||||
|
||||
# this is important for oracle for which an empty string and NULL is the same!
|
||||
if ( $Self->{DBType} eq 'oracle' && $Param{CompareValue} eq '' ) {
|
||||
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Prepare(
|
||||
SQL => 'SELECT id FROM condition_expression '
|
||||
. 'WHERE condition_id = ? AND object_id = ? AND attribute_id = ? '
|
||||
. 'AND operator_id = ? AND selector = ? AND compare_value IS NULL',
|
||||
Bind => [
|
||||
\$Param{ConditionID}, \$Param{ObjectID}, \$Param{AttributeID},
|
||||
\$Param{OperatorID}, \$Param{Selector},
|
||||
],
|
||||
Limit => 1,
|
||||
);
|
||||
}
|
||||
|
||||
# for all other databases AND for oracle IF the compare value is NOT an empty string
|
||||
else {
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Prepare(
|
||||
SQL => 'SELECT id FROM condition_expression '
|
||||
. 'WHERE condition_id = ? AND object_id = ? AND attribute_id = ? '
|
||||
. 'AND operator_id = ? AND selector = ? AND compare_value = ?',
|
||||
Bind => [
|
||||
\$Param{ConditionID}, \$Param{ObjectID}, \$Param{AttributeID},
|
||||
\$Param{OperatorID}, \$Param{Selector}, \$Param{CompareValue},
|
||||
],
|
||||
Limit => 1,
|
||||
);
|
||||
}
|
||||
|
||||
# get id of created expression
|
||||
while ( my @Row = $Kernel::OM->Get('Kernel::System::DB')->FetchrowArray() ) {
|
||||
$ExpressionID = $Row[0];
|
||||
}
|
||||
|
||||
# check if expression could be added
|
||||
if ( !$ExpressionID ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "ExpressionAdd() failed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# delete cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Delete(
|
||||
Type => $Self->{CacheType},
|
||||
Key => 'ExpressionList::ConditionID::' . $Param{ConditionID},
|
||||
);
|
||||
|
||||
# trigger ExpressionAddPost-Event
|
||||
$Self->EventHandler(
|
||||
Event => 'ExpressionAddPost',
|
||||
Data => {
|
||||
%Param,
|
||||
ChangeID => $Condition->{ChangeID},
|
||||
ExpressionID => $ExpressionID,
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
return $ExpressionID;
|
||||
}
|
||||
|
||||
=head2 ExpressionUpdate()
|
||||
|
||||
Update a condition expression.
|
||||
|
||||
my $Success = $ConditionObject->ExpressionUpdate(
|
||||
ExpressionID => 1234,
|
||||
ObjectID => 234, # (optional)
|
||||
AttributeID => 345, # (optional)
|
||||
OperatorID => 456, # (optional)
|
||||
Selector => 1234, # (optional)
|
||||
CompareValue => 'rejected', # (optional)
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ExpressionUpdate {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(ExpressionID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get expression
|
||||
my $Expression = $Self->ExpressionGet(
|
||||
ExpressionID => $Param{ExpressionID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check expression
|
||||
return if !$Expression;
|
||||
|
||||
# get condition for event handler
|
||||
my $Condition = $Self->ConditionGet(
|
||||
ConditionID => $Expression->{ConditionID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check condition
|
||||
return if !$Condition;
|
||||
|
||||
# trigger ExpressionUpdatePre-Event
|
||||
$Self->EventHandler(
|
||||
Event => 'ExpressionUpdatePre',
|
||||
Data => {
|
||||
%Param,
|
||||
ChangeID => $Condition->{ChangeID},
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# map update attributes to column names
|
||||
my %Attribute = (
|
||||
ObjectID => 'object_id',
|
||||
AttributeID => 'attribute_id',
|
||||
OperatorID => 'operator_id',
|
||||
Selector => 'selector',
|
||||
CompareValue => 'compare_value',
|
||||
);
|
||||
|
||||
# build SQL to update expression
|
||||
my $SQL = 'UPDATE condition_expression SET ';
|
||||
my @Bind;
|
||||
|
||||
ATTRIBUTE:
|
||||
for my $Attribute ( sort keys %Attribute ) {
|
||||
|
||||
# preserve the old value, when the column isn't in function parameters
|
||||
next ATTRIBUTE if !exists $Param{$Attribute};
|
||||
next ATTRIBUTE if !defined $Param{$Attribute};
|
||||
|
||||
# param checking has already been done, so this is safe
|
||||
$SQL .= "$Attribute{$Attribute} = ?, ";
|
||||
push @Bind, \$Param{$Attribute};
|
||||
}
|
||||
|
||||
# set condition ID to allow trailing comma of previous loop
|
||||
$SQL .= ' condition_id = condition_id ';
|
||||
|
||||
# set matching of SQL statement
|
||||
$SQL .= 'WHERE id = ?';
|
||||
push @Bind, \$Param{ExpressionID};
|
||||
|
||||
# update expression
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => $SQL,
|
||||
Bind => \@Bind,
|
||||
);
|
||||
|
||||
# delete cache
|
||||
for my $Key (
|
||||
'ExpressionList::ConditionID::' . $Expression->{ConditionID},
|
||||
'ExpressionGet::' . $Param{ExpressionID},
|
||||
)
|
||||
{
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Delete(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $Key,
|
||||
);
|
||||
}
|
||||
|
||||
# trigger ExpressionUpdatePost-Event
|
||||
$Self->EventHandler(
|
||||
Event => 'ExpressionUpdatePost',
|
||||
Data => {
|
||||
%Param,
|
||||
ChangeID => $Condition->{ChangeID},
|
||||
OldExpressionData => $Expression,
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 ExpressionGet()
|
||||
|
||||
Get a condition expression for a given expression id.
|
||||
Returns a hash reference of the expression data.
|
||||
|
||||
my $ConditionExpressionRef = $ConditionObject->ExpressionGet(
|
||||
ExpressionID => 1234,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
The returned hash reference contains following elements:
|
||||
|
||||
$ConditionExpression{ExpressionID}
|
||||
$ConditionExpression{ConditionID}
|
||||
$ConditionExpression{ObjectID}
|
||||
$ConditionExpression{AttributeID}
|
||||
$ConditionExpression{OperatorID}
|
||||
$ConditionExpression{Selector}
|
||||
$ConditionExpression{CompareValue}
|
||||
|
||||
=cut
|
||||
|
||||
sub ExpressionGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(ExpressionID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check cache
|
||||
my $CacheKey = 'ExpressionGet::' . $Param{ExpressionID};
|
||||
my $Cache = $Kernel::OM->Get('Kernel::System::Cache')->Get(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if $Cache;
|
||||
|
||||
# prepare SQL statement
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Prepare(
|
||||
SQL => 'SELECT id, condition_id, object_id, attribute_id, '
|
||||
. 'operator_id, selector, compare_value '
|
||||
. 'FROM condition_expression WHERE id = ?',
|
||||
Bind => [ \$Param{ExpressionID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
|
||||
# fetch the result
|
||||
my %ExpressionData;
|
||||
while ( my @Row = $Kernel::OM->Get('Kernel::System::DB')->FetchrowArray() ) {
|
||||
$ExpressionData{ExpressionID} = $Row[0];
|
||||
$ExpressionData{ConditionID} = $Row[1];
|
||||
$ExpressionData{ObjectID} = $Row[2];
|
||||
$ExpressionData{AttributeID} = $Row[3];
|
||||
$ExpressionData{OperatorID} = $Row[4];
|
||||
$ExpressionData{Selector} = $Row[5];
|
||||
|
||||
# this is important for oracle for which an empty string and NULL is the same!
|
||||
$ExpressionData{CompareValue} = $Row[6] // '';
|
||||
}
|
||||
|
||||
# check error
|
||||
if ( !%ExpressionData ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "ExpressionID $Param{ExpressionID} does not exist!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# set cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Set(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $CacheKey,
|
||||
Value => \%ExpressionData,
|
||||
TTL => $Self->{CacheTTL},
|
||||
);
|
||||
|
||||
return \%ExpressionData;
|
||||
}
|
||||
|
||||
=head2 ExpressionList()
|
||||
|
||||
Returns a list of all condition expression ids for
|
||||
a given ConditionID as array reference.
|
||||
|
||||
my $ConditionExpressionIDsRef = $ConditionObject->ExpressionList(
|
||||
ConditionID => 1234,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ExpressionList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(ConditionID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check cache
|
||||
my $CacheKey = 'ExpressionList::ConditionID::' . $Param{ConditionID};
|
||||
my $Cache = $Kernel::OM->Get('Kernel::System::Cache')->Get(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if $Cache;
|
||||
|
||||
# prepare SQL statement
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Prepare(
|
||||
SQL => 'SELECT id FROM condition_expression '
|
||||
. 'WHERE condition_id = ?',
|
||||
Bind => [ \$Param{ConditionID} ],
|
||||
);
|
||||
|
||||
# fetch the result
|
||||
my @ExpressionList;
|
||||
while ( my @Row = $Kernel::OM->Get('Kernel::System::DB')->FetchrowArray() ) {
|
||||
push @ExpressionList, $Row[0];
|
||||
}
|
||||
|
||||
# set cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Set(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $CacheKey,
|
||||
Value => \@ExpressionList,
|
||||
TTL => $Self->{CacheTTL},
|
||||
);
|
||||
|
||||
return \@ExpressionList;
|
||||
}
|
||||
|
||||
=head2 ExpressionDelete()
|
||||
|
||||
Deletes a condition expression.
|
||||
|
||||
my $Success = $ConditionObject->ExpressionDelete(
|
||||
ExpressionID => 123,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ExpressionDelete {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(ExpressionID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get expression
|
||||
my $Expression = $Self->ExpressionGet(
|
||||
ExpressionID => $Param{ExpressionID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check expression
|
||||
return if !$Expression;
|
||||
|
||||
# get condition for event handler
|
||||
my $Condition = $Self->ConditionGet(
|
||||
ConditionID => $Expression->{ConditionID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check condition
|
||||
return if !$Condition;
|
||||
|
||||
# trigger ExpressionDeletePre-Event
|
||||
$Self->EventHandler(
|
||||
Event => 'ExpressionDeletePre',
|
||||
Data => {
|
||||
%Param,
|
||||
ChangeID => $Condition->{ChangeID},
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# delete condition expression from database
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => 'DELETE FROM condition_expression '
|
||||
. 'WHERE id = ?',
|
||||
Bind => [ \$Param{ExpressionID} ],
|
||||
);
|
||||
|
||||
# delete cache
|
||||
for my $Key (
|
||||
'ExpressionList::ConditionID::' . $Expression->{ConditionID},
|
||||
'ExpressionGet::' . $Param{ExpressionID},
|
||||
)
|
||||
{
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Delete(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $Key,
|
||||
);
|
||||
}
|
||||
|
||||
# trigger ExpressionDeletePost-Event
|
||||
$Self->EventHandler(
|
||||
Event => 'ExpressionDeletePost',
|
||||
Data => {
|
||||
%Param,
|
||||
ChangeID => $Condition->{ChangeID},
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 ExpressionDeleteAll()
|
||||
|
||||
Deletes all condition expressions for a given condition id.
|
||||
|
||||
my $Success = $ConditionObject->ExpressionDeleteAll(
|
||||
ConditionID => 123,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ExpressionDeleteAll {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(ConditionID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get condition for event handler
|
||||
my $Condition = $Self->ConditionGet(
|
||||
ConditionID => $Param{ConditionID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check condition
|
||||
return if !$Condition;
|
||||
|
||||
# get all expressions for the given condition id
|
||||
my $ExpressionIDsRef = $Self->ExpressionList(
|
||||
ConditionID => $Param{ConditionID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# trigger ExpressionDeleteAllPre-Event
|
||||
$Self->EventHandler(
|
||||
Event => 'ExpressionDeleteAllPre',
|
||||
Data => {
|
||||
%Param,
|
||||
ChangeID => $Condition->{ChangeID},
|
||||
ConditionID => $Param{ConditionID},
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# delete condition expressions from database
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => 'DELETE FROM condition_expression '
|
||||
. 'WHERE condition_id = ?',
|
||||
Bind => [ \$Param{ConditionID} ],
|
||||
);
|
||||
|
||||
# delete cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Delete(
|
||||
Type => $Self->{CacheType},
|
||||
Key => 'ExpressionList::ConditionID::' . $Param{ConditionID},
|
||||
);
|
||||
|
||||
# delete cache
|
||||
if ( $ExpressionIDsRef && @{$ExpressionIDsRef} ) {
|
||||
for my $ExpressionID ( @{$ExpressionIDsRef} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Delete(
|
||||
Type => $Self->{CacheType},
|
||||
Key => 'ExpressionGet::' . $ExpressionID,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
# trigger ExpressionDeleteAllPost-Event
|
||||
$Self->EventHandler(
|
||||
Event => 'ExpressionDeleteAllPost',
|
||||
Data => {
|
||||
%Param,
|
||||
ChangeID => $Condition->{ChangeID},
|
||||
ConditionID => $Param{ConditionID},
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 ExpressionMatch()
|
||||
|
||||
Returns the boolean value of an expression.
|
||||
|
||||
my $Match = $ConditionObject->ExpressionMatch(
|
||||
ExpressionID => 123,
|
||||
AttributesChanged => { ITSMChange => [ ChangeTitle, ChangeDescription ] }, # (optional)
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ExpressionMatch {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(ExpressionID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get expression content
|
||||
my $Expression = $Self->ExpressionGet(
|
||||
ExpressionID => $Param{ExpressionID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check expression content
|
||||
return if !$Expression;
|
||||
|
||||
# get expression attributes
|
||||
my $ExpressionData = $Self->_ExpressionMatchInit(
|
||||
Expression => $Expression,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check expression attributes
|
||||
return if !$ExpressionData;
|
||||
|
||||
# get changed attributes
|
||||
my $AttributesChangedType;
|
||||
my @AttributesChanged;
|
||||
if ( exists $Param{AttributesChanged} && defined $Param{AttributesChanged} ) {
|
||||
|
||||
# changed attributes
|
||||
my %AttributeChanged;
|
||||
|
||||
# check for reference type
|
||||
if ( ref $Param{AttributesChanged} eq 'HASH' ) {
|
||||
%AttributeChanged = %{ $Param{AttributesChanged} };
|
||||
|
||||
# get attribute type
|
||||
$AttributesChangedType = ( keys %AttributeChanged )[0];
|
||||
}
|
||||
|
||||
# check for reference type
|
||||
if ( $AttributesChangedType && ref $AttributeChanged{$AttributesChangedType} eq 'ARRAY' ) {
|
||||
|
||||
# get list of changed attributes
|
||||
@AttributesChanged = @{ $AttributeChanged{$AttributesChangedType} };
|
||||
}
|
||||
}
|
||||
|
||||
# get object name
|
||||
my $ObjectName = $ExpressionData->{Object}->{Name};
|
||||
|
||||
# check for changed attributes types
|
||||
if ( $AttributesChangedType && $AttributesChangedType ne $ObjectName ) {
|
||||
|
||||
# this expression does not match requested type
|
||||
return;
|
||||
}
|
||||
|
||||
# get attribute type
|
||||
my $AttributeType = $ExpressionData->{Attribute}->{Name};
|
||||
|
||||
# check for changed attributes and available attributes of expression
|
||||
if ( $AttributeType && @AttributesChanged ) {
|
||||
|
||||
# check for our attribute in changed attribute list
|
||||
my @AttributeFound = grep { $_ eq $AttributeType } @AttributesChanged;
|
||||
|
||||
# this expression does not have the requested attribute
|
||||
return if !@AttributeFound;
|
||||
}
|
||||
|
||||
# get object data
|
||||
my $ExpressionObjectData = $Self->ObjectDataGet(
|
||||
ConditionID => $Expression->{ConditionID},
|
||||
ObjectName => $ObjectName,
|
||||
Selector => $Expression->{Selector},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check for expression object data
|
||||
# no need to execute operator if it is an empty array ref
|
||||
if (
|
||||
!$ExpressionObjectData
|
||||
|| ref $ExpressionObjectData ne 'ARRAY'
|
||||
|| ref $ExpressionObjectData eq 'ARRAY' && !@{$ExpressionObjectData}
|
||||
)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
# check attribute type
|
||||
if ( !$AttributeType ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "No attribute $ObjectName ($Expression->{Selector}) found!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# check for object attribute
|
||||
for my $ExpressionObject ( @{$ExpressionObjectData} ) {
|
||||
if ( !exists $ExpressionObject->{$AttributeType} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "No object attribute for $ObjectName ($AttributeType) found!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# return result of the expressions execution
|
||||
my $Result = $Self->OperatorExecute(
|
||||
OperatorName => $ExpressionData->{Operator}->{Name},
|
||||
Attribute => $AttributeType,
|
||||
Selector => $Expression->{Selector},
|
||||
ObjectData => $ExpressionObjectData,
|
||||
CompareValue => $Expression->{CompareValue},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# return result of the expressions execution
|
||||
return $Result;
|
||||
}
|
||||
|
||||
=head1 PRIVATE INTERFACE
|
||||
|
||||
=head2 _ExpressionMatchInit()
|
||||
|
||||
Returns object, attribute and operator of a given expression.
|
||||
|
||||
my $ExpressionData = $ConditionObject->_ExpressionMatchInit(
|
||||
Expression => $ExpressionRef,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub _ExpressionMatchInit {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# extract expression
|
||||
my $Expression = $Param{Expression};
|
||||
|
||||
# declare expression data
|
||||
my %ExpressionData;
|
||||
|
||||
# get object data
|
||||
$ExpressionData{Object} = $Self->ObjectGet(
|
||||
ObjectID => $Expression->{ObjectID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check for object data
|
||||
if ( !$ExpressionData{Object} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "No value for 'Object' with ID '$Expression->{ObjectID}'!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get attribute data
|
||||
$ExpressionData{Attribute} = $Self->AttributeGet(
|
||||
AttributeID => $Expression->{AttributeID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check for attribute data
|
||||
if ( !$ExpressionData{Attribute} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "No value for 'Attribute' with ID '$Expression->{AttributeID}'!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get operator data
|
||||
$ExpressionData{Operator} = $Self->OperatorGet(
|
||||
OperatorID => $Expression->{OperatorID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check for operator data
|
||||
if ( !$ExpressionData{Operator} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "No value for 'Operator' with ID '$Expression->{OperatorID}'!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
return \%ExpressionData;
|
||||
}
|
||||
|
||||
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
|
||||
697
Perl OTRS/Kernel/System/ITSMChange/ITSMCondition/Object.pm
Normal file
697
Perl OTRS/Kernel/System/ITSMChange/ITSMCondition/Object.pm
Normal file
@@ -0,0 +1,697 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::ITSMChange::ITSMCondition::Object;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our $ObjectManagerDisabled = 1;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ITSMChange::ITSMCondition::Object - condition object lib
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 ObjectAdd()
|
||||
|
||||
Add a new condition object.
|
||||
|
||||
my $ConditionID = $ConditionObject->ObjectAdd(
|
||||
Name => 'ObjectName',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectAdd {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Name UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# make lookup with given name for checks
|
||||
my $ObjectID = $Self->ObjectLookup(
|
||||
Name => $Param{Name},
|
||||
);
|
||||
|
||||
# check if object name already exists
|
||||
if ($ObjectID) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Condition object ($Param{Name}) already exists!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# add new object name to database
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => 'INSERT INTO condition_object '
|
||||
. '(name) '
|
||||
. 'VALUES (?)',
|
||||
Bind => [ \$Param{Name} ],
|
||||
);
|
||||
|
||||
# get id of created object
|
||||
$ObjectID = $Self->ObjectLookup(
|
||||
Name => $Param{Name},
|
||||
);
|
||||
|
||||
# check if object could be added
|
||||
if ( !$ObjectID ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "ObjectAdd() failed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# delete cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Delete(
|
||||
Type => $Self->{CacheType},
|
||||
Key => 'ObjectList',
|
||||
);
|
||||
|
||||
return $ObjectID;
|
||||
}
|
||||
|
||||
=head2 ObjectUpdate()
|
||||
|
||||
Update a condition object.
|
||||
|
||||
my $Success = $ConditionObject->ObjectUpdate(
|
||||
ObjectID => 1234,
|
||||
Name => 'NewObjectName',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectUpdate {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(ObjectID Name UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get object data
|
||||
my $ObjectData = $Self->ObjectGet(
|
||||
ObjectID => $Param{ObjectID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check object data
|
||||
if ( !$ObjectData ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "ObjectUpdate of $Param{ObjectID} failed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# update object in database
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => 'UPDATE condition_object '
|
||||
. 'SET name = ? '
|
||||
. 'WHERE id = ?',
|
||||
Bind => [
|
||||
\$Param{Name},
|
||||
\$Param{ObjectID},
|
||||
],
|
||||
);
|
||||
|
||||
# delete cache
|
||||
for my $Key (
|
||||
'ObjectList',
|
||||
'ObjectGet::ObjectID::' . $Param{ObjectID},
|
||||
'ObjectLookup::ObjectID::' . $Param{ObjectID},
|
||||
'ObjectLookup::Name::' . $ObjectData->{Name}, # use the old name
|
||||
)
|
||||
{
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Delete(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $Key,
|
||||
);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 ObjectGet()
|
||||
|
||||
Get a condition object for a given object id.
|
||||
Returns a hash reference of the object data.
|
||||
|
||||
my $ConditionObjectRef = $ConditionObject->ObjectGet(
|
||||
ObjectID => 1234,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
The returned hash reference contains following elements:
|
||||
|
||||
$ConditionObject->{ObjectID}
|
||||
$ConditionObject->{Name}
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(ObjectID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check cache
|
||||
my $CacheKey = 'ObjectGet::ObjectID::' . $Param{ObjectID};
|
||||
my $Cache = $Kernel::OM->Get('Kernel::System::Cache')->Get(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if $Cache;
|
||||
|
||||
# prepare SQL statement
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Prepare(
|
||||
SQL => 'SELECT id, name FROM condition_object WHERE id = ?',
|
||||
Bind => [ \$Param{ObjectID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
|
||||
# fetch the result
|
||||
my %ObjectData;
|
||||
while ( my @Row = $Kernel::OM->Get('Kernel::System::DB')->FetchrowArray() ) {
|
||||
$ObjectData{ObjectID} = $Row[0];
|
||||
$ObjectData{Name} = $Row[1];
|
||||
}
|
||||
|
||||
# check error
|
||||
if ( !%ObjectData ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "ObjectID $Param{ObjectID} does not exist!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# set cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Set(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $CacheKey,
|
||||
Value => \%ObjectData,
|
||||
TTL => $Self->{CacheTTL},
|
||||
);
|
||||
|
||||
return \%ObjectData;
|
||||
}
|
||||
|
||||
=head2 ObjectLookup()
|
||||
|
||||
This method does a lookup for a condition object. If an object
|
||||
id is given, it returns the name of the object. If the name of the
|
||||
object is given, the appropriate id is returned.
|
||||
|
||||
my $ObjectName = $ConditionObject->ObjectLookup(
|
||||
ObjectID => 4321,
|
||||
);
|
||||
|
||||
my $ObjectID = $ConditionObject->ObjectLookup(
|
||||
Name => 'ObjectName',
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectLookup {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check if both parameters are given
|
||||
if ( $Param{ObjectID} && $Param{Name} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need ObjectID or Name - not both!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# check if both parameters are not given
|
||||
if ( !$Param{ObjectID} && !$Param{Name} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need ObjectID or Name - none is given!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# check if ObjectID is a number
|
||||
if ( $Param{ObjectID} && $Param{ObjectID} !~ m{ \A \d+ \z }xms ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "ObjectID must be a number! (ObjectID: $Param{ObjectID})",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
my $CacheKey;
|
||||
|
||||
# prepare SQL statements
|
||||
if ( $Param{ObjectID} ) {
|
||||
|
||||
# check cache
|
||||
$CacheKey = 'ObjectLookup::ObjectID::' . $Param{ObjectID};
|
||||
my $Cache = $Kernel::OM->Get('Kernel::System::Cache')->Get(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if $Cache;
|
||||
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Prepare(
|
||||
SQL => 'SELECT name FROM condition_object WHERE id = ?',
|
||||
Bind => [ \$Param{ObjectID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
}
|
||||
elsif ( $Param{Name} ) {
|
||||
|
||||
# check cache
|
||||
$CacheKey = 'ObjectLookup::Name::' . $Param{Name};
|
||||
my $Cache = $Kernel::OM->Get('Kernel::System::Cache')->Get(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if $Cache;
|
||||
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Prepare(
|
||||
SQL => 'SELECT id FROM condition_object WHERE name = ?',
|
||||
Bind => [ \$Param{Name} ],
|
||||
Limit => 1,
|
||||
);
|
||||
}
|
||||
|
||||
# fetch the result
|
||||
my $Lookup;
|
||||
while ( my @Row = $Kernel::OM->Get('Kernel::System::DB')->FetchrowArray() ) {
|
||||
$Lookup = $Row[0];
|
||||
}
|
||||
|
||||
# set cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Set(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $CacheKey,
|
||||
Value => $Lookup,
|
||||
TTL => $Self->{CacheTTL},
|
||||
);
|
||||
|
||||
return $Lookup;
|
||||
}
|
||||
|
||||
=head2 ObjectList()
|
||||
|
||||
Returns a list of all condition objects as hash reference
|
||||
|
||||
my $ConditionObjectsRef = $ConditionObject->ObjectList(
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
The returned hash reference contains entries like this:
|
||||
|
||||
$ConditionObject{ObjectID} = 'ObjectName'
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need UserID!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# check cache
|
||||
my $CacheKey = 'ObjectList';
|
||||
my $Cache = $Kernel::OM->Get('Kernel::System::Cache')->Get(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $CacheKey,
|
||||
);
|
||||
return $Cache if $Cache;
|
||||
|
||||
# prepare SQL statement
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Prepare(
|
||||
SQL => 'SELECT id, name FROM condition_object',
|
||||
);
|
||||
|
||||
# fetch the result
|
||||
my %ObjectList;
|
||||
while ( my @Row = $Kernel::OM->Get('Kernel::System::DB')->FetchrowArray() ) {
|
||||
$ObjectList{ $Row[0] } = $Row[1];
|
||||
}
|
||||
|
||||
# set cache
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Set(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $CacheKey,
|
||||
Value => \%ObjectList,
|
||||
TTL => $Self->{CacheTTL},
|
||||
);
|
||||
|
||||
return \%ObjectList;
|
||||
}
|
||||
|
||||
=head2 ObjectDelete()
|
||||
|
||||
Deletes a condition object.
|
||||
|
||||
my $Success = $ConditionObject->ObjectDelete(
|
||||
ObjectID => 123,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectDelete {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(ObjectID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# lookup object name
|
||||
my $ObjectName = $Self->ObjectLookup(
|
||||
ObjectID => $Param{ObjectID},
|
||||
);
|
||||
|
||||
# delete condition object from database
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => 'DELETE FROM condition_object '
|
||||
. 'WHERE id = ?',
|
||||
Bind => [ \$Param{ObjectID} ],
|
||||
);
|
||||
|
||||
# delete cache
|
||||
for my $Key (
|
||||
'ObjectList',
|
||||
'ObjectGet::ObjectID::' . $Param{ObjectID},
|
||||
'ObjectLookup::ObjectID::' . $Param{ObjectID},
|
||||
'ObjectLookup::Name::' . $ObjectName,
|
||||
)
|
||||
{
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Delete(
|
||||
Type => $Self->{CacheType},
|
||||
Key => $Key,
|
||||
);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 ObjectSelectorList()
|
||||
|
||||
Returns a list of all selectors available for the given object id and condition id as hash reference
|
||||
|
||||
my $SelectorList = $ConditionObject->ObjectSelectorList(
|
||||
ObjectID => 1234,
|
||||
ConditionID => 5,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns a hash reference like this (for C<workorder> objects)
|
||||
|
||||
$SelectorList = {
|
||||
10 => '1 - WorkorderTitle of Workorder 1',
|
||||
12 => '2 - WorkorderTitle of Workorder 2',
|
||||
34 => '3 - WorkorderTitle of Workorder 3',
|
||||
'any' => 'any',
|
||||
'all' => 'all',
|
||||
}
|
||||
|
||||
or for change objects:
|
||||
|
||||
$SelectorList = {
|
||||
456 => 'Change# 2010011610000618',
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectSelectorList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(ObjectID ConditionID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# lookup object name
|
||||
my $ObjectName = $Self->ObjectLookup(
|
||||
ObjectID => $Param{ObjectID},
|
||||
);
|
||||
|
||||
# get condition data
|
||||
my $ConditionData = $Self->ConditionGet(
|
||||
ConditionID => $Param{ConditionID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check for error
|
||||
return if !$ConditionData;
|
||||
|
||||
# get object backend
|
||||
my $BackendObject = $Kernel::OM->Get( 'Kernel::System::ITSMChange::ITSMCondition::Object::' . $ObjectName );
|
||||
|
||||
# check for error
|
||||
return if !$BackendObject;
|
||||
|
||||
# define default functions for backend
|
||||
my $Sub = 'SelectorList';
|
||||
|
||||
# check for available function
|
||||
if ( !$BackendObject->can($Sub) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "No function '$Sub' available for backend '$ObjectName'!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# execute the action subroutine
|
||||
my $SelectorList = $BackendObject->$Sub(
|
||||
ConditionID => $Param{ConditionID},
|
||||
ChangeID => $ConditionData->{ChangeID},
|
||||
UserID => $Param{UserID},
|
||||
ExpressionID => $Param{ExpressionID},
|
||||
ActionID => $Param{ActionID},
|
||||
) || {};
|
||||
|
||||
return $SelectorList;
|
||||
}
|
||||
|
||||
=head2 ObjectCompareValueList()
|
||||
|
||||
Returns a list of available CompareValues for the given object id and attribute id as hash reference.
|
||||
|
||||
my $CompareValueList = $ConditionObject->ObjectCompareValueList(
|
||||
ObjectID => 1234,
|
||||
AttributeName => 'WorkOrderStateID',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns a hash reference like this, for a C<workorder> object and the attribute 'WorkOrderStateID':
|
||||
|
||||
$CompareValueList = {
|
||||
10 => 'created',
|
||||
12 => 'accepted',
|
||||
13 => 'ready',
|
||||
14 => 'in progress',
|
||||
15 => 'closed',
|
||||
16 => 'canceled',
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectCompareValueList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(ObjectID AttributeName UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# set object name
|
||||
my $ObjectName = $Param{ObjectName};
|
||||
if ( $Param{ObjectID} ) {
|
||||
$ObjectName = $Self->ObjectLookup(
|
||||
ObjectID => $Param{ObjectID},
|
||||
);
|
||||
}
|
||||
|
||||
# get object type
|
||||
my $ObjectType = $ObjectName;
|
||||
|
||||
# get object backend
|
||||
my $BackendObject = $Kernel::OM->Get( 'Kernel::System::ITSMChange::ITSMCondition::Object::' . $ObjectType );
|
||||
|
||||
return if !$BackendObject;
|
||||
|
||||
# define default functions for backend
|
||||
my $Sub = 'CompareValueList';
|
||||
|
||||
# check for available function
|
||||
if ( !$BackendObject->can($Sub) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "No function '$Sub' available for backend '$ObjectType'!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# execute the action subroutine
|
||||
my $CompareValueList = $BackendObject->$Sub(
|
||||
AttributeName => $Param{AttributeName},
|
||||
UserID => $Param{UserID},
|
||||
) || {};
|
||||
|
||||
return $CompareValueList;
|
||||
}
|
||||
|
||||
=head2 ObjectDataGet()
|
||||
|
||||
Return the data of a given type and selector of a certain object.
|
||||
|
||||
my $ObjectDataRef = $ConditionObject->ObjectDataGet(
|
||||
ConditionID => 1234,
|
||||
ObjectName => 'ITSMChange', # or ObjectID
|
||||
ObjectID => 1, # or ObjectName
|
||||
Selector => '123', # ( ObjectKey | any | all )
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectDataGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(ConditionID Selector UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# either ObjectName or ObjectID must be passed
|
||||
if ( !$Param{ObjectName} && !$Param{ObjectID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'ObjectName ID or ObjectID!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# check that not both ObjectName and ObjectID are given
|
||||
if ( $Param{ObjectName} && $Param{ObjectID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need either ObjectName OR ObjectID - not both!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# set object name
|
||||
my $ObjectName = $Param{ObjectName};
|
||||
if ( $Param{ObjectID} ) {
|
||||
$ObjectName = $Self->ObjectLookup(
|
||||
ObjectID => $Param{ObjectID},
|
||||
);
|
||||
}
|
||||
|
||||
# get object type
|
||||
my $ObjectType = $ObjectName;
|
||||
|
||||
# get object backend
|
||||
my $BackendObject = $Kernel::OM->Get( 'Kernel::System::ITSMChange::ITSMCondition::Object::' . $ObjectType );
|
||||
|
||||
return if !$BackendObject;
|
||||
|
||||
# define default functions for backend
|
||||
my $Sub = 'DataGet';
|
||||
|
||||
# check for available function
|
||||
if ( !$BackendObject->can($Sub) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "No function '$Sub' available for backend '$ObjectType'!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get object data
|
||||
my $ObjectData = $BackendObject->$Sub(
|
||||
ConditionID => $Param{ConditionID},
|
||||
Selector => $Param{Selector},
|
||||
UserID => $Param{UserID},
|
||||
) || [];
|
||||
|
||||
return $ObjectData;
|
||||
}
|
||||
|
||||
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,214 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::ITSMChange::ITSMCondition::Object::ITSMChange;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::ITSMChange',
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::User',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ITSMChange::ITSMCondition::Object::ITSMChange - condition itsm change object lib
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
create an object
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $ConditionObjectITSMChange = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMCondition::Object::ITSMChange');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 DataGet()
|
||||
|
||||
Returns change data in an array reference.
|
||||
|
||||
my $ChangeDataRef = $ConditionObjectITSMChange->DataGet(
|
||||
Selector => 1234,
|
||||
UserID => 2345,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub DataGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Selector UserID)) {
|
||||
if ( !exists $Param{$Argument} || !defined $Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# remap params
|
||||
my %ChangeGet = (
|
||||
ChangeID => $Param{Selector},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# get change data as anon hash ref
|
||||
my $Change = $Kernel::OM->Get('Kernel::System::ITSMChange')->ChangeGet(%ChangeGet);
|
||||
|
||||
# check for change
|
||||
return if !$Change;
|
||||
|
||||
# build array ref
|
||||
my $ChangeData = [$Change];
|
||||
|
||||
return $ChangeData;
|
||||
}
|
||||
|
||||
=head2 CompareValueList()
|
||||
|
||||
Returns a list of available CompareValues for the given attribute id of a change object as hash reference.
|
||||
|
||||
my $CompareValueList = $ConditionObjectITSMChange->CompareValueList(
|
||||
AttributeName => 'PriorityID',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns a hash reference like this, for the change attribute 'Priority':
|
||||
|
||||
$CompareValueList = {
|
||||
23 => '1 very low',
|
||||
24 => '2 low',
|
||||
25 => '3 normal',
|
||||
26 => '4 high',
|
||||
27 => '5 very high',
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub CompareValueList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(AttributeName UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# to store the list
|
||||
my $CompareValueList = {};
|
||||
|
||||
# CategoryID, ImpactID, PriorityID
|
||||
if ( $Param{AttributeName} =~ m{ \A ( Category | Impact | Priority ) ID \z }xms ) {
|
||||
|
||||
# remove 'ID' at the end of attribute
|
||||
my $Type = $1;
|
||||
|
||||
# get the category or impact or priority list
|
||||
$CompareValueList = $Kernel::OM->Get('Kernel::System::ITSMChange')->ChangePossibleCIPGet(
|
||||
Type => $Type,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
|
||||
# ChangeStateID
|
||||
elsif ( $Param{AttributeName} eq 'ChangeStateID' ) {
|
||||
|
||||
# get change state list
|
||||
$CompareValueList = $Kernel::OM->Get('Kernel::System::ITSMChange')->ChangePossibleStatesGet(
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
elsif (
|
||||
$Param{AttributeName} eq 'ChangeBuilderID'
|
||||
|| $Param{AttributeName} eq 'ChangeManagerID'
|
||||
)
|
||||
{
|
||||
|
||||
# get a complete list of users
|
||||
my %Users = $Kernel::OM->Get('Kernel::System::User')->UserList(
|
||||
Type => 'Long',
|
||||
Valid => 1,
|
||||
);
|
||||
|
||||
$CompareValueList = \%Users;
|
||||
}
|
||||
|
||||
return $CompareValueList;
|
||||
}
|
||||
|
||||
=head2 SelectorList()
|
||||
|
||||
Returns a list of all selectors available for the given change object id and condition id as hash reference
|
||||
|
||||
my $SelectorList = $ConditionObjectITSMChange->SelectorList(
|
||||
ObjectID => 1234,
|
||||
ConditionID => 5,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns a hash reference like this:
|
||||
|
||||
$SelectorList = {
|
||||
456 => 'Change# 2010011610000618',
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub SelectorList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# get change data
|
||||
my $ChangeData = $Kernel::OM->Get('Kernel::System::ITSMChange')->ChangeGet(
|
||||
ChangeID => $Param{ChangeID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check error
|
||||
return if !$ChangeData;
|
||||
|
||||
# build selector list
|
||||
my %SelectorList = (
|
||||
$ChangeData->{ChangeID} => $ChangeData->{ChangeNumber},
|
||||
);
|
||||
|
||||
return \%SelectorList;
|
||||
}
|
||||
|
||||
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,290 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::ITSMChange::ITSMCondition::Object::ITSMWorkOrder;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::Language qw(Translatable);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::ITSMChange::ITSMCondition',
|
||||
'Kernel::System::ITSMChange::ITSMWorkOrder',
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::User',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ITSMChange::ITSMCondition::Object::ITSMWorkOrder - condition itsm C<workorder> object lib
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
create an object
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $ConditionObjectITSMWorkOrder = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMCondition::Object::ITSMWorkOrder');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 DataGet()
|
||||
|
||||
Returns C<workorder> data in an array reference.
|
||||
|
||||
my $WorkOrderDataRef = $ConditionObjectITSMWorkOrder->DataGet(
|
||||
Selector => 1234,
|
||||
UserID => 2345,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub DataGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Selector UserID)) {
|
||||
if ( !exists $Param{$Argument} || !defined $Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# handle 'any' or 'all' in a special case
|
||||
return $Self->_DataGetAll(%Param) if $Param{Selector} eq 'any';
|
||||
return $Self->_DataGetAll(%Param) if $Param{Selector} eq 'all';
|
||||
|
||||
# remap params
|
||||
my %WorkOrderGet = (
|
||||
WorkOrderID => $Param{Selector},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# get workorder as anon hash ref
|
||||
my $WorkOrder = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderGet(%WorkOrderGet);
|
||||
|
||||
# check for workorder
|
||||
return if !$WorkOrder;
|
||||
|
||||
# build array ref
|
||||
my $WorkOrderData = [$WorkOrder];
|
||||
|
||||
return $WorkOrderData;
|
||||
}
|
||||
|
||||
=head2 CompareValueList()
|
||||
|
||||
Returns a list of available CompareValues for the given attribute id of a C<workorder> object as hash reference.
|
||||
|
||||
my $CompareValueList = $ConditionObjectITSMWorkOrder->CompareValueList(
|
||||
AttributeName => 'WorkOrderStateID',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns a hash reference like this, for the C<workorder> attribute 'WorkOrderStateID':
|
||||
|
||||
$CompareValueList = {
|
||||
10 => 'created',
|
||||
12 => 'accepted',
|
||||
13 => 'ready',
|
||||
14 => 'in progress',
|
||||
15 => 'closed',
|
||||
16 => 'canceled',
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub CompareValueList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(AttributeName UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# to store the list
|
||||
my $CompareValueList = {};
|
||||
|
||||
# WorkOrderStateID
|
||||
if ( $Param{AttributeName} eq 'WorkOrderStateID' ) {
|
||||
|
||||
# get workorder state list
|
||||
$CompareValueList = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderPossibleStatesGet(
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
|
||||
# WorkOrderTypeID
|
||||
elsif ( $Param{AttributeName} eq 'WorkOrderTypeID' ) {
|
||||
|
||||
# get workorder type list
|
||||
$CompareValueList = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderTypeList(
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
elsif ( $Param{AttributeName} eq 'WorkOrderAgentID' ) {
|
||||
|
||||
# get a complete list of users
|
||||
my %Users = $Kernel::OM->Get('Kernel::System::User')->UserList(
|
||||
Type => 'Long',
|
||||
Valid => 1,
|
||||
);
|
||||
|
||||
$CompareValueList = \%Users;
|
||||
}
|
||||
|
||||
return $CompareValueList;
|
||||
}
|
||||
|
||||
=head2 SelectorList()
|
||||
|
||||
Returns a list of all selectors available for the given C<workorder> object id and condition id as hash reference
|
||||
|
||||
my $SelectorList = $ConditionObjectITSMWorkOrder->SelectorList(
|
||||
ObjectID => 1234,
|
||||
ConditionID => 5,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns a hash reference like this:
|
||||
|
||||
$SelectorList = {
|
||||
10 => '1 - WorkorderTitle of Workorder 1',
|
||||
12 => '2 - WorkorderTitle of Workorder 2',
|
||||
34 => '3 - WorkorderTitle of Workorder 3',
|
||||
'any' => 'any',
|
||||
'all' => 'all',
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub SelectorList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# get all workorder ids of change
|
||||
my $WorkOrderIDs = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderList(
|
||||
ChangeID => $Param{ChangeID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check for workorder ids
|
||||
return if !$WorkOrderIDs;
|
||||
return if ref $WorkOrderIDs ne 'ARRAY';
|
||||
|
||||
# build selector list
|
||||
my %SelectorList;
|
||||
for my $WorkOrderID ( @{$WorkOrderIDs} ) {
|
||||
|
||||
# get workorder data
|
||||
my $WorkOrderData = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderGet(
|
||||
WorkOrderID => $WorkOrderID,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
$SelectorList{ $WorkOrderData->{WorkOrderID} }
|
||||
= $WorkOrderData->{WorkOrderNumber} . ' - ' . $WorkOrderData->{WorkOrderTitle};
|
||||
}
|
||||
|
||||
# add 'all' selector (for expressions and actions)
|
||||
$SelectorList{'all'} = Translatable('all');
|
||||
|
||||
# add 'any' selector only for expressions
|
||||
if ( $Param{ExpressionID} ) {
|
||||
$SelectorList{'any'} = Translatable('any');
|
||||
}
|
||||
|
||||
return \%SelectorList;
|
||||
}
|
||||
|
||||
=head1 PRIVATE INTERFACE
|
||||
|
||||
=head2 _DataGetAll()
|
||||
|
||||
my $WorkOrderDataArrayRef = $ConditionObjectITSMWorkOrder->_DataGetAll(
|
||||
ConditionID => 123,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub _DataGetAll {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# get condition
|
||||
my $ConditionData = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMCondition')->ConditionGet(
|
||||
ConditionID => $Param{ConditionID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check for condition
|
||||
return if !$ConditionData;
|
||||
|
||||
# get all workorder ids of change
|
||||
my $WorkOrderIDs = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderList(
|
||||
ChangeID => $ConditionData->{ChangeID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check for workorder ids
|
||||
return if !$WorkOrderIDs;
|
||||
return if ref $WorkOrderIDs ne 'ARRAY';
|
||||
return if !@{$WorkOrderIDs};
|
||||
|
||||
# get workorder data
|
||||
my @WorkOrderData;
|
||||
WORKORDERID:
|
||||
for my $WorkOrderID ( @{$WorkOrderIDs} ) {
|
||||
my $WorkOrder = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderGet(
|
||||
WorkOrderID => $WorkOrderID,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check workorder
|
||||
next WORKORDERID if !$WorkOrder;
|
||||
|
||||
# add workorder to return array
|
||||
push @WorkOrderData, $WorkOrder;
|
||||
}
|
||||
|
||||
# return workorder data
|
||||
return \@WorkOrderData;
|
||||
}
|
||||
|
||||
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
|
||||
1279
Perl OTRS/Kernel/System/ITSMChange/ITSMCondition/Operator.pm
Normal file
1279
Perl OTRS/Kernel/System/ITSMChange/ITSMCondition/Operator.pm
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,107 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::ITSMChange::ITSMCondition::Operator::ITSMChange;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::ITSMChange',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ITSMChange::ITSMCondition::Operator::ITSMChange - condition itsm change operator lib
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object.
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $ConditionOperatorITSMChange = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMCondition::Operator::ITSMChange');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Set()
|
||||
|
||||
Updates a change with the given data.
|
||||
|
||||
my $Success = $ITSMChangeOperator->Set(
|
||||
Selector => 1234,
|
||||
Attribute => 'ChangeStateID',
|
||||
ActionValue => 2345,
|
||||
UserID => 1234,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub Set {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Selector Attribute ActionValue UserID)) {
|
||||
if ( !exists $Param{$Argument} || !defined $Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get change
|
||||
my $Change = $Kernel::OM->Get('Kernel::System::ITSMChange')->ChangeGet(
|
||||
ChangeID => $Param{Selector},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check error
|
||||
return if !$Change;
|
||||
return if ref $Change ne 'HASH';
|
||||
|
||||
# set change attribute to empty string if it is not true
|
||||
$Change->{ $Param{Attribute} } ||= '';
|
||||
|
||||
# do not update the attribute if it already has this value
|
||||
# ( this will prevent infinite event looping! )
|
||||
return 1 if $Change->{ $Param{Attribute} } eq $Param{ActionValue};
|
||||
|
||||
# update change and return update result
|
||||
return $Kernel::OM->Get('Kernel::System::ITSMChange')->ChangeUpdate(
|
||||
ChangeID => $Param{Selector},
|
||||
$Param{Attribute} => $Param{ActionValue},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
|
||||
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::ITSMChange::ITSMCondition::Operator::ITSMWorkOrder;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::ITSMChange::ITSMWorkOrder',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::ITSMChange::ITSMCondition::Operator::ITSMWorkOrder - condition itsm workorder operator lib
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object.
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $ConditionOperatorITSMWorkOrder = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMCondition::Operator::ITSMWorkOrder');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Set()
|
||||
|
||||
Updates a C<workorder> with the given data.
|
||||
|
||||
my $Success = $ITSMWorkOrderOperator->Set(
|
||||
Selector => 1234,
|
||||
Attribute => 'WorkOrderStateID',
|
||||
ActionValue => 2345,
|
||||
UserID => 1234,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub Set {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Selector Attribute ActionValue UserID)) {
|
||||
if ( !exists $Param{$Argument} || !defined $Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get workorder
|
||||
my $WorkOrder = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderGet(
|
||||
WorkOrderID => $Param{Selector},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# check error
|
||||
return if !$WorkOrder;
|
||||
return if ref $WorkOrder ne 'HASH';
|
||||
|
||||
# set workorder attribute to empty string if it is not true
|
||||
$WorkOrder->{ $Param{Attribute} } ||= '';
|
||||
|
||||
# do not update the attribute if it already has this value
|
||||
# ( this will prevent infinite event looping! )
|
||||
return 1 if $WorkOrder->{ $Param{Attribute} } eq $Param{ActionValue};
|
||||
|
||||
# if the workorder agent should be deleted it has to be undefined
|
||||
if ( $Param{Attribute} eq 'WorkOrderAgentID' && !$Param{ActionValue} ) {
|
||||
$Param{ActionValue} = undef;
|
||||
}
|
||||
|
||||
# update workorder and return update result
|
||||
return $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderUpdate(
|
||||
WorkOrderID => $Param{Selector},
|
||||
$Param{Attribute} => $Param{ActionValue},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
|
||||
=head2 SetAll()
|
||||
|
||||
Updates a set of C<workorders> with the given data.
|
||||
|
||||
my $Success = $ITSMWorkOrderOperator->SetAll(
|
||||
Objects => [ {...}, {...}, ], # data of ITSMWorkOrders
|
||||
Attribute => 'WorkOrderStateID',
|
||||
ActionValue => 2345,
|
||||
UserID => 1234,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub SetAll {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Objects Attribute ActionValue UserID)) {
|
||||
if ( !exists $Param{$Argument} || !defined $Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check objects
|
||||
return if ref $Param{Objects} ne 'ARRAY';
|
||||
|
||||
# this will be set to zero if any of the Set-Operations fails
|
||||
my $SetAllSuccess = 1;
|
||||
|
||||
# update each workorder object
|
||||
WORKORDEROBJECT:
|
||||
for my $WorkOrderObject ( @{ $Param{Objects} } ) {
|
||||
|
||||
# check workorder object
|
||||
next WORKORDEROBJECT if !$WorkOrderObject;
|
||||
next WORKORDEROBJECT if ref $WorkOrderObject ne 'HASH';
|
||||
|
||||
# update workorder object
|
||||
my $Result = $Self->Set(
|
||||
Selector => $WorkOrderObject->{WorkOrderID},
|
||||
Attribute => $Param{Attribute},
|
||||
ActionValue => $Param{ActionValue},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# if a set operation was not successful,
|
||||
# then the complete SetAll operation will not be successful
|
||||
if ( !$Result ) {
|
||||
$SetAllSuccess = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return $SetAllSuccess;
|
||||
}
|
||||
|
||||
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