init III
This commit is contained in:
@@ -0,0 +1,291 @@
|
||||
# --
|
||||
# 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::Config::FixInvalid;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
use Kernel::System::VariableCheck qw( :all );
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::Main',
|
||||
'Kernel::System::SysConfig',
|
||||
'Kernel::System::YAML',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Attempt to fix invalid system configuration settings.');
|
||||
$Self->AddOption(
|
||||
Name => 'non-interactive',
|
||||
Description => 'Attempt to fix invalid settings without user interaction.',
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
|
||||
$Self->AddOption(
|
||||
Name => 'values-from-path',
|
||||
Description =>
|
||||
"Read values for invalid settings from a YAML file instead of user input (takes precedence in non-interactive mode).",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
$Self->AddOption(
|
||||
Name => 'skip-missing',
|
||||
Description => 'Skip invalid settings whose XML configuration file is not present.',
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $NonInteractive = $Self->GetOption('non-interactive') || 0;
|
||||
my $ValuesFromPath = $Self->GetOption('values-from-path');
|
||||
my $SkipMissing = $Self->GetOption('skip-missing') || 0;
|
||||
|
||||
my $SysConfigObject = $Kernel::OM->Get('Kernel::System::SysConfig');
|
||||
|
||||
my @InvalidSettings = $SysConfigObject->ConfigurationInvalidList(
|
||||
Undeployed => 1,
|
||||
NoCache => 1,
|
||||
);
|
||||
|
||||
if ( !scalar @InvalidSettings ) {
|
||||
$Self->Print("<green>All settings are valid.</green>\n\n");
|
||||
|
||||
$Self->Print("<green>Done.</green>\n") if !$NonInteractive;
|
||||
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
my $MainObject = $Kernel::OM->Get('Kernel::System::Main');
|
||||
|
||||
if ($SkipMissing) {
|
||||
$Self->Print("<yellow>Skipping missing settings for now...</yellow>\n\n");
|
||||
}
|
||||
|
||||
my $TargetValues;
|
||||
if ($ValuesFromPath) {
|
||||
|
||||
my $Content = $Kernel::OM->Get('Kernel::System::Main')->FileRead(
|
||||
Location => $ValuesFromPath,
|
||||
);
|
||||
if ( !$Content ) {
|
||||
$Self->PrintError("Could not read YAML source from '$ValuesFromPath'.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$TargetValues = $Kernel::OM->Get('Kernel::System::YAML')->Load( Data => ${$Content} );
|
||||
|
||||
if ( !$TargetValues ) {
|
||||
$Self->PrintError('Could not parse YAML source.');
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
}
|
||||
|
||||
my @FixedSettings;
|
||||
my @NotFixedSettings;
|
||||
|
||||
SETTING:
|
||||
for my $SettingName (@InvalidSettings) {
|
||||
my %Setting = $SysConfigObject->SettingGet(
|
||||
Name => $SettingName,
|
||||
);
|
||||
|
||||
# If we have a target value use it if it's valid - otherwise use normal flow.
|
||||
# This also works for missing xml files and non-entity types.
|
||||
if (
|
||||
$TargetValues
|
||||
&& $TargetValues->{$SettingName}
|
||||
&& $Self->_TryUpdateSetting(
|
||||
SettingName => $SettingName,
|
||||
Value => $TargetValues->{$SettingName},
|
||||
)
|
||||
)
|
||||
{
|
||||
push @FixedSettings, $SettingName;
|
||||
$Self->Print("<green>Corrected setting via input file:</green> $SettingName\n");
|
||||
|
||||
next SETTING;
|
||||
}
|
||||
|
||||
# Skip setting if the original XML file does not exist.
|
||||
if ($SkipMissing) {
|
||||
my $XMLFilename = $Setting{XMLFilename};
|
||||
my $FilePath = join '/',
|
||||
$Kernel::OM->Get('Kernel::Config')->Get('Home'),
|
||||
'Kernel/Config/Files/XML',
|
||||
$XMLFilename;
|
||||
|
||||
next SETTING if !( -e $FilePath );
|
||||
}
|
||||
|
||||
my $EntityType = $Setting{XMLContentRaw} =~ s{ \A .*? ValueEntityType=" ( [^"]* ) " .*? \z }{$1}xmsr;
|
||||
|
||||
# Skip settings that are not related to the Entities.
|
||||
if ( $Setting{XMLContentRaw} eq $EntityType ) { # non-match
|
||||
$Self->PrintWarning("$SettingName is not an entity value type, skipping...");
|
||||
push @NotFixedSettings, $SettingName;
|
||||
next SETTING;
|
||||
}
|
||||
|
||||
# Skip settings without ValueEntityType.
|
||||
if ( !$EntityType ) {
|
||||
$Self->PrintWarning("System was unable to determine ValueEntityType for $SettingName, skipping...");
|
||||
push @NotFixedSettings, $SettingName;
|
||||
next SETTING;
|
||||
}
|
||||
|
||||
# Check if Entity module exists.
|
||||
my $Loaded = $MainObject->Require(
|
||||
"Kernel::System::SysConfig::ValueType::Entity::$EntityType",
|
||||
Silent => 1,
|
||||
);
|
||||
|
||||
if ( !$Loaded ) {
|
||||
$Self->PrintWarning("Kernel::System::SysConfig::ValueType::Entity::$EntityType not found, skipping...");
|
||||
push @NotFixedSettings, $SettingName;
|
||||
next SETTING;
|
||||
}
|
||||
|
||||
my @List = $Kernel::OM->Get("Kernel::System::SysConfig::ValueType::Entity::$EntityType")->EntityValueList();
|
||||
|
||||
if ( !scalar @List ) {
|
||||
$Self->PrintWarning("$EntityType list is empty, skipping...");
|
||||
push @NotFixedSettings, $SettingName;
|
||||
next SETTING;
|
||||
}
|
||||
|
||||
# Non-interactive.
|
||||
if ($NonInteractive) {
|
||||
|
||||
next SETTING if !$Self->_TryUpdateSetting(
|
||||
SettingName => $SettingName,
|
||||
Value => $List[0], # Take first available option.
|
||||
NotFixedSettings => \@NotFixedSettings,
|
||||
);
|
||||
|
||||
push @FixedSettings, $SettingName;
|
||||
$Self->Print("<green>Auto-corrected setting:</green> $SettingName\n");
|
||||
|
||||
next SETTING;
|
||||
}
|
||||
|
||||
# Ask user.
|
||||
$Self->Print("\n<yellow>$SettingName is invalid, select one of the choices below:</yellow>\n");
|
||||
|
||||
my $Index = 1;
|
||||
for my $Item (@List) {
|
||||
$Self->Print(" [$Index] $Item\n");
|
||||
$Index++;
|
||||
}
|
||||
|
||||
my $SelectedIndex;
|
||||
while (
|
||||
!$SelectedIndex
|
||||
|| !IsPositiveInteger($SelectedIndex)
|
||||
|| $SelectedIndex > scalar @List
|
||||
)
|
||||
{
|
||||
$Self->Print("\nYour choice: ");
|
||||
$SelectedIndex = <STDIN>; ## no critic
|
||||
|
||||
# Remove white space.
|
||||
$SelectedIndex =~ s{\s}{}smx;
|
||||
}
|
||||
|
||||
next SETTING if !$Self->_TryUpdateSetting(
|
||||
SettingName => $SettingName,
|
||||
Value => $List[ $SelectedIndex - 1 ],
|
||||
NotFixedSettings => \@NotFixedSettings,
|
||||
);
|
||||
|
||||
push @FixedSettings, $SettingName;
|
||||
}
|
||||
|
||||
if ( scalar @FixedSettings ) {
|
||||
|
||||
my %Result = $SysConfigObject->ConfigurationDeploy(
|
||||
Comments => 'FixInvalid - Automatically fixed invalid settings',
|
||||
NoValidation => 1,
|
||||
UserID => 1,
|
||||
Force => 1,
|
||||
DirtySettings => \@FixedSettings,
|
||||
);
|
||||
|
||||
if ( !$Result{Success} ) {
|
||||
$Self->PrintError('Deployment failed!');
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("\n<green>Deployment successful.</green>\n");
|
||||
}
|
||||
|
||||
if ( scalar @NotFixedSettings ) {
|
||||
$Self->Print(
|
||||
"\nFollowing settings were not fixed:\n"
|
||||
. join( ",\n", map {" - $_"} @NotFixedSettings ) . "\n"
|
||||
. "\nPlease use console command (bin/otrs.Console.pl Admin::Config::Update --help) or GUI to fix them.\n\n"
|
||||
);
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n") if !$NonInteractive;
|
||||
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
sub PrintWarning {
|
||||
my ( $Self, $Message ) = @_;
|
||||
|
||||
return $Self->Print("<yellow>Warning: $Message</yellow>\n");
|
||||
}
|
||||
|
||||
sub _TryUpdateSetting {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $SysConfigObject = $Kernel::OM->Get('Kernel::System::SysConfig');
|
||||
|
||||
my $ExclusiveLockGUID = $SysConfigObject->SettingLock(
|
||||
Name => $Param{SettingName},
|
||||
Force => 1,
|
||||
UserID => 1,
|
||||
);
|
||||
if ( !$ExclusiveLockGUID && $Param{NotFixedSettings} ) {
|
||||
$Self->PrintWarning("System was not able to lock the setting $Param{SettingName}, skipping...");
|
||||
push @{ $Param{NotFixedSettings} }, $Param{SettingName};
|
||||
}
|
||||
return if !$ExclusiveLockGUID;
|
||||
|
||||
my %Update = $SysConfigObject->SettingUpdate(
|
||||
Name => $Param{SettingName},
|
||||
IsValid => 1,
|
||||
EffectiveValue => $Param{Value},
|
||||
ExclusiveLockGUID => $ExclusiveLockGUID,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
if ( !$Update{Success} && $Param{NotFixedSettings} ) {
|
||||
$Self->PrintWarning("System was not able to update the setting $Param{SettingName}, skipping...");
|
||||
push @{ $Param{NotFixedSettings} }, $Param{SettingName};
|
||||
}
|
||||
return if !$Update{Success};
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,109 @@
|
||||
# --
|
||||
# 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::Config::ListInvalid;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Main',
|
||||
'Kernel::System::SysConfig',
|
||||
'Kernel::System::YAML',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('List invalid system configuration.');
|
||||
$Self->AddOption(
|
||||
Name => 'export-to-path',
|
||||
Description => "Export list to a YAML file instead.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $SysConfigObject = $Kernel::OM->Get('Kernel::System::SysConfig');
|
||||
|
||||
my @InvalidSettings = $SysConfigObject->ConfigurationInvalidList(
|
||||
Undeployed => 1,
|
||||
NoCache => 1,
|
||||
);
|
||||
|
||||
if ( !scalar @InvalidSettings ) {
|
||||
$Self->Print("<green>All settings are valid.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
my $ExportToPath = $Self->GetOption('export-to-path');
|
||||
|
||||
if ($ExportToPath) {
|
||||
$Self->Print("<red>Settings with invalid values have been found.</red>\n");
|
||||
}
|
||||
else {
|
||||
$Self->Print("<red>The following settings have an invalid value:</red>\n");
|
||||
}
|
||||
|
||||
my $MainObject = $Kernel::OM->Get('Kernel::System::Main');
|
||||
|
||||
my %EffectiveValues;
|
||||
SETTINGNAME:
|
||||
for my $SettingName (@InvalidSettings) {
|
||||
my %Setting = $SysConfigObject->SettingGet(
|
||||
Name => $SettingName,
|
||||
);
|
||||
|
||||
if ($ExportToPath) {
|
||||
$EffectiveValues{$SettingName} = $Setting{EffectiveValue};
|
||||
next SETTINGNAME;
|
||||
}
|
||||
|
||||
my $EffectiveValue = $MainObject->Dump(
|
||||
$Setting{EffectiveValue},
|
||||
);
|
||||
|
||||
$EffectiveValue =~ s/\$VAR1 = //;
|
||||
|
||||
$Self->Print(" $SettingName = $EffectiveValue");
|
||||
}
|
||||
|
||||
if ($ExportToPath) {
|
||||
|
||||
my $EffectiveValuesYAML = $Kernel::OM->Get('Kernel::System::YAML')->Dump(
|
||||
Data => \%EffectiveValues,
|
||||
);
|
||||
|
||||
# Write settings to a file.
|
||||
my $FileLocation = $Kernel::OM->Get('Kernel::System::Main')->FileWrite(
|
||||
Location => $ExportToPath,
|
||||
Content => \$EffectiveValuesYAML,
|
||||
Mode => 'utf8',
|
||||
);
|
||||
|
||||
# Check if target file exists.
|
||||
if ( !$FileLocation ) {
|
||||
$Self->PrintError("Could not write file $ExportToPath!\nFail.\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
}
|
||||
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
1;
|
||||
121
Perl OTRS/Kernel/System/Console/Command/Admin/Config/Read.pm
Normal file
121
Perl OTRS/Kernel/System/Console/Command/Admin/Config/Read.pm
Normal file
@@ -0,0 +1,121 @@
|
||||
# --
|
||||
# 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::Config::Read;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::SysConfig',
|
||||
'Kernel::System::Main',
|
||||
'Kernel::System::YAML',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Gather the value of a setting.');
|
||||
$Self->AddOption(
|
||||
Name => 'setting-name',
|
||||
Description => "The name of the setting.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'target-path',
|
||||
Description => "Specify the output location of the setting value YAML file.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Gathering setting value...</yellow>\n");
|
||||
|
||||
my $SettingName = $Self->GetOption('setting-name');
|
||||
|
||||
my %Setting = $Kernel::OM->Get('Kernel::System::SysConfig')->SettingGet(
|
||||
Name => $SettingName,
|
||||
);
|
||||
|
||||
# Return if there was no setting.
|
||||
if ( !%Setting ) {
|
||||
$Self->Print("<red>Fail.</red>\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
# Return if setting is invalid or not visible
|
||||
if ( !$Setting{IsValid} || $Setting{IsInvisible} ) {
|
||||
$Self->PrintError("Setting is invalid!\nFail.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
# Return if not effectiveValue.
|
||||
if ( !defined $Setting{EffectiveValue} ) {
|
||||
$Self->PrintError("No effective value found for setting: $SettingName!.\nFail.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
# Dump config as string.
|
||||
my $TargetPath = $Self->GetOption('target-path');
|
||||
my $EffectiveValueYAML = $Kernel::OM->Get('Kernel::System::YAML')->Dump(
|
||||
Data => $Setting{EffectiveValue},
|
||||
);
|
||||
|
||||
if ($TargetPath) {
|
||||
|
||||
# Write configuration in a file.
|
||||
my $FileLocation = $Kernel::OM->Get('Kernel::System::Main')->FileWrite(
|
||||
Location => $TargetPath,
|
||||
Content => \$EffectiveValueYAML,
|
||||
Mode => 'utf8',
|
||||
);
|
||||
|
||||
# Check if target file exists.
|
||||
if ( !$FileLocation ) {
|
||||
$Self->PrintError("Could not write file $TargetPath!\nFail.\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
# Send value to standard output
|
||||
$Self->Print("\nSetting: <yellow>$SettingName</yellow>");
|
||||
if ( !ref $Setting{EffectiveValue} ) {
|
||||
$Self->Print("\n$Setting{EffectiveValue}\n\n");
|
||||
}
|
||||
else {
|
||||
$Self->Print(" (YAML)\n$EffectiveValueYAML\n");
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</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
|
||||
@@ -0,0 +1,43 @@
|
||||
# --
|
||||
# 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::Config::UnlockAll;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::SysConfig',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Unlock all settings.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Unlocking all settings...</yellow>\n");
|
||||
|
||||
my $Success = $Kernel::OM->Get('Kernel::System::SysConfig')->SettingUnlock(
|
||||
UnlockAll => 1,
|
||||
);
|
||||
|
||||
return $Self->ExitCodeError(1) if !$Success;
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
259
Perl OTRS/Kernel/System/Console/Command/Admin/Config/Update.pm
Normal file
259
Perl OTRS/Kernel/System/Console/Command/Admin/Config/Update.pm
Normal file
@@ -0,0 +1,259 @@
|
||||
# --
|
||||
# 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::Config::Update;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw( IsHashRefWithData );
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Main',
|
||||
'Kernel::System::SysConfig',
|
||||
'Kernel::System::YAML',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Update the value of a setting.');
|
||||
$Self->AddOption(
|
||||
Name => 'setting-name',
|
||||
Description => "The name of the setting.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'source-path',
|
||||
Description => "Specify the source location of the setting value YAML file.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'value',
|
||||
Description => "Specify single line setting value.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'valid',
|
||||
Description => "Specify validity of the setting ( 0 or 1 ).",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/0|1/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'reset',
|
||||
Description => "Reset setting to default value.",
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'no-deploy',
|
||||
Description => "Specify that the update of this setting should not be deployed.",
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Perform any custom validations here. Command execution can be stopped with die().
|
||||
|
||||
my %Setting = $Kernel::OM->Get('Kernel::System::SysConfig')->SettingGet(
|
||||
Name => $Self->GetOption('setting-name'),
|
||||
Default => 1,
|
||||
);
|
||||
|
||||
if ( !%Setting ) {
|
||||
die "setting-name is invalid!";
|
||||
}
|
||||
|
||||
return if $Self->GetOption('reset');
|
||||
return if defined $Self->GetOption('valid');
|
||||
|
||||
my $SourcePath = $Self->GetOption('source-path');
|
||||
|
||||
my $Value = $Self->GetOption('value');
|
||||
|
||||
if ( $SourcePath && $Value ) {
|
||||
die "source-path or value is required but not both!";
|
||||
}
|
||||
|
||||
if ( !$SourcePath && !defined $Value ) {
|
||||
die "source-path or value is required!";
|
||||
}
|
||||
|
||||
if ( $SourcePath && !-e $SourcePath ) {
|
||||
die "File $SourcePath does not exists!";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $SettingReset = $Self->GetOption('reset');
|
||||
my $SettingValid = $Self->GetOption('valid');
|
||||
|
||||
if ($SettingReset) {
|
||||
$Self->Print("<yellow>Resetting setting value...</yellow>\n\n");
|
||||
}
|
||||
elsif ( defined $SettingValid ) {
|
||||
$Self->Print("<yellow>Updating setting valid state...</yellow>\n\n");
|
||||
}
|
||||
else {
|
||||
$Self->Print("<yellow>Updating setting value...</yellow>\n\n");
|
||||
}
|
||||
|
||||
my $SourcePath = $Self->GetOption('source-path');
|
||||
|
||||
my $EffectiveValue = $Self->GetOption('value');
|
||||
|
||||
if ($SourcePath) {
|
||||
|
||||
my $YAMLContentRef = $Kernel::OM->Get('Kernel::System::Main')->FileRead(
|
||||
Location => $SourcePath,
|
||||
Mode => 'utf8',
|
||||
Type => 'Local',
|
||||
Result => 'SCALAR',
|
||||
DisableWarnings => 1,
|
||||
);
|
||||
|
||||
if ( !$YAMLContentRef ) {
|
||||
$Self->PrintError("Could not read $SourcePath!");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$EffectiveValue = $Kernel::OM->Get('Kernel::System::YAML')->Load(
|
||||
Data => ${$YAMLContentRef},
|
||||
);
|
||||
|
||||
if ( !defined $EffectiveValue ) {
|
||||
$Self->PrintError("The content of $SourcePath is invalid");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
}
|
||||
|
||||
my $SysConfigObject = $Kernel::OM->Get('Kernel::System::SysConfig');
|
||||
|
||||
my $SettingName = $Self->GetOption('setting-name');
|
||||
|
||||
# Get default setting.
|
||||
my %Setting = $SysConfigObject->SettingGet(
|
||||
Name => $SettingName,
|
||||
Default => 1,
|
||||
);
|
||||
|
||||
if ( !IsHashRefWithData( \%Setting ) ) {
|
||||
$Self->PrintError("Setting doesn't exists!");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
my $ExclusiveLockGUID = $SysConfigObject->SettingLock(
|
||||
UserID => 1,
|
||||
Force => 1,
|
||||
DefaultID => $Setting{DefaultID},
|
||||
);
|
||||
|
||||
my $Success;
|
||||
if ($SettingReset) {
|
||||
$Success = $SysConfigObject->SettingReset(
|
||||
Name => $SettingName,
|
||||
TargetUserID => 1,
|
||||
ExclusiveLockGUID => $ExclusiveLockGUID,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Self->PrintError("Setting could not be resetted!");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
}
|
||||
elsif ( defined $SettingValid ) {
|
||||
|
||||
# Get current setting value.
|
||||
my %Setting = $SysConfigObject->SettingGet(
|
||||
Name => $SettingName,
|
||||
);
|
||||
|
||||
# Update setting with modified 'IsValid' param.
|
||||
$Success = $SysConfigObject->SettingUpdate(
|
||||
Name => $SettingName,
|
||||
IsValid => $SettingValid,
|
||||
EffectiveValue => $Setting{EffectiveValue},
|
||||
ExclusiveLockGUID => $ExclusiveLockGUID,
|
||||
UserID => 1,
|
||||
);
|
||||
if ( !$Success ) {
|
||||
$Self->PrintError("Setting valid state could not be updated!");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
}
|
||||
else {
|
||||
$Success = $SysConfigObject->SettingUpdate(
|
||||
Name => $SettingName,
|
||||
EffectiveValue => $EffectiveValue,
|
||||
ExclusiveLockGUID => $ExclusiveLockGUID,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Self->PrintError("Setting could not be updated!");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
}
|
||||
|
||||
$Success = $SysConfigObject->SettingUnlock(
|
||||
UserID => 1,
|
||||
DefaultID => $Setting{DefaultID},
|
||||
);
|
||||
|
||||
if ( $Self->GetOption('no-deploy') ) {
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
my %DeploymentResult = $SysConfigObject->ConfigurationDeploy(
|
||||
Comments => "Admin::Config::Update $SettingName",
|
||||
UserID => 1,
|
||||
Force => 1,
|
||||
DirtySettings => [$SettingName],
|
||||
);
|
||||
|
||||
if ( !$DeploymentResult{Success} ) {
|
||||
$Self->PrintError("Deployment failed!\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</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
|
||||
Reference in New Issue
Block a user