1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
# --
# Copyright (C) 2001-2021 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
|