Added reading from STDIN to DynamicField::Add, which enables piping config.
Added example calls to README.md.
This commit is contained in:
parent
be02d11c48
commit
58bb23cbbd
@ -68,10 +68,11 @@ sub Configure {
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'config',
|
||||
Description => 'Config for dynamic field. Takes either an YAML or JSON string. See also Admin::DynamicField::ConfigDump and Admin::DynamicField::ConfigBuild.',
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
Description =>
|
||||
'Config for dynamic field. Takes either an YAML or JSON string. See also Admin::DynamicField::ConfigDump and Admin::DynamicField::ConfigBuild.',
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'namespace',
|
||||
@ -82,10 +83,11 @@ sub Configure {
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'field-order',
|
||||
Description => 'Field order to place the field at. Defaults to hightest order plus 1. Per default, other fields are reordered if an occupied order number is chosen.',
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/\d+/smx,
|
||||
Description =>
|
||||
'Field order to place the field at. Defaults to hightest order plus 1. Per default, other fields are reordered if an occupied order number is chosen.',
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/\d+/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'reorder',
|
||||
@ -101,6 +103,12 @@ sub Configure {
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/\d/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'stdin',
|
||||
Description => 'Read config from STDIN.',
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -113,17 +121,32 @@ sub Run {
|
||||
# get necessary objects
|
||||
my $DynamicFieldObject = $Kernel::OM->Get('Kernel::System::DynamicField');
|
||||
|
||||
# check field order
|
||||
# check field order
|
||||
my $DynamicFieldList = $DynamicFieldObject->DynamicFieldListGet(
|
||||
ObjectType => 'All',
|
||||
Valid => 0,
|
||||
Valid => 0,
|
||||
);
|
||||
my $FieldOrder = $Self->GetOption('field-order') || max map { $_->{FieldOrder} } $DynamicFieldList->@*;
|
||||
my $FieldOrder = $Self->GetOption('field-order') || max map { $_->{FieldOrder} } $DynamicFieldList->@*;
|
||||
|
||||
# check config string
|
||||
# trying to parse as yaml and as json - if both fails, not valid
|
||||
my $PlainConfig = $Self->GetOption('config');
|
||||
my $PlainConfig;
|
||||
|
||||
# either fetch config from stdin or param
|
||||
if ( $Self->GetOption('stdin') ) {
|
||||
$Self->Print("<green>Reading config from stdin...</green>\n");
|
||||
while ( my $Line = <STDIN>) { ## no critic qw(ProhibitExplicitStdin)
|
||||
$PlainConfig .= $Line;
|
||||
}
|
||||
}
|
||||
elsif ( $Self->GetOption('config') ) {
|
||||
$PlainConfig = $Self->GetOption('config');
|
||||
}
|
||||
else {
|
||||
$Self->Print("<red>Either param config or param stdin has to be provided!</red>");
|
||||
$Self->ExitCodeError();
|
||||
}
|
||||
|
||||
# trying to parse as yaml and as json - if both fails, not valid
|
||||
$Self->Print("<yellow>Trying to parse config as YAML...</yellow>\n");
|
||||
my $ConfigHashRef = $Kernel::OM->Get('Kernel::System::YAML')->Load(
|
||||
Data => $PlainConfig,
|
||||
@ -138,26 +161,26 @@ sub Run {
|
||||
$Self->Print("<red>Parsing config as JSON failed also. Aborting.</red>\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
# check namespace
|
||||
my $Namespace = $Self->GetOption('namespace');
|
||||
my $Name = $Self->GetOption('name');
|
||||
if ( $Namespace ) {
|
||||
my $Name = $Self->GetOption('name');
|
||||
if ($Namespace) {
|
||||
$Name = "$Namespace-$Name";
|
||||
}
|
||||
}
|
||||
|
||||
# add queue
|
||||
my $Success = $Kernel::OM->Get('Kernel::System::DynamicField')->DynamicFieldAdd(
|
||||
Name => $Name,
|
||||
Label => $Self->GetOption('label'),
|
||||
FieldOrder => $FieldOrder,
|
||||
FieldType => $Self->GetOption('field-type'),
|
||||
ObjectType => $Self->GetOption('object-type'),
|
||||
Config => $ConfigHashRef,
|
||||
Reorder => $Self->GetOption('reorder') || 1,
|
||||
ValidID => $Self->GetOption('valid') || 1,
|
||||
UserID => 1,
|
||||
Name => $Name,
|
||||
Label => $Self->GetOption('label'),
|
||||
FieldOrder => $FieldOrder,
|
||||
FieldType => $Self->GetOption('field-type'),
|
||||
ObjectType => $Self->GetOption('object-type'),
|
||||
Config => $ConfigHashRef,
|
||||
Reorder => $Self->GetOption('reorder') || 1,
|
||||
ValidID => $Self->GetOption('valid') || 1,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
# error handling
|
||||
|
20
README.md
20
README.md
@ -1,6 +1,26 @@
|
||||
# consolecommands
|
||||
Custom Console Commands for OTOBO - intended to make their way into standard or die in silence.
|
||||
|
||||
For convenience, I will try to provide example calls for commands. Feel free to suggest usability improvements or to introduce them yourselves.
|
||||
|
||||
```
|
||||
~$ bin/otobo.Console.pl Admin::DynamicField::Add --name YourFieldName --label SomeLabel --valid 1 --object-type YourObjectType --field-type YourFieldType --config '---
|
||||
DefaultValue: 'SomeDefaultValue'
|
||||
Link: 'https://some.url.org'
|
||||
LinkPreview: 'https://some.url.org/preview'
|
||||
RegExList:
|
||||
- ErrorMessage: 'some meaningful error message'
|
||||
Value: '\d+'
|
||||
- ErrorMessage: 'some other meaningful error message'
|
||||
Value: '\w+'
|
||||
Tooltip: 'Some helpful tooltip'
|
||||
'
|
||||
```
|
||||
|
||||
```
|
||||
~$ mariadb -u otobo -p --execute="SELECT config FROM otobo.dynamic_field WHERE name = 'YourFieldName';" --silent --raw | bin/otobo.Console.pl Admin::DynamicField::Add --name YourNewFieldName --label SomeLabel --valid 1 --object-type YourObjectType --field-type YourFieldType --stdin
|
||||
```
|
||||
|
||||
Currently included are the following commands:
|
||||
- Kernel/System/Console/Command/Admin/DynamicField/Add.pm
|
||||
- Kernel/System/Console/Command/Admin/CustomerUser/List.pm
|
||||
|
Loading…
Reference in New Issue
Block a user