This commit is contained in:
2024-10-14 00:08:40 +02:00
parent dbfba56f66
commit 1462d52e13
4572 changed files with 2658864 additions and 0 deletions

View File

@@ -0,0 +1,125 @@
# --
# 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::Console::Command::Admin::ITSM::IncidentState::Recalculate;
use strict;
use warnings;
## nofilter(TidyAll::Plugin::OTRS::Migrations::OTRS6::SysConfig)
use parent qw(Kernel::System::Console::BaseCommand);
our @ObjectDependencies = (
'Kernel::System::GeneralCatalog',
'Kernel::System::ITSMConfigItem',
'Kernel::System::Service',
);
sub Configure {
my ( $Self, %Param ) = @_;
$Self->Description('Recalculates the incident state of config items.');
return;
}
sub Run {
my ( $Self, %Param ) = @_;
$Self->Print("<yellow>Recalculating the incident state of config items...</yellow>\n\n");
# get class list
my $ClassList = $Kernel::OM->Get('Kernel::System::GeneralCatalog')->ItemList(
Class => 'ITSM::ConfigItem::Class',
);
# get the valid class ids
my @ValidClassIDs = sort keys %{$ClassList};
# get all config items ids form all valid classes
my $ConfigItemsIDsRef = $Kernel::OM->Get('Kernel::System::ITSMConfigItem')->ConfigItemSearch(
ClassIDs => \@ValidClassIDs,
);
# get number of config items
my $CICount = scalar @{$ConfigItemsIDsRef};
$Self->Print("<yellow>Recalculating incident state for $CICount config items.</yellow>\n");
# Remember config item results through multiple runs of CurInciStateRecalc().
my %NewConfigItemIncidentState;
my %ScannedConfigItemIDs;
my $Count = 0;
CONFIGITEM:
for my $ConfigItemID ( @{$ConfigItemsIDsRef} ) {
my $Success = $Kernel::OM->Get('Kernel::System::ITSMConfigItem')->CurInciStateRecalc(
ConfigItemID => $ConfigItemID,
NewConfigItemIncidentState => \%NewConfigItemIncidentState,
ScannedConfigItemIDs => \%ScannedConfigItemIDs,
);
if ( !$Success ) {
$Self->Print("<red>... could not recalculate incident state for config item id '$ConfigItemID'!</red>\n");
next CONFIGITEM;
}
$Count++;
if ( $Count % 100 == 0 ) {
$Self->Print("<green>... $Count config items recalculated.</green>\n");
}
}
$Self->Print("\n<green>Ready. Recalculated $Count config items.</green>\n\n");
# get service object
my $ServiceObject = $Kernel::OM->Get('Kernel::System::Service');
# get list of all services (valid and invalid)
my %ServiceList = $ServiceObject->ServiceList(
Valid => 0,
UserID => 1,
);
my $NumberOfServices = scalar keys %ServiceList;
$Self->Print(
"<green>Resetting ServicePreferences 'CurInciStateTypeFromCIs' for $NumberOfServices services...</green>\n"
);
for my $ServiceID ( sort keys %ServiceList ) {
# update the current incident state type from CIs of the service with an empty value
# this is necessary to force a recalculation on a ServiceGet()
$ServiceObject->ServicePreferencesSet(
ServiceID => $ServiceID,
Key => 'CurInciStateTypeFromCIs',
Value => '',
UserID => 1,
);
}
$Self->Print("<green>Ready.</green>\n");
return $Self->ExitCodeOk();
}
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