init III
This commit is contained in:
@@ -0,0 +1,188 @@
|
||||
# --
|
||||
# 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::Article::StorageSwitch;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::DateTime',
|
||||
'Kernel::System::PID',
|
||||
'Kernel::System::Ticket',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Migrate article files from one storage backend to another on the fly.');
|
||||
$Self->AddOption(
|
||||
Name => 'target',
|
||||
Description => "Specify the target backend to migrate to (ArticleStorageDB|ArticleStorageFS).",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/^(?:ArticleStorageDB|ArticleStorageFS)$/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'tickets-closed-before-date',
|
||||
Description => "Only process tickets closed before given ISO date.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/^\d{4}-\d{2}-\d{2}[ ]\d{2}:\d{2}:\d{2}$/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'tickets-closed-before-days',
|
||||
Description => "Only process tickets closed more than ... days ago.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/^\d+$/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'tolerant',
|
||||
Description => "Continue after failures.",
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'micro-sleep',
|
||||
Description => "Specify microseconds to sleep after every ticket to reduce system load (e.g. 1000).",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/^\d+$/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'force-pid',
|
||||
Description => "Start even if another process is still registered in the database.",
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
|
||||
my $Name = $Self->Name();
|
||||
|
||||
$Self->AdditionalHelp(<<"EOF");
|
||||
The <green>$Name</green> command migrates article data from one storage backend to another on the fly, for example from DB to FS:
|
||||
|
||||
<green>otrs.Console.pl $Self->{Name} --target ArticleStorageFS</green>
|
||||
|
||||
You can specify limits for the tickets migrated with <yellow>--tickets-closed-before-date</yellow> and <yellow>--tickets-closed-before-days</yellow>.
|
||||
|
||||
To reduce load on the database for a running system, you can use the <yellow>--micro-sleep</yellow> parameter. The command will pause for the specified amount of microseconds after each ticket.
|
||||
|
||||
<green>otrs.Console.pl $Self->{Name} --target ArticleStorageFS --micro-sleep 1000</green>
|
||||
EOF
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ($Self) = @_;
|
||||
|
||||
my $PIDCreated = $Kernel::OM->Get('Kernel::System::PID')->PIDCreate(
|
||||
Name => $Self->Name(),
|
||||
Force => $Self->GetOption('force-pid'),
|
||||
TTL => 60 * 60 * 24 * 3,
|
||||
);
|
||||
if ( !$PIDCreated ) {
|
||||
my $Error = "Unable to register the process in the database. Is another instance still running?\n";
|
||||
$Error .= "You can use --force-pid to override this check.\n";
|
||||
die $Error;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ($Self) = @_;
|
||||
|
||||
# disable ticket events
|
||||
$Kernel::OM->Get('Kernel::Config')->{'Ticket::EventModulePost'} = {};
|
||||
|
||||
# extended input validation
|
||||
my %SearchParams;
|
||||
|
||||
if ( $Self->GetOption('tickets-closed-before-date') ) {
|
||||
%SearchParams = (
|
||||
StateType => 'Closed',
|
||||
TicketCloseTimeOlderDate => $Self->GetOption('tickets-closed-before-date'),
|
||||
);
|
||||
}
|
||||
elsif ( $Self->GetOption('tickets-closed-before-days') ) {
|
||||
my $Seconds = $Self->GetOption('tickets-closed-before-days') * 60 * 60 * 24;
|
||||
|
||||
my $OlderDTObject = $Kernel::OM->Create('Kernel::System::DateTime');
|
||||
$OlderDTObject->Subtract( Seconds => $Seconds );
|
||||
|
||||
%SearchParams = (
|
||||
StateType => 'Closed',
|
||||
TicketCloseTimeOlderDate => $OlderDTObject->ToString(),
|
||||
);
|
||||
}
|
||||
|
||||
# If Archive system is enabled, take into account archived tickets as well.
|
||||
# See bug#13945 (https://bugs.otrs.org/show_bug.cgi?id=13945).
|
||||
if ( $Kernel::OM->Get('Kernel::Config')->{'Ticket::ArchiveSystem'} ) {
|
||||
$SearchParams{ArchiveFlags} = [ 'y', 'n' ];
|
||||
}
|
||||
|
||||
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
|
||||
|
||||
my @TicketIDs = $TicketObject->TicketSearch(
|
||||
%SearchParams,
|
||||
Result => 'ARRAY',
|
||||
OrderBy => 'Up',
|
||||
Limit => 1_000_000_000,
|
||||
UserID => 1,
|
||||
Permission => 'ro',
|
||||
);
|
||||
|
||||
my $Count = 0;
|
||||
my $CountTotal = scalar @TicketIDs;
|
||||
|
||||
my $Target = $Self->GetOption('target');
|
||||
my %Target2Source = (
|
||||
ArticleStorageFS => 'ArticleStorageDB',
|
||||
ArticleStorageDB => 'ArticleStorageFS',
|
||||
);
|
||||
|
||||
my $MicroSleep = $Self->GetOption('micro-sleep');
|
||||
my $Tolerant = $Self->GetOption('tolerant');
|
||||
|
||||
TICKETID:
|
||||
for my $TicketID (@TicketIDs) {
|
||||
|
||||
$Count++;
|
||||
|
||||
$Self->Print("$Count/$CountTotal (TicketID:$TicketID)\n");
|
||||
|
||||
my $Success = $TicketObject->TicketArticleStorageSwitch(
|
||||
TicketID => $TicketID,
|
||||
Source => $Target2Source{$Target},
|
||||
Destination => $Target,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
return $Self->ExitCodeError() if !$Tolerant && !$Success;
|
||||
|
||||
Time::HiRes::usleep($MicroSleep) if ($MicroSleep);
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
|
||||
return $Self->ExitCodeOk();
|
||||
|
||||
}
|
||||
|
||||
sub PostRun {
|
||||
my ($Self) = @_;
|
||||
|
||||
return $Kernel::OM->Get('Kernel::System::PID')->PIDDelete( Name => $Self->Name() );
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,110 @@
|
||||
# --
|
||||
# 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::CommunicationChannel::Drop;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::CommunicationChannel',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description(
|
||||
'Drop a communication channel (with its data) that is no longer available in the system.'
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'channel-id',
|
||||
Description => 'The ID of the communication channel to drop.',
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/\A\d+\z/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'channel-name',
|
||||
Description => 'The name of the communication channel to drop.',
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/\A\w+\z/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'force',
|
||||
Description => 'Force drop the channel even if there is existing article data, use with care.',
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $ChannelID = $Self->GetOption('channel-id');
|
||||
my $ChannelName = $Self->GetOption('channel-name');
|
||||
|
||||
if ( !$ChannelID && !$ChannelName ) {
|
||||
die "Please provide either --channel-id or --channel-name option.\n";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Deleting communication channel...</yellow>\n");
|
||||
|
||||
my $ChannelID = $Self->GetOption('channel-id');
|
||||
my $ChannelName = $Self->GetOption('channel-name');
|
||||
|
||||
my $CommunicationChannelObject = $Kernel::OM->Get('Kernel::System::CommunicationChannel');
|
||||
|
||||
my %CommunicationChannel = $CommunicationChannelObject->ChannelGet(
|
||||
ChannelID => $ChannelID,
|
||||
ChannelName => $ChannelName,
|
||||
);
|
||||
|
||||
if ( !%CommunicationChannel ) {
|
||||
if ($ChannelID) {
|
||||
$Self->PrintError("Channel with the ID $ChannelID could not be found!");
|
||||
}
|
||||
else {
|
||||
$Self->PrintError("Channel '$ChannelName' could not be found!");
|
||||
}
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
# Try to drop the channel.
|
||||
my $Success = $CommunicationChannelObject->ChannelDrop(
|
||||
ChannelID => $ChannelID,
|
||||
ChannelName => $ChannelName,
|
||||
DropArticleData => $Self->GetOption('force'),
|
||||
);
|
||||
if ( !$Success ) {
|
||||
$Self->PrintError('Could not drop a channel!');
|
||||
if ( !$Self->GetOption('force') ) {
|
||||
$Self->Print("<yellow>Channel might still have associated data in the system.</yellow>\n");
|
||||
$Self->Print("If you want to drop this data as well, please use the <green>--force</green> switch.\n");
|
||||
}
|
||||
else {
|
||||
$Self->Print("<yellow>Please note that only invalid channels can be dropped.</yellow>\n");
|
||||
}
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,64 @@
|
||||
# --
|
||||
# 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::CommunicationChannel::Sync;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::CommunicationChannel',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Synchronize registered communication channels in the system.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Syncing communication channels...</yellow>\n");
|
||||
|
||||
my $CommunicationChannelObject = $Kernel::OM->Get('Kernel::System::CommunicationChannel');
|
||||
|
||||
# Sync the channels.
|
||||
my %Result = $CommunicationChannelObject->ChannelSync(
|
||||
UserID => 1,
|
||||
);
|
||||
if (%Result) {
|
||||
if ( $Result{ChannelsAdded} ) {
|
||||
$Self->Print(
|
||||
sprintf( "<yellow>%s</yellow> channels were added.\n", scalar @{ $Result{ChannelsAdded} || [] } )
|
||||
);
|
||||
}
|
||||
if ( $Result{ChannelsUpdated} ) {
|
||||
$Self->Print(
|
||||
sprintf( "<yellow>%s</yellow> channels were updated.\n", scalar @{ $Result{ChannelsUpdated} || [] } )
|
||||
);
|
||||
}
|
||||
if ( $Result{ChannelsInvalid} ) {
|
||||
$Self->Print(
|
||||
sprintf( "<red>%s</red> channels are invalid.\n", scalar @{ $Result{ChannelsInvalid} || [] } )
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$Self->Print("<yellow>All channels were already in sync with configuration.</yellow>\n");
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -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
|
||||
@@ -0,0 +1,113 @@
|
||||
# --
|
||||
# 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::CustomerCompany::Add;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::CustomerCompany',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Add a customer company.');
|
||||
$Self->AddOption(
|
||||
Name => 'customer-id',
|
||||
Description => "Company ID for the new customer company.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'name',
|
||||
Description => "Company name for the new customer company.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'street',
|
||||
Description => "Street of the new customer company.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'zip',
|
||||
Description => "ZIP code of the new customer company.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'city',
|
||||
Description => "City of the new customer company.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'country',
|
||||
Description => "Country of the new customer company.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'url',
|
||||
Description => "URL of the new customer company.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'comment',
|
||||
Description => "Comment for the new customer company.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Adding a new customer company...</yellow>\n");
|
||||
|
||||
# add customer company
|
||||
if (
|
||||
!$Kernel::OM->Get('Kernel::System::CustomerCompany')->CustomerCompanyAdd(
|
||||
CustomerID => $Self->GetOption('customer-id'),
|
||||
CustomerCompanyName => $Self->GetOption('name'),
|
||||
CustomerCompanyStreet => $Self->GetOption('street'),
|
||||
CustomerCompanyZIP => $Self->GetOption('zip'),
|
||||
CustomerCompanyCity => $Self->GetOption('city'),
|
||||
CustomerCompanyCountry => $Self->GetOption('country'),
|
||||
CustomerCompanyURL => $Self->GetOption('url'),
|
||||
CustomerCompanyComment => $Self->GetOption('comment'),
|
||||
ValidID => 1,
|
||||
UserID => 1,
|
||||
)
|
||||
)
|
||||
{
|
||||
$Self->PrintError("Can't add customer company.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,99 @@
|
||||
# --
|
||||
# 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::CustomerUser::Add;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::CustomerUser',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Add a customer user.');
|
||||
$Self->AddOption(
|
||||
Name => 'user-name',
|
||||
Description => "User name for the new customer user.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'first-name',
|
||||
Description => "First name of the new customer user.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'last-name',
|
||||
Description => "Last name of the new customer user.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'email-address',
|
||||
Description => "Email address of the new customer user.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'customer-id',
|
||||
Description => "Customer ID for the new customer user.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'password',
|
||||
Description => "Password for the new customer user. If left empty, a password will be generated automatically.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Adding a new customer user...</yellow>\n");
|
||||
|
||||
# add customer user
|
||||
if (
|
||||
!$Kernel::OM->Get('Kernel::System::CustomerUser')->CustomerUserAdd(
|
||||
Source => 'CustomerUser',
|
||||
UserLogin => $Self->GetOption('user-name'),
|
||||
UserFirstname => $Self->GetOption('first-name'),
|
||||
UserLastname => $Self->GetOption('last-name'),
|
||||
UserCustomerID => $Self->GetOption('customer-id'),
|
||||
UserPassword => $Self->GetOption('password'),
|
||||
UserEmail => $Self->GetOption('email-address'),
|
||||
UserID => 1,
|
||||
ChangeUserID => 1,
|
||||
ValidID => 1,
|
||||
)
|
||||
)
|
||||
{
|
||||
$Self->PrintError("Can't add customer user.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,79 @@
|
||||
# --
|
||||
# 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::CustomerUser::SetPassword;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::CustomerUser',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Update the password for a customer user.');
|
||||
$Self->AddArgument(
|
||||
Name => 'user',
|
||||
Description => "Specify the user login of the agent/customer to be updated.",
|
||||
Required => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddArgument(
|
||||
Name => 'password',
|
||||
Description => "Set a new password for the user (a password will be generated otherwise).",
|
||||
Required => 0,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $Login = $Self->GetArgument('user');
|
||||
|
||||
$Self->Print("<yellow>Setting password for user $Login...</yellow>\n");
|
||||
|
||||
my $CustomerUserObject = $Kernel::OM->Get('Kernel::System::CustomerUser');
|
||||
my %CustomerUserList = $CustomerUserObject->CustomerSearch(
|
||||
UserLogin => $Login,
|
||||
);
|
||||
|
||||
if ( !scalar %CustomerUserList ) {
|
||||
$Self->PrintError("No customer user found with login '$Login'!\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
# if no password has been provided, generate one
|
||||
my $Password = $Self->GetArgument('password');
|
||||
if ( !$Password ) {
|
||||
$Password = $CustomerUserObject->GenerateRandomPassword( Size => 12 );
|
||||
$Self->Print("<yellow>Generated password '$Password'.</yellow>\n");
|
||||
}
|
||||
|
||||
my $Result = $CustomerUserObject->SetPassword(
|
||||
UserLogin => $Login,
|
||||
PW => $Password,
|
||||
);
|
||||
|
||||
if ( !$Result ) {
|
||||
$Self->PrintError("Failed to set password!\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Successfully set password for customer user '$Login'.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
278
Perl OTRS/Kernel/System/Console/Command/Admin/FAQ/Import.pm
Normal file
278
Perl OTRS/Kernel/System/Console/Command/Admin/FAQ/Import.pm
Normal file
@@ -0,0 +1,278 @@
|
||||
# --
|
||||
# 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::FAQ::Import;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::CSV',
|
||||
'Kernel::System::DB',
|
||||
'Kernel::System::FAQ',
|
||||
'Kernel::System::Group',
|
||||
'Kernel::System::Main',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('FAQ import tool.');
|
||||
$Self->AddOption(
|
||||
Name => 'separator',
|
||||
Description => "Defines the separator for data in CSV file (default ';').",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'quote',
|
||||
Description => "Defines the quote for data in CSV file (default '\"').",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddArgument(
|
||||
Name => 'source-path',
|
||||
Description => "Specify the path to the file which containing FAQ items for importing.",
|
||||
Required => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
$Self->AdditionalHelp(
|
||||
"<yellow>Format of the CSV file:\n
|
||||
title;category;language;statetype;field1;field2;field3;field4;field5;field6;keywords
|
||||
</yellow>\n"
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $SourcePath = $Self->GetArgument('source-path');
|
||||
if ( $SourcePath && !-r $SourcePath ) {
|
||||
die "File $SourcePath does not exist, can not be read.\n";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Importing FAQ items...</yellow>\n");
|
||||
$Self->Print( "<yellow>" . ( '=' x 69 ) . "</yellow>\n" );
|
||||
|
||||
my $SourcePath = $Self->GetArgument('source-path');
|
||||
$Self->Print("<yellow>Read File $SourcePath </yellow>\n\n");
|
||||
|
||||
# read source file
|
||||
my $CSVStringRef = $Kernel::OM->Get('Kernel::System::Main')->FileRead(
|
||||
Location => $SourcePath,
|
||||
Result => 'SCALAR',
|
||||
Mode => 'binmode',
|
||||
);
|
||||
|
||||
if ( !$CSVStringRef ) {
|
||||
$Self->PrintError("Can't read file $SourcePath.\nImport aborted.\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
my $Separator = $Self->GetOption('separator') || ';';
|
||||
my $Quote = $Self->GetOption('quote') || '"';
|
||||
|
||||
# read CSV data
|
||||
my $DataRef = $Kernel::OM->Get('Kernel::System::CSV')->CSV2Array(
|
||||
String => $$CSVStringRef,
|
||||
Separator => $Separator,
|
||||
Quote => $Quote,
|
||||
);
|
||||
|
||||
if ( !$DataRef ) {
|
||||
$Self->PrintError("Error occurred. Import impossible! See Syslog for details.\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
my $FAQObject = $Kernel::OM->Get('Kernel::System::FAQ');
|
||||
|
||||
my %LanguageID = reverse $FAQObject->LanguageList(
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
my %StateTypeID = reverse %{ $FAQObject->StateTypeList( UserID => 1 ) };
|
||||
|
||||
# get group id for FAQ group
|
||||
my $FAQGroupID = $Kernel::OM->Get('Kernel::System::Group')->GroupLookup(
|
||||
Group => 'faq',
|
||||
);
|
||||
|
||||
my $LineCounter;
|
||||
my $SuccessCount = 0;
|
||||
my $UnScuccessCount = 0;
|
||||
|
||||
ROWREF:
|
||||
for my $RowRef ( @{$DataRef} ) {
|
||||
|
||||
$LineCounter++;
|
||||
|
||||
my (
|
||||
$Title, $CategoryString, $Language, $StateType,
|
||||
$Field1, $Field2, $Field3, $Field4, $Field5, $Field6, $Keywords
|
||||
) = @{$RowRef};
|
||||
|
||||
# check language
|
||||
if ( !$LanguageID{$Language} ) {
|
||||
$Self->PrintError("Error: Could not import line $LineCounter. Language '$Language' does not exist.\n");
|
||||
next ROWREF;
|
||||
}
|
||||
|
||||
# check state type
|
||||
if ( !$StateTypeID{$StateType} ) {
|
||||
$Self->PrintError("Error: Could not import line $LineCounter. State '$StateType' does not exist.\n");
|
||||
next ROWREF;
|
||||
}
|
||||
|
||||
# get subcategories
|
||||
my @CategoryArray = split /::/, $CategoryString;
|
||||
|
||||
# check each subcategory if it exists
|
||||
my $CategoryID;
|
||||
my $ParentID = 0;
|
||||
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
for my $Category (@CategoryArray) {
|
||||
|
||||
# get the category id
|
||||
$DBObject->Prepare(
|
||||
SQL => 'SELECT id FROM faq_category '
|
||||
. 'WHERE valid_id = 1 AND name = ? AND parent_id = ?',
|
||||
Bind => [ \$Category, \$ParentID ],
|
||||
Limit => 1,
|
||||
);
|
||||
my @Result;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
push( @Result, $Row[0] );
|
||||
}
|
||||
$CategoryID = $Result[0];
|
||||
|
||||
# create category if it does not exist
|
||||
if ( !$CategoryID ) {
|
||||
$CategoryID = $FAQObject->CategoryAdd(
|
||||
Name => $Category,
|
||||
ParentID => $ParentID,
|
||||
ValidID => 1,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
# add new category to FAQ group
|
||||
$FAQObject->SetCategoryGroup(
|
||||
CategoryID => $CategoryID,
|
||||
GroupIDs => [$FAQGroupID],
|
||||
UserID => 1,
|
||||
);
|
||||
}
|
||||
|
||||
# set new parent id
|
||||
$ParentID = $CategoryID;
|
||||
}
|
||||
|
||||
# check category
|
||||
if ( !$CategoryID ) {
|
||||
$Self->PrintError(
|
||||
"Error: Could not import line $LineCounter. Category '$CategoryString' could not be created.\n"
|
||||
);
|
||||
next ROW;
|
||||
}
|
||||
|
||||
# convert StateType to State
|
||||
my %StateLookup = reverse $FAQObject->StateList( UserID => 1 );
|
||||
my $StateID;
|
||||
|
||||
STATENAME:
|
||||
for my $StateName ( sort keys %StateLookup ) {
|
||||
if ( $StateName =~ m{\A $StateType }msxi ) {
|
||||
$StateID = $StateLookup{$StateName};
|
||||
last STATENAME;
|
||||
}
|
||||
}
|
||||
|
||||
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
|
||||
|
||||
# set content type
|
||||
my $ContentType = 'text/plain';
|
||||
if ( $ConfigObject->Get('Frontend::RichText') && $ConfigObject->Get('FAQ::Item::HTML') ) {
|
||||
$ContentType = 'text/html';
|
||||
}
|
||||
|
||||
# add FAQ article
|
||||
my $ItemID = $FAQObject->FAQAdd(
|
||||
Title => $Title,
|
||||
CategoryID => $CategoryID,
|
||||
StateID => $StateID,
|
||||
LanguageID => $LanguageID{$Language},
|
||||
Field1 => $Field1,
|
||||
Field2 => $Field2,
|
||||
Field3 => $Field3,
|
||||
Field4 => $Field4,
|
||||
Field5 => $Field5,
|
||||
Field6 => $Field6,
|
||||
Keywords => $Keywords || '',
|
||||
Approved => 1,
|
||||
UserID => 1,
|
||||
ContentType => $ContentType,
|
||||
);
|
||||
|
||||
# check success
|
||||
if ($ItemID) {
|
||||
$SuccessCount++;
|
||||
}
|
||||
else {
|
||||
$UnScuccessCount++;
|
||||
$Self->PrintError("Could not import line $LineCounter.\n");
|
||||
}
|
||||
}
|
||||
|
||||
if ($SuccessCount) {
|
||||
$Self->Print("<green>Successfully imported $SuccessCount FAQ item(s).</green>\n");
|
||||
}
|
||||
if ($UnScuccessCount) {
|
||||
$Self->Print("\n<red>Unsuccessfully imported $UnScuccessCount FAQ items(s).</red>\n\n");
|
||||
|
||||
$Self->Print("<red>Import complete with errors.</red>\n");
|
||||
$Self->Print( "<yellow>" . ( '=' x 69 ) . "</yellow>\n" );
|
||||
|
||||
$Self->Print("<red>Fail</red>\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("\n");
|
||||
|
||||
$Self->Print("<green>Import complete.</green>\n");
|
||||
$Self->Print( "<yellow>" . ( '=' x 69 ) . "</yellow>\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
|
||||
65
Perl OTRS/Kernel/System/Console/Command/Admin/Group/Add.pm
Normal file
65
Perl OTRS/Kernel/System/Console/Command/Admin/Group/Add.pm
Normal file
@@ -0,0 +1,65 @@
|
||||
# --
|
||||
# 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::Group::Add;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Group'
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Create a new group.');
|
||||
$Self->AddOption(
|
||||
Name => 'name',
|
||||
Description => "Name of the new group.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'comment',
|
||||
Description => "Comment for the new group.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Creating a new group...</yellow>\n");
|
||||
|
||||
my $Success = $Kernel::OM->Get('Kernel::System::Group')->GroupAdd(
|
||||
UserID => 1,
|
||||
ValidID => 1,
|
||||
Comment => $Self->GetOption('comment'),
|
||||
Name => $Self->GetOption('name'),
|
||||
);
|
||||
|
||||
# error handling
|
||||
if ( !$Success ) {
|
||||
$Self->PrintError("Can't create group.\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,105 @@
|
||||
# --
|
||||
# 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::Group::CustomerLink;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::CustomerGroup',
|
||||
'Kernel::System::CustomerUser',
|
||||
'Kernel::System::Group',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Connect a customer user to a group.');
|
||||
$Self->AddOption(
|
||||
Name => 'customer-user-login',
|
||||
Description => 'Login name of the customer who should be linked to the given group.',
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'group-name',
|
||||
Description => 'Group name of the group the given customer should be linked to.',
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'permission',
|
||||
Description => 'Permission (ro|rw) the customer user should have for the group he is going to be linked to.',
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/(ro|rw)/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->{CustomerLogin} = $Self->GetOption('customer-user-login');
|
||||
$Self->{GroupName} = $Self->GetOption('group-name');
|
||||
|
||||
# check role
|
||||
my $CustomerName = $Kernel::OM->Get('Kernel::System::CustomerUser')->CustomerName(
|
||||
UserLogin => $Self->{CustomerLogin},
|
||||
);
|
||||
if ( !$CustomerName ) {
|
||||
die "Customer $Self->{CustomerLogin} does not exist.\n";
|
||||
}
|
||||
|
||||
# check group
|
||||
$Self->{GroupID} = $Kernel::OM->Get('Kernel::System::Group')->GroupLookup( Group => $Self->{GroupName} );
|
||||
if ( !$Self->{GroupID} ) {
|
||||
die "Group $Self->{GroupName} does not exist.\n";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Trying to link customer $Self->{CustomerLogin} to group $Self->{GroupName}...</yellow>\n");
|
||||
|
||||
my %Permissions;
|
||||
for my $Permission (qw(ro rw)) {
|
||||
$Permissions{$Permission} = ( $Self->GetOption('permission') eq $Permission ) ? 1 : 0;
|
||||
}
|
||||
|
||||
# add user 2 group
|
||||
if (
|
||||
!$Kernel::OM->Get('Kernel::System::CustomerGroup')->GroupMemberAdd(
|
||||
UID => $Self->{CustomerLogin},
|
||||
GID => $Self->{GroupID},
|
||||
UserID => 1,
|
||||
ValidID => 1,
|
||||
Permission => {
|
||||
%Permissions,
|
||||
},
|
||||
)
|
||||
)
|
||||
{
|
||||
$Self->PrintError("Can't add user to group.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
102
Perl OTRS/Kernel/System/Console/Command/Admin/Group/RoleLink.pm
Normal file
102
Perl OTRS/Kernel/System/Console/Command/Admin/Group/RoleLink.pm
Normal file
@@ -0,0 +1,102 @@
|
||||
# --
|
||||
# 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::Group::RoleLink;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Group',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Connect a role to a group.');
|
||||
$Self->AddOption(
|
||||
Name => 'role-name',
|
||||
Description => 'Name of the role which should be linked to the given group.',
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'group-name',
|
||||
Description => 'Group name of the group the given role should be linked to.',
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'permission',
|
||||
Description =>
|
||||
'Permissions (ro|move_into|create|note|owner|priority|rw) the role should have for the group which it is going to be linked to.',
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
Multiple => 1,
|
||||
ValueRegex => qr/(ro|move_into|create|note|owner|priority|rw)/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->{RoleName} = $Self->GetOption('role-name');
|
||||
$Self->{GroupName} = $Self->GetOption('group-name');
|
||||
|
||||
# check role
|
||||
$Self->{RoleID} = $Kernel::OM->Get('Kernel::System::Group')->RoleLookup( Role => $Self->{RoleName} );
|
||||
if ( !$Self->{RoleID} ) {
|
||||
die "Role $Self->{RoleName} does not exist.\n";
|
||||
}
|
||||
|
||||
# check group
|
||||
$Self->{GroupID} = $Kernel::OM->Get('Kernel::System::Group')->GroupLookup( Group => $Self->{GroupName} );
|
||||
if ( !$Self->{GroupID} ) {
|
||||
die "Group $Self->{GroupName} does not exist.\n";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Trying to link role $Self->{RoleName} to group $Self->{GroupName}...</yellow>\n");
|
||||
|
||||
my %Permissions;
|
||||
for my $Permission (qw(ro move_into create note owner priority rw)) {
|
||||
$Permissions{$Permission} = ( grep { $_ eq $Permission } @{ $Self->GetOption('permission') // [] } ) ? 1 : 0;
|
||||
}
|
||||
|
||||
# add user 2 group
|
||||
if (
|
||||
!$Kernel::OM->Get('Kernel::System::Group')->PermissionGroupRoleAdd(
|
||||
RID => $Self->{RoleID},
|
||||
GID => $Self->{GroupID},
|
||||
UserID => 1,
|
||||
Permission => {
|
||||
%Permissions,
|
||||
},
|
||||
)
|
||||
)
|
||||
{
|
||||
$Self->PrintError("Can't add role to group.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
103
Perl OTRS/Kernel/System/Console/Command/Admin/Group/UserLink.pm
Normal file
103
Perl OTRS/Kernel/System/Console/Command/Admin/Group/UserLink.pm
Normal file
@@ -0,0 +1,103 @@
|
||||
# --
|
||||
# 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::Group::UserLink;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Group',
|
||||
'Kernel::System::User',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Connect a user to a group.');
|
||||
$Self->AddOption(
|
||||
Name => 'user-name',
|
||||
Description => 'Name of the user who should be linked to the given group.',
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'group-name',
|
||||
Description => 'Name of the group the given user should be linked to.',
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'permission',
|
||||
Description =>
|
||||
'Permissions (ro|move_into|create|owner|priority|rw) the given user should have for the group he is going to be linked to.',
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/(ro|move_into|create|owner|priority|rw)/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->{UserName} = $Self->GetOption('user-name');
|
||||
$Self->{GroupName} = $Self->GetOption('group-name');
|
||||
|
||||
# check user
|
||||
$Self->{UserID} = $Kernel::OM->Get('Kernel::System::User')->UserLookup( UserLogin => $Self->{UserName} );
|
||||
if ( !$Self->{UserID} ) {
|
||||
die "User $Self->{UserName} does not exist.\n";
|
||||
}
|
||||
|
||||
# check group
|
||||
$Self->{GroupID} = $Kernel::OM->Get('Kernel::System::Group')->GroupLookup( Group => $Self->{GroupName} );
|
||||
if ( !$Self->{GroupID} ) {
|
||||
die "Group $Self->{GroupName} does not exist.\n";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Trying to link user $Self->{UserName} to group $Self->{GroupName}...</yellow>\n");
|
||||
|
||||
my %Permissions;
|
||||
for my $Permission (qw(ro move_into create owner priority rw)) {
|
||||
$Permissions{$Permission} = ( $Self->GetOption('permission') eq $Permission ) ? 1 : 0;
|
||||
}
|
||||
|
||||
# add user 2 group
|
||||
if (
|
||||
!$Kernel::OM->Get('Kernel::System::Group')->PermissionGroupUserAdd(
|
||||
UID => $Self->{UserID},
|
||||
GID => $Self->{GroupID},
|
||||
Active => 1,
|
||||
UserID => 1,
|
||||
Permission => {
|
||||
%Permissions,
|
||||
},
|
||||
)
|
||||
)
|
||||
{
|
||||
$Self->PrintError("Can't add user to group.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done</green>.\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,387 @@
|
||||
# --
|
||||
# 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::Change::Check;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(
|
||||
Kernel::System::Console::BaseCommand
|
||||
Kernel::System::EventHandler);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::DateTime',
|
||||
'Kernel::System::PID',
|
||||
'Kernel::System::ITSMChange',
|
||||
'Kernel::System::ITSMChange::ITSMWorkOrder',
|
||||
'Kernel::System::ITSMChange::History',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Check if ITSM changes have reached specific times.');
|
||||
$Self->AddOption(
|
||||
Name => 'force-pid',
|
||||
Description => "Start even if another process is still registered in the database.",
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# get PID object
|
||||
my $PIDObject = $Kernel::OM->Get('Kernel::System::PID');
|
||||
|
||||
# create PID lock
|
||||
my $PIDCreated = $PIDObject->PIDCreate(
|
||||
Name => $Self->Name(),
|
||||
Force => $Self->GetOption('force-pid'),
|
||||
TTL => 60 * 60 * 2,
|
||||
);
|
||||
if ( !$PIDCreated ) {
|
||||
my $Error = "Unable to register the process in the database. Is another instance still running?\n";
|
||||
$Error .= "You can use --force-pid to override this check.\n";
|
||||
die $Error;
|
||||
}
|
||||
|
||||
# init of event handler
|
||||
$Self->EventHandlerInit(
|
||||
Config => 'ITSMChangeCronjob::EventModule',
|
||||
);
|
||||
|
||||
# get time object
|
||||
my $DateTimeObject = $Kernel::OM->Create('Kernel::System::DateTime');
|
||||
|
||||
$Self->{SystemTime} = $DateTimeObject->ToEpoch();
|
||||
$Self->{Now} = $DateTimeObject->ToString();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Checking ITSM changes...</yellow>\n");
|
||||
|
||||
# get change object
|
||||
my $ChangeObject = $Kernel::OM->Get('Kernel::System::ITSMChange');
|
||||
|
||||
# notifications for changes' plannedXXXtime events
|
||||
for my $Type (qw(StartTime EndTime)) {
|
||||
|
||||
# get changes with PlannedStartTime older than now
|
||||
my $PlannedChangeIDs = $ChangeObject->ChangeSearch(
|
||||
"Planned${Type}OlderDate" => $Self->{Now},
|
||||
MirrorDB => 1,
|
||||
UserID => 1,
|
||||
) || [];
|
||||
|
||||
CHANGEID:
|
||||
for my $ChangeID ( @{$PlannedChangeIDs} ) {
|
||||
|
||||
# get change data
|
||||
my $Change = $ChangeObject->ChangeGet(
|
||||
ChangeID => $ChangeID,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
# skip change if there is already an actualXXXtime set or notification was sent
|
||||
next CHANGEID if $Change->{"Actual$Type"};
|
||||
|
||||
my $LastNotificationSentDate = $Self->ChangeNotificationSent(
|
||||
ChangeID => $ChangeID,
|
||||
Type => "Planned${Type}",
|
||||
);
|
||||
|
||||
my $AlreadySentWithinPeriod = $Self->SentWithinPeriod(
|
||||
LastNotificationSentDate => $LastNotificationSentDate,
|
||||
);
|
||||
|
||||
next CHANGEID if $AlreadySentWithinPeriod;
|
||||
|
||||
# trigger ChangePlannedStartTimeReachedPost-Event
|
||||
$Self->EventHandler(
|
||||
Event => "ChangePlanned${Type}ReachedPost",
|
||||
Data => {
|
||||
ChangeID => $ChangeID,
|
||||
},
|
||||
UserID => 1,
|
||||
);
|
||||
}
|
||||
|
||||
# get changes with actualxxxtime
|
||||
my $ActualChangeIDs = $ChangeObject->ChangeSearch(
|
||||
"Actual${Type}OlderDate" => $Self->{Now},
|
||||
MirrorDB => 1,
|
||||
UserID => 1,
|
||||
) || [];
|
||||
|
||||
ACTUALCHANGEID:
|
||||
for my $ChangeID ( @{$ActualChangeIDs} ) {
|
||||
|
||||
# get change data
|
||||
my $Change = $ChangeObject->ChangeGet(
|
||||
ChangeID => $ChangeID,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
my $LastNotificationSentDate = $Self->ChangeNotificationSent(
|
||||
ChangeID => $ChangeID,
|
||||
Type => "Actual${Type}",
|
||||
);
|
||||
|
||||
next ACTUALCHANGEID if $LastNotificationSentDate;
|
||||
|
||||
# trigger Event
|
||||
$Self->EventHandler(
|
||||
Event => "ChangeActual${Type}ReachedPost",
|
||||
Data => {
|
||||
ChangeID => $ChangeID,
|
||||
},
|
||||
UserID => 1,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
# get changes with RequestedTimeOlderDate
|
||||
my $RequestedTimeChangeIDs = $ChangeObject->ChangeSearch(
|
||||
RequestedTimeOlderDate => $Self->{Now},
|
||||
MirrorDB => 1,
|
||||
UserID => 1,
|
||||
) || [];
|
||||
|
||||
CHANGEID:
|
||||
for my $ChangeID ( @{$RequestedTimeChangeIDs} ) {
|
||||
|
||||
# get change data
|
||||
my $Change = $ChangeObject->ChangeGet(
|
||||
ChangeID => $ChangeID,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
my $LastNotificationSentDate = $Self->ChangeNotificationSent(
|
||||
ChangeID => $ChangeID,
|
||||
Type => "RequestedTime",
|
||||
);
|
||||
|
||||
next CHANGEID if $LastNotificationSentDate;
|
||||
|
||||
# trigger Event
|
||||
$Self->EventHandler(
|
||||
Event => "ChangeRequestedTimeReachedPost",
|
||||
Data => {
|
||||
ChangeID => $ChangeID,
|
||||
},
|
||||
UserID => 1,
|
||||
);
|
||||
}
|
||||
|
||||
# notifications for workorders' plannedXXXtime events
|
||||
for my $Type (qw(StartTime EndTime)) {
|
||||
|
||||
my $WorkOrderObject = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder');
|
||||
|
||||
# get workorders with PlannedStartTime older than now
|
||||
my $PlannedWorkOrderIDs = $WorkOrderObject->WorkOrderSearch(
|
||||
"Planned${Type}OlderDate" => $Self->{Now},
|
||||
MirrorDB => 1,
|
||||
UserID => 1,
|
||||
) || [];
|
||||
|
||||
WORKORDERID:
|
||||
for my $WorkOrderID ( @{$PlannedWorkOrderIDs} ) {
|
||||
|
||||
# get workorder data
|
||||
my $WorkOrder = $WorkOrderObject->WorkOrderGet(
|
||||
WorkOrderID => $WorkOrderID,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
# skip workorder if there is already an actualXXXtime set or notification was sent
|
||||
next WORKORDERID if $WorkOrder->{"Actual$Type"};
|
||||
|
||||
my $LastNotificationSentDate = $Self->WorkOrderNotificationSent(
|
||||
WorkOrderID => $WorkOrderID,
|
||||
Type => "Planned${Type}",
|
||||
);
|
||||
|
||||
my $AlreadySentWithinPeriod = $Self->SentWithinPeriod(
|
||||
LastNotificationSentDate => $LastNotificationSentDate,
|
||||
);
|
||||
|
||||
next WORKORDERID if $AlreadySentWithinPeriod;
|
||||
|
||||
# trigger WorkOrderPlannedStartTimeReachedPost-Event
|
||||
$Self->EventHandler(
|
||||
Event => "WorkOrderPlanned${Type}ReachedPost",
|
||||
Data => {
|
||||
WorkOrderID => $WorkOrderID,
|
||||
ChangeID => $WorkOrder->{ChangeID},
|
||||
},
|
||||
UserID => 1,
|
||||
);
|
||||
}
|
||||
|
||||
# get workorders with actualxxxtime
|
||||
my $ActualWorkOrderIDs = $WorkOrderObject->WorkOrderSearch(
|
||||
"Actual${Type}OlderDate" => $Self->{Now},
|
||||
MirrorDB => 1,
|
||||
UserID => 1,
|
||||
) || [];
|
||||
|
||||
WORKORDERID:
|
||||
for my $WorkOrderID ( @{$ActualWorkOrderIDs} ) {
|
||||
|
||||
# get workorder data
|
||||
my $WorkOrder = $WorkOrderObject->WorkOrderGet(
|
||||
WorkOrderID => $WorkOrderID,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
my $LastNotificationSentDate = $Self->WorkOrderNotificationSent(
|
||||
WorkOrderID => $WorkOrderID,
|
||||
Type => "Actual${Type}",
|
||||
);
|
||||
|
||||
next WORKORDERID if $LastNotificationSentDate;
|
||||
|
||||
# trigger Event
|
||||
$Self->EventHandler(
|
||||
Event => "WorkOrderActual${Type}ReachedPost",
|
||||
Data => {
|
||||
WorkOrderID => $WorkOrderID,
|
||||
ChangeID => $WorkOrder->{ChangeID},
|
||||
},
|
||||
UserID => 1,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
|
||||
}
|
||||
|
||||
# check if a notification was already sent for the given change
|
||||
sub ChangeNotificationSent {
|
||||
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Needed (qw(ChangeID Type)) {
|
||||
return if !$Param{$Needed};
|
||||
}
|
||||
|
||||
# get history entries
|
||||
my $History = $Kernel::OM->Get('Kernel::System::ITSMChange::History')->ChangeHistoryGet(
|
||||
ChangeID => $Param{ChangeID},
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
# search for notifications sent earlier
|
||||
for my $HistoryEntry ( reverse @{$History} ) {
|
||||
if (
|
||||
$HistoryEntry->{HistoryType} eq 'Change' . $Param{Type} . 'Reached'
|
||||
&& $HistoryEntry->{ContentNew} =~ m{ Notification \s Sent $ }xms
|
||||
)
|
||||
{
|
||||
return $HistoryEntry->{CreateTime};
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
# check if a notification was already sent for the given workorder
|
||||
sub WorkOrderNotificationSent {
|
||||
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Needed (qw(WorkOrderID Type)) {
|
||||
return if !$Param{$Needed};
|
||||
}
|
||||
|
||||
# get history entries
|
||||
my $History = $Kernel::OM->Get('Kernel::System::ITSMChange::History')->WorkOrderHistoryGet(
|
||||
WorkOrderID => $Param{WorkOrderID},
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
# search for notifications sent earlier
|
||||
for my $HistoryEntry ( reverse @{$History} ) {
|
||||
if (
|
||||
$HistoryEntry->{HistoryType} eq 'WorkOrder' . $Param{Type} . 'Reached'
|
||||
&& $HistoryEntry->{ContentNew} =~ m{ Notification \s Sent }xms
|
||||
)
|
||||
{
|
||||
return $HistoryEntry->{CreateTime};
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub SentWithinPeriod {
|
||||
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
return if !$Param{LastNotificationSentDate};
|
||||
|
||||
# get SysConfig option
|
||||
my $Config = $Kernel::OM->Get('Kernel::Config')->Get('ITSMChange::TimeReachedNotifications');
|
||||
|
||||
# if notifications should be sent only once
|
||||
return 1 if $Config->{Frequency} eq 'once';
|
||||
|
||||
# get epoche seconds of send time
|
||||
my $SentEpoche = $Kernel::OM->Create(
|
||||
'Kernel::System::DateTime',
|
||||
ObjectParams => {
|
||||
String => $Param{LastNotificationSentDate},
|
||||
}
|
||||
)->ToEpoch();
|
||||
|
||||
# calc diff
|
||||
my $EpocheSinceSent = $Self->{SystemTime} - $SentEpoche;
|
||||
my $HoursSinceSent = int( $EpocheSinceSent / ( 60 * 60 ) );
|
||||
|
||||
if ( $HoursSinceSent >= $Config->{Hours} ) {
|
||||
return;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub PostRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# delete pid lock
|
||||
$Kernel::OM->Get('Kernel::System::PID')->PIDDelete( Name => $Self->Name() );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
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,178 @@
|
||||
# --
|
||||
# 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::Change::Delete;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::ITSMChange',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Delete changes (all or by number).');
|
||||
$Self->AddOption(
|
||||
Name => 'all',
|
||||
Description => "Delete all changes.",
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
$Self->AddArgument(
|
||||
Name => 'accept',
|
||||
Description => "Accept delete all or cancel.",
|
||||
Required => 0,
|
||||
ValueRegex => qr/(y|n)/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'change-number',
|
||||
Description => "Delete listed changes.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/\d+/smx,
|
||||
Multiple => 1,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my @ChangeNumbers = @{ $Self->GetOption('change-number') // [] };
|
||||
|
||||
if ( !$Self->GetOption('all') && !@ChangeNumbers ) {
|
||||
die "Please provide option --all or --change-number. For more details use --help\n";
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Deleting changes...</yellow>\n");
|
||||
|
||||
$Self->Print( "<green>" . ( '=' x 69 ) . "</green>\n" );
|
||||
|
||||
# get change object
|
||||
my $ChangeObject = $Kernel::OM->Get('Kernel::System::ITSMChange');
|
||||
|
||||
# get change numbers
|
||||
my @ChangeNumbers = @{ $Self->GetOption('change-number') // [] };
|
||||
|
||||
# delete all changes
|
||||
if ( $Self->GetOption('all') ) {
|
||||
|
||||
# get all change ids
|
||||
my @ChangesIDs = @{ $ChangeObject->ChangeList( UserID => 1 ) };
|
||||
|
||||
# get number of changes
|
||||
my $ChangeCount = scalar @ChangesIDs;
|
||||
|
||||
# if there are any changes to delete
|
||||
if ($ChangeCount) {
|
||||
|
||||
$Self->Print("<yellow>Are you sure that you want to delete ALL $ChangeCount changes?</yellow>\n");
|
||||
$Self->Print("<yellow>This is irrevocable. [y/n] </yellow>\n");
|
||||
my $Confirmation = $Self->GetArgument('accept');
|
||||
chomp( $Confirmation = lc <STDIN> ) if !defined $Confirmation;
|
||||
|
||||
# if the user confirms the deletion
|
||||
if ( $Confirmation eq 'y' ) {
|
||||
|
||||
# delete changes
|
||||
$Self->Print("<yellow>Deleting all changes...</yellow>\n");
|
||||
$Self->DeleteChanges( ChangesIDs => \@ChangesIDs );
|
||||
}
|
||||
else {
|
||||
$Self->Print("<yellow>Command delete was canceled!</yellow>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
}
|
||||
else {
|
||||
$Self->Print("<yellow>There are NO changes to delete.</yellow>\n");
|
||||
}
|
||||
}
|
||||
|
||||
# delete listed changes
|
||||
elsif (@ChangeNumbers) {
|
||||
|
||||
my @ChangesIDs;
|
||||
|
||||
for my $ChangeNumber (@ChangeNumbers) {
|
||||
|
||||
# checks the validity of the change id
|
||||
my $ID = $ChangeObject->ChangeLookup(
|
||||
ChangeNumber => $ChangeNumber,
|
||||
);
|
||||
|
||||
if ($ID) {
|
||||
push @ChangesIDs, $ID;
|
||||
}
|
||||
else {
|
||||
$Self->PrintError("Unable to find change $ChangeNumber.");
|
||||
}
|
||||
}
|
||||
|
||||
# delete changes (if any valid number was given)
|
||||
if (@ChangesIDs) {
|
||||
$Self->Print("<yellow>Deleting specified changes...</yellow>\n");
|
||||
$Self->DeleteChanges( ChangesIDs => \@ChangesIDs );
|
||||
}
|
||||
}
|
||||
else {
|
||||
$Self->PrintError("No change for delete.");
|
||||
}
|
||||
|
||||
$Self->Print( "<green>" . ( '=' x 69 ) . "</green>\n" );
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
sub DeleteChanges {
|
||||
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $DeletedChanges = 0;
|
||||
|
||||
# delete specified changes
|
||||
for my $ChangeID ( @{ $Param{ChangesIDs} } ) {
|
||||
my $True = $Kernel::OM->Get('Kernel::System::ITSMChange')->ChangeDelete(
|
||||
ChangeID => $ChangeID,
|
||||
UserID => 1,
|
||||
);
|
||||
if ( !$True ) {
|
||||
$Self->PrintError("Unable to delete change with id $ChangeID\n");
|
||||
}
|
||||
else {
|
||||
$DeletedChanges++;
|
||||
}
|
||||
}
|
||||
|
||||
$Self->Print("<green>Deleted $DeletedChanges change(s).</green>\n\n");
|
||||
|
||||
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
|
||||
@@ -0,0 +1,465 @@
|
||||
# --
|
||||
# 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::Configitem::Delete;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
## nofilter(TidyAll::Plugin::OTRS::Migrations::OTRS6::SysConfig)
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::GeneralCatalog',
|
||||
'Kernel::System::ITSMConfigItem',
|
||||
'Kernel::System::DateTime',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Delete config items (all, by class (and deployment state) or by number).');
|
||||
$Self->AddOption(
|
||||
Name => 'all',
|
||||
Description => "Delete all config items.",
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
$Self->AddArgument(
|
||||
Name => 'accept',
|
||||
Description => "Accept delete all or cancel.",
|
||||
Required => 0,
|
||||
ValueRegex => qr/(y|n)/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'class',
|
||||
Description => "Delete all config items of this class.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'deployment-state',
|
||||
Description => "Delete all config items with this deployment state (ONLY TOGETHER with the --class parameter).",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'configitem-number',
|
||||
Description => "Delete listed config items.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/\d+/smx,
|
||||
Multiple => 1,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'all-old-versions',
|
||||
Description => "Delete all config item versions except the newest version.",
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'all-but-keep-last-versions',
|
||||
Description => "Delete all config item versions but keep the last XX versions.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/\d+/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'all-older-than-days-versions',
|
||||
Description => "Delete all config item versions older than XX days.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/\d+/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $All = $Self->GetOption('all');
|
||||
my $Class = $Self->GetOption('class') // '';
|
||||
my @ConfigItemNumbers = @{ $Self->GetOption('configitem-number') // [] };
|
||||
my $DeploymentState = $Self->GetOption('deployment-state') // '';
|
||||
my $AllOldVersions = $Self->GetOption('all-old-versions') // '';
|
||||
my $AllButKeepLast = $Self->GetOption('all-but-keep-last-versions') // '';
|
||||
my $AllOlderThanDays = $Self->GetOption('all-older-than-days-versions') // '';
|
||||
|
||||
if (
|
||||
!$All
|
||||
&& !$Class
|
||||
&& !@ConfigItemNumbers
|
||||
&& !$DeploymentState
|
||||
&& !$AllOldVersions
|
||||
&& !$AllButKeepLast
|
||||
&& !$AllOlderThanDays
|
||||
)
|
||||
{
|
||||
die
|
||||
"Please provide option --all, --class, --configitem-number, --all-old-versions, --all-but-keep-last-versions or --all-older-than-days-versions."
|
||||
. " For more details use --help\n";
|
||||
}
|
||||
|
||||
my $AllOptionTypeCount;
|
||||
for my $Value ( $All, $AllOldVersions, $AllButKeepLast, $AllOlderThanDays ) {
|
||||
if ($Value) {
|
||||
$AllOptionTypeCount++;
|
||||
}
|
||||
}
|
||||
if ( $AllOptionTypeCount > 1 ) {
|
||||
die
|
||||
"The options --all, --all-old-versions, --all-but-keep-last-versions and --all-older-than-days-versions can not be mixed. \nFor more details use --help\n";
|
||||
}
|
||||
if ( $AllOptionTypeCount && ( $Class || @ConfigItemNumbers || $DeploymentState ) ) {
|
||||
die
|
||||
"The options --all, --all-old-versions, --all-but-keep-last-versions and --all-older-than-days-versions can not used together with any other option. \nFor more details use --help\n";
|
||||
}
|
||||
|
||||
if ( $DeploymentState && !$Class ) {
|
||||
die
|
||||
"Deleting all config items with this deployment state is posible ONLY TOGETHER with the --class parameter. \nFor more details use --help\n";
|
||||
}
|
||||
|
||||
if ( @ConfigItemNumbers && ( $Class || $DeploymentState ) ) {
|
||||
die
|
||||
"The option --configitem-number can not be used together with the --class or the --deployment-state parameter. \nFor more details use --help\n";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Deleting config items...</yellow>\n\n");
|
||||
|
||||
my $All = $Self->GetOption('all');
|
||||
my $Class = $Self->GetOption('class') // '';
|
||||
my @ConfigItemNumbers = @{ $Self->GetOption('configitem-number') // [] };
|
||||
my $DeploymentState = $Self->GetOption('deployment-state') // '';
|
||||
my $AllOldVersions = $Self->GetOption('all-old-versions') // '';
|
||||
my $AllButKeepLast = $Self->GetOption('all-but-keep-last-versions') // '';
|
||||
my $AllOlderThanDays = $Self->GetOption('all-older-than-days-versions') // '';
|
||||
|
||||
# delete all config items
|
||||
if ($All) {
|
||||
|
||||
# get all config items ids
|
||||
my @ConfigItemIDs = @{ $Kernel::OM->Get('Kernel::System::ITSMConfigItem')->ConfigItemSearch() };
|
||||
|
||||
# get number of config items
|
||||
my $CICount = scalar @ConfigItemIDs;
|
||||
|
||||
# if there are any CI to delete
|
||||
if ($CICount) {
|
||||
|
||||
$Self->Print("<yellow>Are you sure that you want to delete ALL $CICount config items?</yellow>\n");
|
||||
$Self->Print("<yellow>This is irrevocable. [y/n] </yellow>\n");
|
||||
my $Confirmation = $Self->GetArgument('accept');
|
||||
chomp( $Confirmation = lc <STDIN> ) if !defined $Confirmation;
|
||||
|
||||
# if the user confirms the deletion
|
||||
if ( $Confirmation eq 'y' ) {
|
||||
|
||||
# delete config items
|
||||
$Self->Print("<green>Deleting all config items...</green>\n");
|
||||
$Self->DeleteConfigItems( ConfigItemIDs => \@ConfigItemIDs );
|
||||
}
|
||||
else {
|
||||
$Self->Print("<yellow>Command delete was canceled</yellow>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
}
|
||||
else {
|
||||
$Self->Print("<yellow>There are NO config items to delete.</yellow>\n");
|
||||
}
|
||||
}
|
||||
|
||||
# delete listed config items
|
||||
elsif ( IsArrayRefWithData( \@ConfigItemNumbers ) ) {
|
||||
|
||||
my @ConfigItemIDs;
|
||||
|
||||
for my $ConfigItemNumber (@ConfigItemNumbers) {
|
||||
|
||||
# checks the validity of the config item id
|
||||
my $ID = $Kernel::OM->Get('Kernel::System::ITSMConfigItem')->ConfigItemLookup(
|
||||
ConfigItemNumber => $ConfigItemNumber,
|
||||
);
|
||||
|
||||
if ($ID) {
|
||||
push @ConfigItemIDs, $ID;
|
||||
}
|
||||
else {
|
||||
$Self->Print("<yellow>Unable to find config item $ConfigItemNumber.</yellow>\n");
|
||||
}
|
||||
}
|
||||
|
||||
# delete config items (if any valid number was given)
|
||||
if (@ConfigItemIDs) {
|
||||
$Self->Print("<yellow>Deleting specified config items...</yellow>\n");
|
||||
$Self->DeleteConfigItems( ConfigItemIDs => \@ConfigItemIDs );
|
||||
}
|
||||
}
|
||||
|
||||
# delete config items that belong to the class
|
||||
elsif ($Class) {
|
||||
|
||||
my @ConfigItemIDs;
|
||||
|
||||
# get class list
|
||||
my $ClassList = $Kernel::OM->Get('Kernel::System::GeneralCatalog')->ItemList(
|
||||
Class => 'ITSM::ConfigItem::Class',
|
||||
Valid => 0,
|
||||
);
|
||||
|
||||
# invert the hash to have the classes names as keys
|
||||
my %ClassName2ID = reverse %{$ClassList};
|
||||
|
||||
if ( $ClassName2ID{$Class} ) {
|
||||
my $ID = $ClassName2ID{$Class};
|
||||
|
||||
# define the search param for the class search
|
||||
my %SearchParam = (
|
||||
ClassIDs => [$ID],
|
||||
);
|
||||
|
||||
# also a deployment state is given
|
||||
if ($DeploymentState) {
|
||||
|
||||
# get deployment state list
|
||||
my $DeploymentStateList = $Kernel::OM->Get('Kernel::System::GeneralCatalog')->ItemList(
|
||||
Class => 'ITSM::ConfigItem::DeploymentState',
|
||||
);
|
||||
|
||||
# invert the hash to have the deployment state names as keys
|
||||
my %DeploymentState2ID = reverse %{$DeploymentStateList};
|
||||
|
||||
# if the deployment state is valid
|
||||
if ( $DeploymentState2ID{$DeploymentState} ) {
|
||||
|
||||
# get the deployment state id
|
||||
my $ID = $DeploymentState2ID{$DeploymentState};
|
||||
|
||||
# add search parameter
|
||||
$SearchParam{DeplStateIDs} = [$ID];
|
||||
}
|
||||
else {
|
||||
$Self->PrintError("Unable to find deployment state $DeploymentState.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
}
|
||||
|
||||
# get ids of this class (and maybe deployment state) config items
|
||||
@ConfigItemIDs = @{
|
||||
$Kernel::OM->Get('Kernel::System::ITSMConfigItem')->ConfigItemSearch(%SearchParam)
|
||||
};
|
||||
}
|
||||
else {
|
||||
$Self->PrintError("Unable to find class name $Class.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
# delete config items (if any valid number was given)
|
||||
if (@ConfigItemIDs) {
|
||||
$Self->Print("<yellow>Deleting config items that belong to the class $Class...</yellow>\n");
|
||||
$Self->DeleteConfigItems( ConfigItemIDs => \@ConfigItemIDs );
|
||||
}
|
||||
else {
|
||||
$Self->Print("<yellow>There are no config items that belong to the class $Class...</yellow>\n");
|
||||
}
|
||||
}
|
||||
|
||||
# delete versions older than xx days from all config items
|
||||
elsif ($AllOlderThanDays) {
|
||||
|
||||
my $OlderDateDTObject = $Kernel::OM->Create('Kernel::System::DateTime');
|
||||
$OlderDateDTObject->Subtract(
|
||||
Days => $AllOlderThanDays,
|
||||
);
|
||||
|
||||
my $VersionsOlderDate = $Kernel::OM->Get('Kernel::System::ITSMConfigItem')->VersionListAll(
|
||||
OlderDate => $OlderDateDTObject->ToString(),
|
||||
);
|
||||
|
||||
# We need to get all versions to make sure that at least one version remains
|
||||
# -> if one version of a configitem is younger than the amount of days,
|
||||
# we can delete all Versions received by the "OlderDate" query
|
||||
# -> if no version is younger than the amount of days
|
||||
# we have to keep one version of the "OlderDate" query result
|
||||
my $VersionsAll = $Kernel::OM->Get('Kernel::System::ITSMConfigItem')->VersionListAll();
|
||||
|
||||
my @VersionsToDelete;
|
||||
|
||||
CONFIGITEMID:
|
||||
for my $ConfigItemID ( sort keys %{$VersionsOlderDate} ) {
|
||||
|
||||
# number of found older versions of this CI
|
||||
my $NumberOfOlderVersions = scalar keys %{ $VersionsOlderDate->{$ConfigItemID} };
|
||||
|
||||
# number of all versions of this CI
|
||||
my $NumberOfAllVersions = scalar keys %{ $VersionsAll->{$ConfigItemID} };
|
||||
|
||||
# next if there are no older versions
|
||||
next CONFIGITEMID if !$NumberOfOlderVersions;
|
||||
|
||||
# next if there is only one or zero of all versions
|
||||
next CONFIGITEMID if $NumberOfAllVersions <= 1;
|
||||
|
||||
# if the amount of Versions we have to delete
|
||||
# is exactly the same as the amount of AllVersions
|
||||
# we have to keep the last one
|
||||
# in order to keep the system working
|
||||
#
|
||||
# -> so let's start counting at "1" instead of "0"
|
||||
# in order to stop deleting before we reach the newest version
|
||||
my $Count = 0;
|
||||
if ( $NumberOfOlderVersions == $NumberOfAllVersions ) {
|
||||
$Count = 1;
|
||||
}
|
||||
|
||||
# make sure that the versions are numerically sorted
|
||||
for my $Version ( sort { $a <=> $b } keys %{ $VersionsOlderDate->{$ConfigItemID} } ) {
|
||||
|
||||
if ( $Count < $NumberOfOlderVersions ) {
|
||||
push @VersionsToDelete, $Version;
|
||||
}
|
||||
$Count++;
|
||||
}
|
||||
}
|
||||
|
||||
$Self->DeleteConfigItemVersions(
|
||||
VersionIDs => \@VersionsToDelete,
|
||||
UserID => 1,
|
||||
);
|
||||
}
|
||||
|
||||
# delete all config item versions except the newest version
|
||||
elsif ($AllOldVersions) {
|
||||
|
||||
my $VersionsAll = $Kernel::OM->Get('Kernel::System::ITSMConfigItem')->VersionListAll();
|
||||
|
||||
my @VersionsToDelete;
|
||||
if ( IsHashRefWithData($VersionsAll) ) {
|
||||
|
||||
CONFIGITEMID:
|
||||
for my $ConfigItemID ( sort keys %{$VersionsAll} ) {
|
||||
|
||||
next CONFIGITEMID if !IsHashRefWithData( $VersionsAll->{$ConfigItemID} );
|
||||
|
||||
# make sure that the versions are numerically sorted
|
||||
my @ReducedVersions = sort { $a <=> $b } keys %{ $VersionsAll->{$ConfigItemID} };
|
||||
|
||||
# remove the last (newest) version
|
||||
pop @ReducedVersions;
|
||||
|
||||
push @VersionsToDelete, @ReducedVersions;
|
||||
}
|
||||
}
|
||||
|
||||
$Self->DeleteConfigItemVersions(
|
||||
VersionIDs => \@VersionsToDelete,
|
||||
UserID => 1,
|
||||
);
|
||||
}
|
||||
|
||||
# delete all config item versions but keep the last XX versions
|
||||
elsif ($AllButKeepLast) {
|
||||
|
||||
my $VersionsAll = $Kernel::OM->Get('Kernel::System::ITSMConfigItem')->VersionListAll();
|
||||
|
||||
my @VersionsToDelete;
|
||||
|
||||
if ( IsHashRefWithData($VersionsAll) ) {
|
||||
|
||||
CONFIGITEMID:
|
||||
for my $ConfigItemID ( sort keys %{$VersionsAll} ) {
|
||||
|
||||
next CONFIGITEMID if !IsHashRefWithData( $VersionsAll->{$ConfigItemID} );
|
||||
|
||||
# make sure that the versions are numerically reverse sorted
|
||||
my @ReducedVersions = reverse sort { $a <=> $b } keys %{ $VersionsAll->{$ConfigItemID} };
|
||||
|
||||
my $Count = 0;
|
||||
@ReducedVersions = grep { $Count++; $Count > $AllButKeepLast } @ReducedVersions;
|
||||
push @VersionsToDelete, @ReducedVersions;
|
||||
}
|
||||
}
|
||||
|
||||
$Self->DeleteConfigItemVersions(
|
||||
VersionIDs => \@VersionsToDelete,
|
||||
UserID => 1,
|
||||
);
|
||||
}
|
||||
else {
|
||||
$Self->PrintError("No config item for delete.");
|
||||
}
|
||||
|
||||
# show successfull output
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
sub DeleteConfigItems {
|
||||
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $DeletedCI;
|
||||
|
||||
# delete specified config items
|
||||
for my $ConfigItemID ( @{ $Param{ConfigItemIDs} } ) {
|
||||
my $True = $Kernel::OM->Get('Kernel::System::ITSMConfigItem')->ConfigItemDelete(
|
||||
ConfigItemID => $ConfigItemID,
|
||||
UserID => 1,
|
||||
);
|
||||
if ( !$True ) {
|
||||
$Self->PrintError("Unable to delete config item with id $ConfigItemID.");
|
||||
}
|
||||
else {
|
||||
$DeletedCI++;
|
||||
}
|
||||
}
|
||||
|
||||
$Self->Print("<green>Deleted $DeletedCI config item(s).</green>\n\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub DeleteConfigItemVersions {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
return if !IsArrayRefWithData( $Param{VersionIDs} );
|
||||
|
||||
$Self->Print("<green>Deleting config item versions.</green>\n\n");
|
||||
|
||||
$Kernel::OM->Get('Kernel::System::ITSMConfigItem')->VersionDelete(
|
||||
VersionIDs => $Param{VersionIDs},
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
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
|
||||
@@ -0,0 +1,235 @@
|
||||
# --
|
||||
# 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::Configitem::ListDuplicates;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
## nofilter(TidyAll::Plugin::OTRS::Migrations::OTRS6::SysConfig)
|
||||
|
||||
use Kernel::System::VariableCheck qw(IsArrayRefWithData);
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::GeneralCatalog',
|
||||
'Kernel::System::ITSMConfigItem',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('List ConfigItems which have a non-unique name.');
|
||||
$Self->AddOption(
|
||||
Name => 'class',
|
||||
Description => "Check only config items of this class.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'scope',
|
||||
Description => "Define the scope for the uniqueness check (global|class)",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/(global|class)/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'all-states',
|
||||
Description => "Also check config items in non-productive states.",
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# get class argument
|
||||
my $Class = $Self->GetOption('class') // '';
|
||||
|
||||
if ($Class) {
|
||||
|
||||
# get class list
|
||||
my $ClassList = $Kernel::OM->Get('Kernel::System::GeneralCatalog')->ItemList(
|
||||
Class => 'ITSM::ConfigItem::Class',
|
||||
);
|
||||
|
||||
# invert the hash to have the classes' names as keys
|
||||
my %ClassName2ID = reverse %{$ClassList};
|
||||
|
||||
# check, whether this class exists
|
||||
if ( $ClassName2ID{$Class} ) {
|
||||
my $ID = $ClassName2ID{$Class};
|
||||
|
||||
# get ids of this class' config items
|
||||
$Self->{SearchCriteria}->{ClassIDs} = [$ID];
|
||||
}
|
||||
else {
|
||||
die "Class $Class does not exist...\n";
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Listing duplicates of config items...</yellow>\n\n");
|
||||
|
||||
if ( !$Self->GetOption('all-states') ) {
|
||||
|
||||
my $StateList = $Kernel::OM->Get('Kernel::System::GeneralCatalog')->ItemList(
|
||||
Class => 'ITSM::ConfigItem::DeploymentState',
|
||||
Preferences => {
|
||||
Functionality => [ 'preproductive', 'productive' ],
|
||||
},
|
||||
);
|
||||
|
||||
my $DeploymentStateIDs = [ keys %{$StateList} ];
|
||||
|
||||
$Self->{SearchCriteria}->{DeplStateIDs} = [ keys %{$StateList} ];
|
||||
|
||||
}
|
||||
|
||||
# get ITSMConfigitem object
|
||||
my $ITSMConfigitemObject = $Kernel::OM->Get('Kernel::System::ITSMConfigItem');
|
||||
|
||||
# get all config items ids
|
||||
my @ConfigItemIDs = @{ $ITSMConfigitemObject->ConfigItemSearch( %{ $Self->{SearchCriteria} } ) };
|
||||
|
||||
# get number of config items
|
||||
my $CICount = scalar @ConfigItemIDs;
|
||||
|
||||
# get class argument
|
||||
my $Class = $Self->GetOption('class') // '';
|
||||
|
||||
# if there are any CI to check
|
||||
if ($CICount) {
|
||||
|
||||
# if the scope was explicitely defined, set it, otherwise this script will fall back to the
|
||||
# value set in SysConfig
|
||||
my $Scope = $Self->GetOption('scope');
|
||||
if ($Scope) {
|
||||
$Kernel::OM->Get('Kernel::Config')->Set(
|
||||
Key => 'UniqueCIName::UniquenessCheckScope',
|
||||
Value => $Scope,
|
||||
);
|
||||
}
|
||||
|
||||
if ($Class) {
|
||||
$Self->Print("<yellow>Checking config items of class $Class...</yellow>\n");
|
||||
}
|
||||
else {
|
||||
$Self->Print("<yellow>Checking all config items...\n</yellow>\n");
|
||||
}
|
||||
|
||||
$Self->Print( "<green>" . ( '=' x 69 ) . "</green>\n" );
|
||||
|
||||
my $DuplicatesFound = 0;
|
||||
|
||||
# check config items
|
||||
CONFIGITEMID:
|
||||
for my $ConfigItemID (@ConfigItemIDs) {
|
||||
|
||||
# get the attributes of this config item
|
||||
my $ConfigItem = $ITSMConfigitemObject->ConfigItemGet(
|
||||
ConfigItemID => $ConfigItemID,
|
||||
);
|
||||
|
||||
next CONFIGITEMID if !$ConfigItem->{LastVersionID};
|
||||
|
||||
# get the latest version of this config item
|
||||
my $Version = $ITSMConfigitemObject->VersionGet(
|
||||
VersionID => $ConfigItem->{LastVersionID},
|
||||
XMLDataGet => 1,
|
||||
);
|
||||
|
||||
next CONFIGITEMID if !$Version;
|
||||
|
||||
if ( !$Version->{Name} ) {
|
||||
$Self->Print("<red>Skipping ConfigItem $ConfigItemID as it doesn't have a name.\n</red>\n");
|
||||
next CONFIGITEMID;
|
||||
}
|
||||
|
||||
my $Duplicates = $ITSMConfigitemObject->UniqueNameCheck(
|
||||
ConfigItemID => $ConfigItemID,
|
||||
ClassID => $ConfigItem->{ClassID},
|
||||
Name => $Version->{Name}
|
||||
);
|
||||
|
||||
if ( IsArrayRefWithData($Duplicates) ) {
|
||||
|
||||
$DuplicatesFound = 1;
|
||||
|
||||
my @DuplicateData;
|
||||
|
||||
for my $DuplicateID ( @{$Duplicates} ) {
|
||||
|
||||
# get the # of the duplicate
|
||||
my $DuplicateConfigItem = $ITSMConfigitemObject->ConfigItemGet(
|
||||
ConfigItemID => $DuplicateID,
|
||||
);
|
||||
|
||||
my $DuplicateVersion = $ITSMConfigitemObject->VersionGet(
|
||||
VersionID => $DuplicateConfigItem->{LastVersionID},
|
||||
);
|
||||
|
||||
push @DuplicateData, $DuplicateVersion;
|
||||
}
|
||||
|
||||
$Self->Print(
|
||||
"<yellow>ConfigItem $Version->{Number} (Name: $Version->{Name}, ConfigItemID: "
|
||||
. "$Version->{ConfigItemID}) has the following duplicates:</yellow>\n"
|
||||
);
|
||||
|
||||
# list all the details of the duplicates
|
||||
for my $DuplicateVersion (@DuplicateData) {
|
||||
print "\n";
|
||||
$Self->Print(
|
||||
"<green>\t * $DuplicateVersion->{Number} (ConfigItemID: "
|
||||
. "$DuplicateVersion->{ConfigItemID})</green>\n"
|
||||
);
|
||||
}
|
||||
|
||||
$Self->Print( "<green>" . ( '-' x 69 ) . "</green>\n" );
|
||||
}
|
||||
}
|
||||
|
||||
if ($DuplicatesFound) {
|
||||
$Self->Print("<green>Finished checking for duplicate names.\n</green>\n");
|
||||
}
|
||||
else {
|
||||
$Self->Print("<yellow>No duplicate names found.\n</yellow>\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
$Self->Print("<yellow>There are NO config items to check.\n</yellow>\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,120 @@
|
||||
# --
|
||||
# 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::ImportExport::Export;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Main',
|
||||
'Kernel::System::ImportExport',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('The tool for exporting config items');
|
||||
$Self->AddOption(
|
||||
Name => 'template-number',
|
||||
Description => "Specify a template number to be exported.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/\d+/smx,
|
||||
);
|
||||
$Self->AddArgument(
|
||||
Name => 'destination',
|
||||
Description => "Specify the path to a file where config item data should be exported.",
|
||||
Required => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $TemplateID = $Self->GetOption('template-number');
|
||||
|
||||
# get template data
|
||||
my $TemplateData = $Kernel::OM->Get('Kernel::System::ImportExport')->TemplateGet(
|
||||
TemplateID => $TemplateID,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
if ( !$TemplateData->{TemplateID} ) {
|
||||
$Self->PrintError("Template $TemplateID not found!.\n");
|
||||
$Self->PrintError("Export aborted..\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<yellow>Exporting config items...</yellow>\n");
|
||||
$Self->Print( "<yellow>" . ( '=' x 69 ) . "</yellow>\n" );
|
||||
|
||||
# export data
|
||||
my $Result = $Kernel::OM->Get('Kernel::System::ImportExport')->Export(
|
||||
TemplateID => $TemplateID,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
if ( !$Result ) {
|
||||
$Self->PrintError("Error occurred. Export impossible! See Syslog for details.\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print( "<green>" . ( '-' x 69 ) . "</green>\n" );
|
||||
$Self->Print("<green>Success: $Result->{Success} succeeded</green>\n");
|
||||
if ( $Result->{Failed} ) {
|
||||
$Self->PrintError("$Result->{Failed} failed.\n");
|
||||
}
|
||||
else {
|
||||
$Self->Print("<green>Error: $Result->{Failed} failed.</green>\n");
|
||||
}
|
||||
|
||||
my $DestinationFile = $Self->GetArgument('destination');
|
||||
|
||||
if ($DestinationFile) {
|
||||
|
||||
my $FileContent = join "\n", @{ $Result->{DestinationContent} };
|
||||
|
||||
# save destination content to file
|
||||
my $Success = $Kernel::OM->Get('Kernel::System::Main')->FileWrite(
|
||||
Location => $DestinationFile,
|
||||
Content => \$FileContent,
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Self->PrintError("Can't write file $DestinationFile.\nExport aborted.\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>File $DestinationFile saved.</green>\n");
|
||||
|
||||
}
|
||||
|
||||
$Self->Print("<green>Export complete.</green>\n");
|
||||
$Self->Print( "<green>" . ( '-' x 69 ) . "</green>\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,142 @@
|
||||
# --
|
||||
# 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::ImportExport::Import;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Main',
|
||||
'Kernel::System::ImportExport',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('The tool for importing config items');
|
||||
$Self->AddOption(
|
||||
Name => 'template-number',
|
||||
Description => "Specify a template number to be impoerted.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/\d+/smx,
|
||||
);
|
||||
$Self->AddArgument(
|
||||
Name => 'source',
|
||||
Description => "Specify the path to the file which containing the config item data for importing.",
|
||||
Required => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $SourcePath = $Self->GetArgument('source');
|
||||
if ( $SourcePath && !-r $SourcePath ) {
|
||||
die "File $SourcePath does not exist, can not be read.\n";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $TemplateID = $Self->GetOption('template-number');
|
||||
|
||||
# get template data
|
||||
my $TemplateData = $Kernel::OM->Get('Kernel::System::ImportExport')->TemplateGet(
|
||||
TemplateID => $TemplateID,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
if ( !$TemplateData->{TemplateID} ) {
|
||||
$Self->PrintError("Template $TemplateID not found!.\n");
|
||||
$Self->PrintError("Export aborted..\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<yellow>Importing config items...</yellow>\n");
|
||||
$Self->Print( "<yellow>" . ( '=' x 69 ) . "</yellow>\n" );
|
||||
|
||||
my $SourceContent;
|
||||
my $SourceFile = $Self->GetArgument('source');
|
||||
|
||||
if ($SourceFile) {
|
||||
|
||||
$Self->Print("<yellow>Read File $SourceFile.</yellow>\n");
|
||||
|
||||
# read source file
|
||||
$SourceContent = $Kernel::OM->Get('Kernel::System::Main')->FileRead(
|
||||
Location => $SourceFile,
|
||||
Result => 'SCALAR',
|
||||
Mode => 'binmode',
|
||||
);
|
||||
|
||||
if ( !$SourceContent ) {
|
||||
$Self->PrintError("Can't read file $SourceFile.\nImport aborted.\n") if !$SourceContent;
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
# import data
|
||||
my $Result = $Kernel::OM->Get('Kernel::System::ImportExport')->Import(
|
||||
TemplateID => $TemplateID,
|
||||
SourceContent => $SourceContent,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
if ( !$Result ) {
|
||||
$Self->PrintError("\nError occurred. Import impossible! See the OTRS log for details.\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
# print result
|
||||
$Self->Print("\n<green>Import of $Result->{Counter} $Result->{Object} records:</green>\n");
|
||||
$Self->Print( "<green>" . ( '-' x 69 ) . "</green>\n" );
|
||||
$Self->Print("<green>Success: $Result->{Success} succeeded</green>\n");
|
||||
if ( $Result->{Failed} ) {
|
||||
$Self->PrintError("$Result->{Failed} failed.\n");
|
||||
}
|
||||
else {
|
||||
$Self->Print("<green>Error: $Result->{Failed} failed.</green>\n");
|
||||
}
|
||||
|
||||
for my $RetCode ( sort keys %{ $Result->{RetCode} } ) {
|
||||
my $Count = $Result->{RetCode}->{$RetCode} || 0;
|
||||
$Self->Print("<green>Import of $Result->{Counter} $Result->{Object} records: $Count $RetCode</green>\n");
|
||||
}
|
||||
if ( $Result->{Failed} ) {
|
||||
$Self->Print("<green>Last processed line number of import file: $Result->{Counter}</green>\n");
|
||||
}
|
||||
|
||||
$Self->Print("<green>Import complete.</green>\n");
|
||||
$Self->Print( "<green>" . ( '-' x 69 ) . "</green>\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,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
|
||||
104
Perl OTRS/Kernel/System/Console/Command/Admin/Package/Export.pm
Normal file
104
Perl OTRS/Kernel/System/Console/Command/Admin/Package/Export.pm
Normal file
@@ -0,0 +1,104 @@
|
||||
# --
|
||||
# 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::Package::Export;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Main',
|
||||
'Kernel::System::Package',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Export the contents of an OTRS package to a directory.');
|
||||
$Self->AddOption(
|
||||
Name => 'target-directory',
|
||||
Description => "Export contents of the package to the specified directory.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddArgument(
|
||||
Name => 'source-path',
|
||||
Description => "Specify the path to an OTRS package (opm) file that should be exported.",
|
||||
Required => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $SourcePath = $Self->GetArgument('source-path');
|
||||
if ( $SourcePath && !-r $SourcePath ) {
|
||||
die "File $SourcePath does not exist / can not be read.\n";
|
||||
}
|
||||
|
||||
my $TargetDirectory = $Self->GetOption('target-directory');
|
||||
if ( $TargetDirectory && !-d $TargetDirectory ) {
|
||||
die "Directory $TargetDirectory does not exist.\n";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Exporting package contents...</yellow>\n");
|
||||
|
||||
my $SourcePath = $Self->GetArgument('source-path');
|
||||
|
||||
my $FileString;
|
||||
my $ContentRef = $Kernel::OM->Get('Kernel::System::Main')->FileRead(
|
||||
Location => $SourcePath,
|
||||
Mode => 'utf8', # optional - binmode|utf8
|
||||
Result => 'SCALAR', # optional - SCALAR|ARRAY
|
||||
);
|
||||
if ( !$ContentRef || ref $ContentRef ne 'SCALAR' ) {
|
||||
$Self->PrintError("File $SourcePath is empty / could not be read.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
$FileString = ${$ContentRef};
|
||||
|
||||
my %Structure = $Kernel::OM->Get('Kernel::System::Package')->PackageParse(
|
||||
String => $FileString,
|
||||
);
|
||||
|
||||
# just export files if PackageIsDownloadable flag is enable
|
||||
if (
|
||||
defined $Structure{PackageIsDownloadable}
|
||||
&& !$Structure{PackageIsDownloadable}->{Content}
|
||||
)
|
||||
{
|
||||
$Self->PrintError("Files cannot be exported.\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
my $TargetDirectory = $Self->GetOption('target-directory');
|
||||
my $Success = $Kernel::OM->Get('Kernel::System::Package')->PackageExport(
|
||||
String => $FileString,
|
||||
Home => $TargetDirectory,
|
||||
);
|
||||
|
||||
if ($Success) {
|
||||
$Self->Print("<green>Exported files of package $SourcePath to $TargetDirectory.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,78 @@
|
||||
# --
|
||||
# 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::Package::FileSearch;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Package',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Find a file in an installed OTRS package.');
|
||||
$Self->AddArgument(
|
||||
Name => 'search-path',
|
||||
Description => "Filename or path to search for.",
|
||||
Required => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Searching in installed OTRS packages...</yellow>\n");
|
||||
|
||||
my $Hit = 0;
|
||||
my $Filepath = $Self->GetArgument('search-path');
|
||||
|
||||
PACKAGE:
|
||||
for my $Package ( $Kernel::OM->Get('Kernel::System::Package')->RepositoryList() ) {
|
||||
|
||||
# Just show if PackageIsVisible flag is enabled.
|
||||
if (
|
||||
defined $Package->{PackageIsVisible}
|
||||
&& !$Package->{PackageIsVisible}->{Content}
|
||||
)
|
||||
{
|
||||
next PACKAGE;
|
||||
}
|
||||
for my $File ( @{ $Package->{Filelist} } ) {
|
||||
if ( $File->{Location} =~ m{\Q$Filepath\E}smx ) {
|
||||
print
|
||||
"+----------------------------------------------------------------------------+\n";
|
||||
print "| File: $File->{Location}\n";
|
||||
print "| Name: $Package->{Name}->{Content}\n";
|
||||
print "| Version: $Package->{Version}->{Content}\n";
|
||||
print "| Vendor: $Package->{Vendor}->{Content}\n";
|
||||
print "| URL: $Package->{URL}->{Content}\n";
|
||||
print "| License: $Package->{License}->{Content}\n";
|
||||
print
|
||||
"+----------------------------------------------------------------------------+\n";
|
||||
$Hit++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($Hit) {
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
$Self->PrintError("File $Filepath was not found in an installed OTRS package.\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
1;
|
||||
143
Perl OTRS/Kernel/System/Console/Command/Admin/Package/Install.pm
Normal file
143
Perl OTRS/Kernel/System/Console/Command/Admin/Package/Install.pm
Normal file
@@ -0,0 +1,143 @@
|
||||
# --
|
||||
# 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::Package::Install;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand Kernel::System::Console::Command::Admin::Package::List);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::Cache',
|
||||
'Kernel::System::Package',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Install an OTRS package.');
|
||||
$Self->AddOption(
|
||||
Name => 'force',
|
||||
Description => 'Force package installation even if validation fails.',
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
$Self->AddArgument(
|
||||
Name => 'location',
|
||||
Description =>
|
||||
"Specify a file path, a remote repository (http://ftp.otrs.org/pub/otrs/packages/:Package-1.0.0.opm) or just any online repository (online:Package).",
|
||||
Required => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Installing package...</yellow>\n");
|
||||
|
||||
my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');
|
||||
|
||||
# Enable in-memory cache to improve SysConfig performance, which is normally disabled for commands.
|
||||
$CacheObject->Configure(
|
||||
CacheInMemory => 1,
|
||||
);
|
||||
|
||||
my $FileString = $Self->_PackageContentGet( Location => $Self->GetArgument('location') );
|
||||
return $Self->ExitCodeError() if !$FileString;
|
||||
|
||||
my $PackageObject = $Kernel::OM->Get('Kernel::System::Package');
|
||||
|
||||
# Parse package.
|
||||
my %Structure = $PackageObject->PackageParse(
|
||||
String => $FileString,
|
||||
);
|
||||
|
||||
my $Verified = $PackageObject->PackageVerify(
|
||||
Package => $FileString,
|
||||
Structure => \%Structure,
|
||||
) || 'verified';
|
||||
my %VerifyInfo = $PackageObject->PackageVerifyInfo();
|
||||
|
||||
# Check if installation of packages, which are not verified by us, is possible.
|
||||
my $PackageAllowNotVerifiedPackages = $Kernel::OM->Get('Kernel::Config')->Get('Package::AllowNotVerifiedPackages');
|
||||
|
||||
if ( $Verified ne 'verified' ) {
|
||||
|
||||
if ( !$PackageAllowNotVerifiedPackages ) {
|
||||
|
||||
$Self->PrintError(
|
||||
"$Structure{Name}->{Content}-$Structure{Version}->{Content} is not verified by the OTRS Group!\n\nThe installation of packages which are not verified by the OTRS Group is not possible by default."
|
||||
);
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
else {
|
||||
|
||||
$Self->Print(
|
||||
"<yellow>Package $Structure{Name}->{Content}-$Structure{Version}->{Content} not verified by the OTRS Group! It is recommended not to use this package.</yellow>\n"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
# intro screen
|
||||
if ( $Structure{IntroInstall} ) {
|
||||
my %Data = $Self->_PackageMetadataGet(
|
||||
Tag => $Structure{IntroInstall},
|
||||
AttributeFilterKey => 'Type',
|
||||
AttributeFilterValue => 'pre',
|
||||
);
|
||||
if ( $Data{Description} ) {
|
||||
print "+----------------------------------------------------------------------------+\n";
|
||||
print "| $Structure{Name}->{Content}-$Structure{Version}->{Content}\n";
|
||||
print "$Data{Title}";
|
||||
print "$Data{Description}";
|
||||
print "+----------------------------------------------------------------------------+\n";
|
||||
}
|
||||
}
|
||||
|
||||
# install
|
||||
my $Success = $PackageObject->PackageInstall(
|
||||
String => $FileString,
|
||||
Force => $Self->GetOption('force'),
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Self->PrintError("Package installation failed.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
# intro screen
|
||||
if ( $Structure{IntroInstall} ) {
|
||||
my %Data = $Self->_PackageMetadataGet(
|
||||
Tag => $Structure{IntroInstall},
|
||||
AttributeFilterKey => 'Type',
|
||||
AttributeFilterValue => 'post',
|
||||
);
|
||||
if ( $Data{Description} ) {
|
||||
print "+----------------------------------------------------------------------------+\n";
|
||||
print "| $Structure{Name}->{Content}-$Structure{Version}->{Content}\n";
|
||||
print "$Data{Title}";
|
||||
print "$Data{Description}";
|
||||
print "+----------------------------------------------------------------------------+\n";
|
||||
}
|
||||
}
|
||||
|
||||
# Disable in memory cache.
|
||||
$CacheObject->Configure(
|
||||
CacheInMemory => 0,
|
||||
);
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
364
Perl OTRS/Kernel/System/Console/Command/Admin/Package/List.pm
Normal file
364
Perl OTRS/Kernel/System/Console/Command/Admin/Package/List.pm
Normal file
@@ -0,0 +1,364 @@
|
||||
# --
|
||||
# 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::Package::List;
|
||||
|
||||
use strict;
|
||||
use utf8;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::Cache',
|
||||
'Kernel::System::Main',
|
||||
'Kernel::System::Package',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('List all installed OTRS packages.');
|
||||
|
||||
$Self->AddOption(
|
||||
Name => 'package-name',
|
||||
Description => '(Part of) package name to filter for. Omit to show all installed packages.',
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/,
|
||||
);
|
||||
|
||||
$Self->AddOption(
|
||||
Name => 'show-deployment-info',
|
||||
Description => 'Show package and files status (package deployment info).',
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
|
||||
$Self->AddOption(
|
||||
Name => 'show-verification-info',
|
||||
Description => 'Show package OTRS Verify™ status.',
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
|
||||
$Self->AddOption(
|
||||
Name => 'delete-verification-cache',
|
||||
Description => 'Delete OTRS Verify™ cache, so verification info is fetch again from OTRS group servers.',
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $ShowVerificationInfoOption = $Self->GetOption('show-verification-info');
|
||||
my $DeleteVerificationCacheOption = $Self->GetOption('delete-verification-cache');
|
||||
|
||||
if ( $DeleteVerificationCacheOption && !$ShowVerificationInfoOption ) {
|
||||
die "--delete-verification-cache requires --show-verification-info";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Listing all installed packages...</yellow>\n");
|
||||
|
||||
my @Packages = $Kernel::OM->Get('Kernel::System::Package')->RepositoryList();
|
||||
|
||||
if ( !@Packages ) {
|
||||
$Self->Print("<green>There are no packages installed.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
my $PackageNameOption = $Self->GetOption('package-name');
|
||||
my $ShowDeploymentInfoOption = $Self->GetOption('show-deployment-info');
|
||||
my $ShowVerificationInfoOption = $Self->GetOption('show-verification-info');
|
||||
my $DeleteVerificationCacheOption = $Self->GetOption('delete-verification-cache');
|
||||
|
||||
my $CloudServicesDisabled = $Kernel::OM->Get('Kernel::Config')->Get('CloudServices::Disabled') || 0;
|
||||
|
||||
# Do not show verification status is cloud services are disabled.
|
||||
if ( $CloudServicesDisabled && $ShowVerificationInfoOption ) {
|
||||
$ShowVerificationInfoOption = 0;
|
||||
$Self->Print("<red>Cloud Services are disabled OTRS Verify information can not be retrieved</red>\n");
|
||||
}
|
||||
|
||||
# Get package object
|
||||
my $PackageObject = $Kernel::OM->Get('Kernel::System::Package');
|
||||
|
||||
my %VerificationInfo;
|
||||
|
||||
PACKAGE:
|
||||
for my $Package (@Packages) {
|
||||
|
||||
# Just show if PackageIsVisible flag is enabled.
|
||||
if (
|
||||
defined $Package->{PackageIsVisible}
|
||||
&& !$Package->{PackageIsVisible}->{Content}
|
||||
)
|
||||
{
|
||||
next PACKAGE;
|
||||
}
|
||||
|
||||
if ( defined $PackageNameOption && length $PackageNameOption ) {
|
||||
my $PackageString = $Package->{Name}->{Content} . '-' . $Package->{Version}->{Content};
|
||||
next PACKAGE if $PackageString !~ m{$PackageNameOption}i;
|
||||
}
|
||||
|
||||
my %Data = $Self->_PackageMetadataGet(
|
||||
Tag => $Package->{Description},
|
||||
StripHTML => 0,
|
||||
);
|
||||
$Self->Print("+----------------------------------------------------------------------------+\n");
|
||||
$Self->Print("| <yellow>Name:</yellow> $Package->{Name}->{Content}\n");
|
||||
$Self->Print("| <yellow>Version:</yellow> $Package->{Version}->{Content}\n");
|
||||
$Self->Print("| <yellow>Vendor:</yellow> $Package->{Vendor}->{Content}\n");
|
||||
$Self->Print("| <yellow>URL:</yellow> $Package->{URL}->{Content}\n");
|
||||
$Self->Print("| <yellow>License:</yellow> $Package->{License}->{Content}\n");
|
||||
$Self->Print("| <yellow>Description:</yellow> $Data{Description}\n");
|
||||
|
||||
if ($ShowDeploymentInfoOption) {
|
||||
my $PackageDeploymentOK = $PackageObject->DeployCheck(
|
||||
Name => $Package->{Name}->{Content},
|
||||
Version => $Package->{Version}->{Content},
|
||||
Log => 0,
|
||||
);
|
||||
|
||||
my %PackageDeploymentInfo = $PackageObject->DeployCheckInfo();
|
||||
if ( defined $PackageDeploymentInfo{File} && %{ $PackageDeploymentInfo{File} } ) {
|
||||
$Self->Print(
|
||||
'| <red>Deployment:</red> ' . ( $PackageDeploymentOK ? 'OK' : 'Not OK' ) . "\n"
|
||||
);
|
||||
for my $File ( sort keys %{ $PackageDeploymentInfo{File} } ) {
|
||||
my $FileMessage = $PackageDeploymentInfo{File}->{$File};
|
||||
$Self->Print("| <red>File Status:</red> $File => $FileMessage\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
$Self->Print(
|
||||
'| <yellow>Pck. Status:</yellow> ' . ( $PackageDeploymentOK ? 'OK' : 'Not OK' ) . "\n"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($ShowVerificationInfoOption) {
|
||||
|
||||
if ( !%VerificationInfo ) {
|
||||
|
||||
# Clear the package verification cache to get fresh results.
|
||||
if ($DeleteVerificationCacheOption) {
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
|
||||
Type => 'PackageVerification',
|
||||
);
|
||||
}
|
||||
|
||||
# Get verification info for all packages (this will create the cache again).
|
||||
%VerificationInfo = $PackageObject->PackageVerifyAll();
|
||||
}
|
||||
|
||||
if (
|
||||
!defined $VerificationInfo{ $Package->{Name}->{Content} }
|
||||
|| $VerificationInfo{ $Package->{Name}->{Content} } ne 'verified'
|
||||
)
|
||||
{
|
||||
$Self->Print("| <red>OTRS Verify:</red> Not Verified\n");
|
||||
}
|
||||
else {
|
||||
$Self->Print("| <yellow>OTRS Verify:</yellow> Verified\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
$Self->Print("+----------------------------------------------------------------------------+\n");
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
# =item _PackageMetadataGet()
|
||||
#
|
||||
# locates information in tags that are language specific.
|
||||
# First, 'en' is looked for, if that is not present, the first found language will be used.
|
||||
#
|
||||
# my %Data = $CommandObject->_PackageMetadataGet(
|
||||
# Tag => $Package->{Description},
|
||||
# StripHTML => 1, # optional, perform HTML->ASCII conversion (default 1)
|
||||
# );
|
||||
#
|
||||
# my %Data = $Self->_PackageMetadataGet(
|
||||
# Tag => $Structure{IntroInstallPost},
|
||||
# AttributeFilterKey => 'Type',
|
||||
# AttributeFilterValue => 'pre',
|
||||
# );
|
||||
#
|
||||
# Returns the content and the title of the tag in a hash:
|
||||
#
|
||||
# my %Result = (
|
||||
# Description => '...', # tag content
|
||||
# Title => '...', # tag title
|
||||
# );
|
||||
#
|
||||
# =cut
|
||||
|
||||
sub _PackageMetadataGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
return if !ref $Param{Tag};
|
||||
|
||||
my $AttributeFilterKey = $Param{AttributeFilterKey};
|
||||
my $AttributeFilterValue = $Param{AttributeFilterValue};
|
||||
|
||||
my $Title = '';
|
||||
my $Description = '';
|
||||
|
||||
TAG:
|
||||
for my $Tag ( @{ $Param{Tag} } ) {
|
||||
if ($AttributeFilterKey) {
|
||||
if ( lc $Tag->{$AttributeFilterKey} ne lc $AttributeFilterValue ) {
|
||||
next TAG;
|
||||
}
|
||||
}
|
||||
if ( !$Description && $Tag->{Lang} eq 'en' ) {
|
||||
$Description = $Tag->{Content} || '';
|
||||
$Title = $Tag->{Title} || '';
|
||||
}
|
||||
}
|
||||
if ( !$Description ) {
|
||||
TAG:
|
||||
for my $Tag ( @{ $Param{Tag} } ) {
|
||||
if ($AttributeFilterKey) {
|
||||
if ( lc $Tag->{$AttributeFilterKey} ne lc $AttributeFilterValue ) {
|
||||
next TAG;
|
||||
}
|
||||
}
|
||||
if ( !$Description ) {
|
||||
$Description = $Tag->{Content} || '';
|
||||
$Title = $Tag->{Title} || '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !defined $Param{StripHTML} || $Param{StripHTML} ) {
|
||||
$Title =~ s/(.{4,78})(?:\s|\z)/| $1\n/gm;
|
||||
$Description =~ s/^\s*//mg;
|
||||
$Description =~ s/\n/ /gs;
|
||||
$Description =~ s/\r/ /gs;
|
||||
$Description =~ s/\<style.+?\>.*\<\/style\>//gsi;
|
||||
$Description =~ s/\<br(\/|)\>/\n/gsi;
|
||||
$Description =~ s/\<(hr|hr.+?)\>/\n\n/gsi;
|
||||
$Description =~ s/\<(\/|)(pre|pre.+?|p|p.+?|table|table.+?|code|code.+?)\>/\n\n/gsi;
|
||||
$Description =~ s/\<(tr|tr.+?|th|th.+?)\>/\n\n/gsi;
|
||||
$Description =~ s/\.+?<\/(td|td.+?)\>/ /gsi;
|
||||
$Description =~ s/\<.+?\>//gs;
|
||||
$Description =~ s/ / /mg;
|
||||
$Description =~ s/&/&/g;
|
||||
$Description =~ s/</</g;
|
||||
$Description =~ s/>/>/g;
|
||||
$Description =~ s/"/"/g;
|
||||
$Description =~ s/ / /g;
|
||||
$Description =~ s/^\s*\n\s*\n/\n/mg;
|
||||
$Description =~ s/(.{4,78})(?:\s|\z)/| $1\n/gm;
|
||||
}
|
||||
return (
|
||||
Description => $Description,
|
||||
Title => $Title,
|
||||
);
|
||||
}
|
||||
|
||||
sub _PackageContentGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $FileString;
|
||||
|
||||
if ( -e $Param{Location} ) {
|
||||
my $ContentRef = $Kernel::OM->Get('Kernel::System::Main')->FileRead(
|
||||
Location => $Param{Location},
|
||||
Mode => 'utf8', # optional - binmode|utf8
|
||||
Result => 'SCALAR', # optional - SCALAR|ARRAY
|
||||
);
|
||||
if ($ContentRef) {
|
||||
$FileString = ${$ContentRef};
|
||||
}
|
||||
else {
|
||||
$Self->PrintError("Can't open: $Param{Location}: $!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
elsif ( $Param{Location} =~ /^(online|.*):(.+?)$/ ) {
|
||||
my $URL = $1;
|
||||
my $PackageName = $2;
|
||||
if ( $URL eq 'online' ) {
|
||||
my %List = %{ $Kernel::OM->Get('Kernel::Config')->Get('Package::RepositoryList') };
|
||||
%List = (
|
||||
%List,
|
||||
$Kernel::OM->Get('Kernel::System::Package')->PackageOnlineRepositories()
|
||||
);
|
||||
for ( sort keys %List ) {
|
||||
if ( $List{$_} =~ /^\[-Master-\]/ ) {
|
||||
$URL = $_;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( $PackageName !~ /^.+?.opm$/ ) {
|
||||
my @Packages = $Kernel::OM->Get('Kernel::System::Package')->PackageOnlineList(
|
||||
URL => $URL,
|
||||
Lang => $Kernel::OM->Get('Kernel::Config')->Get('DefaultLanguage'),
|
||||
);
|
||||
PACKAGE:
|
||||
for my $Package (@Packages) {
|
||||
if ( $Package->{Name} eq $PackageName ) {
|
||||
$PackageName = $Package->{File};
|
||||
last PACKAGE;
|
||||
}
|
||||
}
|
||||
}
|
||||
$FileString = $Kernel::OM->Get('Kernel::System::Package')->PackageOnlineGet(
|
||||
Source => $URL,
|
||||
File => $PackageName,
|
||||
);
|
||||
if ( !$FileString ) {
|
||||
$Self->PrintError("No such file '$Param{Location}' in $URL!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ( $Param{Location} =~ /^(.*)\-(\d{1,4}\.\d{1,4}\.\d{1,4})$/ ) {
|
||||
$FileString = $Kernel::OM->Get('Kernel::System::Package')->RepositoryGet(
|
||||
Name => $1,
|
||||
Version => $2,
|
||||
);
|
||||
}
|
||||
else {
|
||||
PACKAGE:
|
||||
for my $Package ( $Kernel::OM->Get('Kernel::System::Package')->RepositoryList() ) {
|
||||
if ( $Param{Location} eq $Package->{Name}->{Content} ) {
|
||||
$FileString = $Kernel::OM->Get('Kernel::System::Package')->RepositoryGet(
|
||||
Name => $Package->{Name}->{Content},
|
||||
Version => $Package->{Version}->{Content},
|
||||
);
|
||||
last PACKAGE;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( !$FileString ) {
|
||||
$Self->PrintError("No such file '$Param{Location}' or invalid 'package-version'!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return $FileString;
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,58 @@
|
||||
# --
|
||||
# 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::Package::ListInstalledFiles;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::Main',
|
||||
'Kernel::System::Package',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('List all installed OTRS package files.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Listing all installed package files...</yellow>\n");
|
||||
|
||||
my @Packages = $Kernel::OM->Get('Kernel::System::Package')->RepositoryList();
|
||||
|
||||
PACKAGE:
|
||||
for my $Package (@Packages) {
|
||||
|
||||
# Just show if PackageIsVisible flag is enabled.
|
||||
if (
|
||||
defined $Package->{PackageIsVisible}
|
||||
&& !$Package->{PackageIsVisible}->{Content}
|
||||
)
|
||||
{
|
||||
next PACKAGE;
|
||||
}
|
||||
|
||||
for my $File ( @{ $Package->{Filelist} } ) {
|
||||
$Self->Print(" $Package->{Name}->{Content}: $File->{Location}\n");
|
||||
}
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,114 @@
|
||||
# --
|
||||
# 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::Package::Reinstall;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand Kernel::System::Console::Command::Admin::Package::List);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Cache',
|
||||
'Kernel::System::Package',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Reinstall an OTRS package.');
|
||||
$Self->AddOption(
|
||||
Name => 'force',
|
||||
Description => 'Force package reinstallation even if validation fails.',
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
$Self->AddArgument(
|
||||
Name => 'location',
|
||||
Description =>
|
||||
"Specify a file path, a remote repository (http://ftp.otrs.org/pub/otrs/packages/:Package-1.0.0.opm) or just any online repository (online:Package).",
|
||||
Required => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Reinstalling package...</yellow>\n");
|
||||
|
||||
my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');
|
||||
|
||||
# Enable in-memory cache to improve SysConfig performance, which is normally disabled for commands.
|
||||
$CacheObject->Configure(
|
||||
CacheInMemory => 1,
|
||||
);
|
||||
|
||||
my $FileString = $Self->_PackageContentGet( Location => $Self->GetArgument('location') );
|
||||
return $Self->ExitCodeError() if !$FileString;
|
||||
|
||||
# parse package
|
||||
my %Structure = $Kernel::OM->Get('Kernel::System::Package')->PackageParse(
|
||||
String => $FileString,
|
||||
);
|
||||
|
||||
# intro screen
|
||||
if ( $Structure{IntroReinstall} ) {
|
||||
my %Data = $Self->_PackageMetadataGet(
|
||||
Tag => $Structure{IntroReinstall},
|
||||
AttributeFilterKey => 'Type',
|
||||
AttributeFilterValue => 'pre',
|
||||
);
|
||||
if ( $Data{Description} ) {
|
||||
print "+----------------------------------------------------------------------------+\n";
|
||||
print "| $Structure{Name}->{Content}-$Structure{Version}->{Content}\n";
|
||||
print "$Data{Title}";
|
||||
print "$Data{Description}";
|
||||
print "+----------------------------------------------------------------------------+\n";
|
||||
}
|
||||
}
|
||||
|
||||
# install
|
||||
my $Success = $Kernel::OM->Get('Kernel::System::Package')->PackageReinstall(
|
||||
String => $FileString,
|
||||
Force => $Self->GetOption('force'),
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Self->PrintError("Package reinstallation failed.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
# intro screen
|
||||
if ( $Structure{IntroReinstall} ) {
|
||||
my %Data = $Self->_PackageMetadataGet(
|
||||
Tag => $Structure{IntroReinstall},
|
||||
AttributeFilterKey => 'Type',
|
||||
AttributeFilterValue => 'post',
|
||||
);
|
||||
if ( $Data{Description} ) {
|
||||
print "+----------------------------------------------------------------------------+\n";
|
||||
print "| $Structure{Name}->{Content}-$Structure{Version}->{Content}\n";
|
||||
print "$Data{Title}";
|
||||
print "$Data{Description}";
|
||||
print "+----------------------------------------------------------------------------+\n";
|
||||
}
|
||||
}
|
||||
|
||||
# Disable in memory cache.
|
||||
$CacheObject->Configure(
|
||||
CacheInMemory => 0,
|
||||
);
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,104 @@
|
||||
# --
|
||||
# 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::Package::ReinstallAll;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Cache',
|
||||
'Kernel::System::Package',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Reinstall all OTRS packages that are not correctly deployed.');
|
||||
$Self->AddOption(
|
||||
Name => 'force',
|
||||
Description => 'Force package reinstallation even if validation fails.',
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
|
||||
$Self->AddOption(
|
||||
Name => 'hide-deployment-info',
|
||||
Description => 'Hide package and files status (package deployment info).',
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $HideDeploymentInfoOption = $Self->GetOption('hide-deployment-info') || 0;
|
||||
|
||||
$Self->Print("<yellow>Reinstalling all OTRS packages that are not correctly deployed...</yellow>\n");
|
||||
|
||||
my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');
|
||||
|
||||
# Enable in-memory cache to improve SysConfig performance, which is normally disabled for commands.
|
||||
$CacheObject->Configure(
|
||||
CacheInMemory => 1,
|
||||
);
|
||||
|
||||
my @ReinstalledPackages;
|
||||
|
||||
# loop all locally installed packages
|
||||
for my $Package ( $Kernel::OM->Get('Kernel::System::Package')->RepositoryList() ) {
|
||||
|
||||
# do a deploy check to see if reinstallation is needed
|
||||
my $CorrectlyDeployed = $Kernel::OM->Get('Kernel::System::Package')->DeployCheck(
|
||||
Name => $Package->{Name}->{Content},
|
||||
Version => $Package->{Version}->{Content},
|
||||
Log => $HideDeploymentInfoOption ? 0 : 1,
|
||||
);
|
||||
|
||||
if ( !$CorrectlyDeployed ) {
|
||||
|
||||
push @ReinstalledPackages, $Package->{Name}->{Content};
|
||||
|
||||
my $FileString = $Kernel::OM->Get('Kernel::System::Package')->RepositoryGet(
|
||||
Name => $Package->{Name}->{Content},
|
||||
Version => $Package->{Version}->{Content},
|
||||
);
|
||||
|
||||
my $Success = $Kernel::OM->Get('Kernel::System::Package')->PackageReinstall(
|
||||
String => $FileString,
|
||||
Force => $Self->GetOption('force'),
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Self->PrintError("Package $Package->{Name}->{Content} could not be reinstalled.\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (@ReinstalledPackages) {
|
||||
$Self->Print( "<green>" . scalar(@ReinstalledPackages) . " package(s) reinstalled.</green>\n" );
|
||||
}
|
||||
else {
|
||||
$Self->Print("<green>No packages needed reinstallation.</green>\n");
|
||||
}
|
||||
|
||||
# Disable in memory cache.
|
||||
$CacheObject->Configure(
|
||||
CacheInMemory => 0,
|
||||
);
|
||||
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,97 @@
|
||||
# --
|
||||
# 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::Package::RepositoryList;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::Package',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('List all known OTRS package repsitories.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Listing OTRS package repositories...</yellow>\n");
|
||||
|
||||
my $Count = 0;
|
||||
my %List;
|
||||
if ( $Kernel::OM->Get('Kernel::Config')->Get('Package::RepositoryList') ) {
|
||||
%List = %{ $Kernel::OM->Get('Kernel::Config')->Get('Package::RepositoryList') };
|
||||
}
|
||||
%List = ( %List, $Kernel::OM->Get('Kernel::System::Package')->PackageOnlineRepositories() );
|
||||
|
||||
if ( !%List ) {
|
||||
$Self->PrintError("No package repositories configured.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
for my $URL ( sort { $List{$a} cmp $List{$b} } keys %List ) {
|
||||
$Count++;
|
||||
print "+----------------------------------------------------------------------------+\n";
|
||||
print "| $Count) Name: $List{$URL}\n";
|
||||
print "| URL: $URL\n";
|
||||
}
|
||||
print "+----------------------------------------------------------------------------+\n";
|
||||
print "\n";
|
||||
|
||||
$Self->Print("<yellow>Listing OTRS package repository contents...</yellow>\n");
|
||||
|
||||
for my $URL ( sort { $List{$a} cmp $List{$b} } keys %List ) {
|
||||
print
|
||||
"+----------------------------------------------------------------------------+\n";
|
||||
print "| Package Overview for Repository $List{$URL}:\n";
|
||||
my @Packages = $Kernel::OM->Get('Kernel::System::Package')->PackageOnlineList(
|
||||
URL => $URL,
|
||||
Lang => $Kernel::OM->Get('Kernel::Config')->Get('DefaultLanguage'),
|
||||
);
|
||||
my $PackageCount = 0;
|
||||
PACKAGE:
|
||||
for my $Package (@Packages) {
|
||||
|
||||
# Just show if PackageIsVisible flag is enabled.
|
||||
if (
|
||||
defined $Package->{PackageIsVisible}
|
||||
&& !$Package->{PackageIsVisible}->{Content}
|
||||
)
|
||||
{
|
||||
next PACKAGE;
|
||||
}
|
||||
$PackageCount++;
|
||||
print
|
||||
"+----------------------------------------------------------------------------+\n";
|
||||
print "| $PackageCount) Name: $Package->{Name}\n";
|
||||
print "| Version: $Package->{Version}\n";
|
||||
print "| Vendor: $Package->{Vendor}\n";
|
||||
print "| URL: $Package->{URL}\n";
|
||||
print "| License: $Package->{License}\n";
|
||||
print "| Description: $Package->{Description}\n";
|
||||
print "| Install: $URL:$Package->{File}\n";
|
||||
}
|
||||
print
|
||||
"+----------------------------------------------------------------------------+\n";
|
||||
print "\n";
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,135 @@
|
||||
# --
|
||||
# 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::Package::Uninstall;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand Kernel::System::Console::Command::Admin::Package::List);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Cache',
|
||||
'Kernel::System::Package',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Uninstall an OTRS package.');
|
||||
$Self->AddOption(
|
||||
Name => 'force',
|
||||
Description => 'Force package uninstallation even if validation fails.',
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
$Self->AddArgument(
|
||||
Name => 'location',
|
||||
Description =>
|
||||
"Specify a file path, a remote repository (http://ftp.otrs.org/pub/otrs/packages/:Package-1.0.0.opm) or just any online repository (online:Package).",
|
||||
Required => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Uninstalling package...</yellow>\n");
|
||||
|
||||
my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');
|
||||
|
||||
# Enable in-memory cache to improve SysConfig performance, which is normally disabled for commands.
|
||||
$CacheObject->Configure(
|
||||
CacheInMemory => 1,
|
||||
);
|
||||
|
||||
my $FileString = $Self->_PackageContentGet( Location => $Self->GetArgument('location') );
|
||||
return $Self->ExitCodeError() if !$FileString;
|
||||
|
||||
# get package file from db
|
||||
# parse package
|
||||
my %Structure = $Kernel::OM->Get('Kernel::System::Package')->PackageParse(
|
||||
String => $FileString,
|
||||
);
|
||||
|
||||
# just un-install it if PackageIsRemovable flag is enable
|
||||
if (
|
||||
defined $Structure{PackageIsRemovable}
|
||||
&& !$Structure{PackageIsRemovable}->{Content}
|
||||
)
|
||||
{
|
||||
my $Error = "Not possible to remove this package!\n";
|
||||
|
||||
# exchange message if package should not be visible
|
||||
if (
|
||||
defined $Structure{PackageIsVisible}
|
||||
&& !$Structure{PackageIsVisible}->{Content}
|
||||
)
|
||||
{
|
||||
$Error = "No such package!\n";
|
||||
}
|
||||
$Self->PrintError($Error);
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
# intro screen
|
||||
if ( $Structure{IntroUninstall} ) {
|
||||
my %Data = $Self->_PackageMetadataGet(
|
||||
Tag => $Structure{IntroUninstall},
|
||||
AttributeFilterKey => 'Type',
|
||||
AttributeFilterValue => 'pre',
|
||||
);
|
||||
if ( $Data{Description} ) {
|
||||
print "+----------------------------------------------------------------------------+\n";
|
||||
print "| $Structure{Name}->{Content}-$Structure{Version}->{Content}\n";
|
||||
print "$Data{Title}";
|
||||
print "$Data{Description}";
|
||||
print "+----------------------------------------------------------------------------+\n";
|
||||
}
|
||||
}
|
||||
|
||||
# Uninstall
|
||||
my $Success = $Kernel::OM->Get('Kernel::System::Package')->PackageUninstall(
|
||||
String => $FileString,
|
||||
Force => $Self->GetOption('force'),
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Self->PrintError("Package uninstallation failed.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
# intro screen
|
||||
if ( $Structure{IntroUninstallPost} ) {
|
||||
my %Data = $Self->_PackageMetadataGet(
|
||||
Tag => $Structure{IntroUninstall},
|
||||
AttributeFilterKey => 'Type',
|
||||
AttributeFilterValue => 'post',
|
||||
);
|
||||
if ( $Data{Description} ) {
|
||||
print "+----------------------------------------------------------------------------+\n";
|
||||
print "| $Structure{Name}->{Content}-$Structure{Version}->{Content}\n";
|
||||
print "$Data{Title}";
|
||||
print "$Data{Description}";
|
||||
print "+----------------------------------------------------------------------------+\n";
|
||||
}
|
||||
}
|
||||
|
||||
# Disable in memory cache.
|
||||
$CacheObject->Configure(
|
||||
CacheInMemory => 0,
|
||||
);
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
143
Perl OTRS/Kernel/System/Console/Command/Admin/Package/Upgrade.pm
Normal file
143
Perl OTRS/Kernel/System/Console/Command/Admin/Package/Upgrade.pm
Normal file
@@ -0,0 +1,143 @@
|
||||
# --
|
||||
# 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::Package::Upgrade;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand Kernel::System::Console::Command::Admin::Package::List);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Cache',
|
||||
'Kernel::System::Package',
|
||||
'Kernel::Config',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Upgrade an OTRS package.');
|
||||
$Self->AddOption(
|
||||
Name => 'force',
|
||||
Description => 'Force package upgrade even if validation fails.',
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
$Self->AddArgument(
|
||||
Name => 'location',
|
||||
Description =>
|
||||
"Specify a file path, a remote repository (http://ftp.otrs.org/pub/otrs/packages/:Package-1.0.0.opm) or just any online repository (online:Package).",
|
||||
Required => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Upgrading package...</yellow>\n");
|
||||
|
||||
my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');
|
||||
|
||||
# Enable in-memory cache to improve SysConfig performance, which is normally disabled for commands.
|
||||
$CacheObject->Configure(
|
||||
CacheInMemory => 1,
|
||||
);
|
||||
|
||||
my $FileString = $Self->_PackageContentGet( Location => $Self->GetArgument('location') );
|
||||
return $Self->ExitCodeError() if !$FileString;
|
||||
|
||||
my $PackageObject = $Kernel::OM->Get('Kernel::System::Package');
|
||||
|
||||
# Parse package.
|
||||
my %Structure = $PackageObject->PackageParse(
|
||||
String => $FileString,
|
||||
);
|
||||
|
||||
my $Verified = $PackageObject->PackageVerify(
|
||||
Package => $FileString,
|
||||
Structure => \%Structure,
|
||||
) || 'verified';
|
||||
my %VerifyInfo = $PackageObject->PackageVerifyInfo();
|
||||
|
||||
# Check if installation of packages, which are not verified by us, is possible.
|
||||
my $PackageAllowNotVerifiedPackages = $Kernel::OM->Get('Kernel::Config')->Get('Package::AllowNotVerifiedPackages');
|
||||
|
||||
if ( $Verified ne 'verified' ) {
|
||||
|
||||
if ( !$PackageAllowNotVerifiedPackages ) {
|
||||
|
||||
$Self->PrintError(
|
||||
"$Structure{Name}->{Content}-$Structure{Version}->{Content} is not verified by the OTRS Group!\n\nThe installation of packages which are not verified by the OTRS Group is not possible by default."
|
||||
);
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
else {
|
||||
|
||||
$Self->Print(
|
||||
"<yellow>Package $Structure{Name}->{Content}-$Structure{Version}->{Content} not verified by the OTRS Group! It is recommended not to use this package.</yellow>\n"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
# Intro screen.
|
||||
if ( $Structure{IntroUpgrade} ) {
|
||||
my %Data = $Self->_PackageMetadataGet(
|
||||
Tag => $Structure{IntroUpgrade},
|
||||
AttributeFilterKey => 'Type',
|
||||
AttributeFilterValue => 'pre',
|
||||
);
|
||||
if ( $Data{Description} ) {
|
||||
print "+----------------------------------------------------------------------------+\n";
|
||||
print "| $Structure{Name}->{Content}-$Structure{Version}->{Content}\n";
|
||||
print "$Data{Title}";
|
||||
print "$Data{Description}";
|
||||
print "+----------------------------------------------------------------------------+\n";
|
||||
}
|
||||
}
|
||||
|
||||
# Upgrade.
|
||||
my $Success = $Kernel::OM->Get('Kernel::System::Package')->PackageUpgrade(
|
||||
String => $FileString,
|
||||
Force => $Self->GetOption('force'),
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Self->PrintError("Package upgrade failed.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
# Intro screen.
|
||||
if ( $Structure{IntroUpgrade} ) {
|
||||
my %Data = $Self->_PackageMetadataGet(
|
||||
Tag => $Structure{IntroUpgrade},
|
||||
AttributeFilterKey => 'Type',
|
||||
AttributeFilterValue => 'post',
|
||||
);
|
||||
if ( $Data{Description} ) {
|
||||
print "+----------------------------------------------------------------------------+\n";
|
||||
print "| $Structure{Name}->{Content}-$Structure{Version}->{Content}\n";
|
||||
print "$Data{Title}";
|
||||
print "$Data{Description}";
|
||||
print "+----------------------------------------------------------------------------+\n";
|
||||
}
|
||||
}
|
||||
|
||||
# Disable in memory cache.
|
||||
$CacheObject->Configure(
|
||||
CacheInMemory => 0,
|
||||
);
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,226 @@
|
||||
# --
|
||||
# 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::Package::UpgradeAll;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::Cache',
|
||||
'Kernel::System::Package',
|
||||
'Kernel::System::SystemData',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Upgrade all OTRS packages to the latest versions from the on-line repositories.');
|
||||
$Self->AddOption(
|
||||
Name => 'force',
|
||||
Description => 'Force package upgrade/installation even if validation fails.',
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');
|
||||
|
||||
# Enable in-memory cache to improve SysConfig performance, which is normally disabled for commands.
|
||||
$CacheObject->Configure(
|
||||
CacheInMemory => 1,
|
||||
);
|
||||
|
||||
my $PackageObject = $Kernel::OM->Get('Kernel::System::Package');
|
||||
|
||||
my %IsRunningResult = $PackageObject->PackageUpgradeAllIsRunning();
|
||||
|
||||
if ( $IsRunningResult{IsRunning} ) {
|
||||
$Self->Print("\nThere is another package upgrade process running\n");
|
||||
$Self->Print("\n<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
my @List = $PackageObject->RepositoryList(
|
||||
Result => 'short',
|
||||
);
|
||||
if ( !@List ) {
|
||||
$Self->Print("\nThere are no installed packages\n");
|
||||
$Self->Print("\n<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
my %RepositoryList = $PackageObject->_ConfiguredRepositoryDefinitionGet();
|
||||
|
||||
# Show cloud repositories if system is registered.
|
||||
my $RepositoryCloudList;
|
||||
my $RegistrationState = $Kernel::OM->Get('Kernel::System::SystemData')->SystemDataGet(
|
||||
Key => 'Registration::State',
|
||||
) || '';
|
||||
|
||||
if (
|
||||
$RegistrationState eq 'registered'
|
||||
&& !$Kernel::OM->Get('Kernel::Config')->Get('CloudServices::Disabled')
|
||||
)
|
||||
{
|
||||
|
||||
$Self->Print("<yellow>Getting cloud repositories information...</yellow>\n");
|
||||
|
||||
$RepositoryCloudList = $PackageObject->RepositoryCloudList( NoCache => 1 );
|
||||
|
||||
$Self->Print(" Cloud repositories... <green>Done</green>\n\n");
|
||||
}
|
||||
|
||||
my %RepositoryListAll = ( %RepositoryList, %{ $RepositoryCloudList || {} } );
|
||||
|
||||
my @PackageOnlineList;
|
||||
my %PackageSoruceLookup;
|
||||
|
||||
$Self->Print("<yellow>Fetching on-line repositories...</yellow>\n");
|
||||
|
||||
URL:
|
||||
for my $URL ( sort keys %RepositoryListAll ) {
|
||||
|
||||
$Self->Print(" $RepositoryListAll{$URL}... ");
|
||||
|
||||
my $FromCloud = 0;
|
||||
if ( $RepositoryCloudList->{$URL} ) {
|
||||
$FromCloud = 1;
|
||||
|
||||
}
|
||||
|
||||
my @OnlineList = $PackageObject->PackageOnlineList(
|
||||
URL => $URL,
|
||||
Lang => 'en',
|
||||
Cache => 1,
|
||||
FromCloud => $FromCloud,
|
||||
);
|
||||
|
||||
$Self->Print("<green>Done</green>\n");
|
||||
}
|
||||
|
||||
# Check again after repository refresh
|
||||
%IsRunningResult = $PackageObject->PackageUpgradeAllIsRunning();
|
||||
|
||||
if ( $IsRunningResult{IsRunning} ) {
|
||||
$Self->Print("\nThere is another package upgrade process running\n");
|
||||
$Self->Print("\n<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
$Self->Print("\n<yellow>Upgrading installed packages...</yellow>\n");
|
||||
|
||||
my $ErrorMessage;
|
||||
my %Result;
|
||||
eval {
|
||||
# Localize the standard error, everything will be restored after the eval block.
|
||||
# Package installation or upgrades always produce messages in STDERR for files and directories.
|
||||
local *STDERR;
|
||||
|
||||
# Redirect the standard error to a variable.
|
||||
open STDERR, ">>", \$ErrorMessage;
|
||||
|
||||
%Result = $PackageObject->PackageUpgradeAll(
|
||||
Force => $Self->GetOption('force'),
|
||||
);
|
||||
};
|
||||
|
||||
# Remove package upgrade data from the DB, so the GUI will not show the finished notification.
|
||||
$PackageObject->PackageUpgradeAllDataDelete();
|
||||
|
||||
# Be sure to print any error messages in case of a failure.
|
||||
if ( IsHashRefWithData( $Result{Failed} ) ) {
|
||||
print STDERR $ErrorMessage if $ErrorMessage;
|
||||
}
|
||||
|
||||
if (
|
||||
!IsHashRefWithData( $Result{Updated} )
|
||||
&& !IsHashRefWithData( $Result{Installed} )
|
||||
&& !IsHashRefWithData( $Result{Undeployed} )
|
||||
&& !IsHashRefWithData( $Result{Failed} )
|
||||
)
|
||||
{
|
||||
$Self->Print(" All installed packages are already at their latest versions.\n");
|
||||
$Self->Print("\n<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
my %SuccessMessages = (
|
||||
Updated => 'updated',
|
||||
Installed => 'installed',
|
||||
AlreadyUpdated => 'already up-to-date',
|
||||
Undeployed => 'already up-to-date but <red>not deployed correctly</red>',
|
||||
);
|
||||
|
||||
for my $ResultPart (qw(AlreadyUpdated Undeployed Updated Installed)) {
|
||||
if ( IsHashRefWithData( $Result{$ResultPart} ) ) {
|
||||
$Self->Print( ' The following packages were ' . $SuccessMessages{$ResultPart} . "...\n" );
|
||||
my $Color = 'green';
|
||||
if ( $ResultPart eq 'Installed' || $ResultPart eq 'Undeployed' ) {
|
||||
$Color = 'yellow';
|
||||
}
|
||||
for my $PackageName ( sort keys %{ $Result{$ResultPart} } ) {
|
||||
$Self->Print(" <$Color>$PackageName</$Color>\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my %FailedMessages = (
|
||||
UpdateError => 'could not be upgraded...',
|
||||
InstallError => 'could not be installed...',
|
||||
Cyclic => 'had cyclic dependencies...',
|
||||
NotFound => 'could not be found in the on-line repositories...',
|
||||
WrongVersion => 'require a version higher than the one found in the on-line repositories...',
|
||||
DependencyFail => 'fail to upgrade/install their package dependencies...'
|
||||
|
||||
);
|
||||
|
||||
if ( IsHashRefWithData( $Result{Failed} ) ) {
|
||||
for my $FailedPart (qw(UpdateError InstallError DependencyFail Cyclic NotFound WrongVersion)) {
|
||||
if ( IsHashRefWithData( $Result{Failed}->{$FailedPart} ) ) {
|
||||
$Self->Print(" The following packages $FailedMessages{$FailedPart}\n");
|
||||
for my $PackageName ( sort keys %{ $Result{Failed}->{$FailedPart} } ) {
|
||||
$Self->Print(" <red>$PackageName</red>\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !$Result{Success} ) {
|
||||
$Self->Print("\n<red>Fail.</red>\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
if ( IsHashRefWithData( $Result{Undeployed} ) ) {
|
||||
my $Message = "\nPlease reinstall not correctly deployed packages using"
|
||||
. " <yellow>Admin::Package::Reinstall</yellow>"
|
||||
. " or <yellow>Admin::Package::ReinstallAll</yellow> console commands.\n";
|
||||
$Self->Print($Message);
|
||||
}
|
||||
|
||||
# Disable in memory cache.
|
||||
$CacheObject->Configure(
|
||||
CacheInMemory => 0,
|
||||
);
|
||||
|
||||
$Self->Print("\n<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
163
Perl OTRS/Kernel/System/Console/Command/Admin/Queue/Add.pm
Normal file
163
Perl OTRS/Kernel/System/Console/Command/Admin/Queue/Add.pm
Normal file
@@ -0,0 +1,163 @@
|
||||
# --
|
||||
# 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::Queue::Add;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Group',
|
||||
'Kernel::System::Queue',
|
||||
'Kernel::System::SystemAddress',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Create a new queue.');
|
||||
$Self->AddOption(
|
||||
Name => 'name',
|
||||
Description => 'Queue name for the new queue.',
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'group',
|
||||
Description => 'Group which should be assigned to the new queue.',
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'system-address-id',
|
||||
Description => 'ID of the system address which should be assigned to the new queue.',
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/\d/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'system-address-name',
|
||||
Description => 'System email address which should be assigned to the new queue.',
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'comment',
|
||||
Description => 'Comment for the new queue.',
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'unlock-timeout',
|
||||
Description => 'Unlock timeout in minutes for the new queue.',
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/\d/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'first-response-time',
|
||||
Description => 'Ticket first response time in minutes for the new queue.',
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/\d/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'update-time',
|
||||
Description => 'Ticket update time in minutes for the new queue.',
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/\d/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'solution-time',
|
||||
Description => 'Ticket solution time in minutes for the new queue.',
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/\d/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'calendar',
|
||||
Description => 'Calendar order number for the new queue.',
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Adding a new queue...</yellow>\n");
|
||||
|
||||
# check group
|
||||
my $Group = $Self->GetOption('group');
|
||||
my $GroupID = $Kernel::OM->Get('Kernel::System::Group')->GroupLookup( Group => $Group );
|
||||
if ( !$GroupID ) {
|
||||
$Self->PrintError("Found no GroupID for $Group\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
my $SystemAddressID = $Self->GetOption('system-address-id');
|
||||
my $SystemAddressName = $Self->GetOption('system-address-name');
|
||||
|
||||
# check System Address
|
||||
if ($SystemAddressName) {
|
||||
my %SystemAddressList = $Kernel::OM->Get('Kernel::System::SystemAddress')->SystemAddressList(
|
||||
Valid => 1
|
||||
);
|
||||
ADDRESS:
|
||||
for my $ID ( sort keys %SystemAddressList ) {
|
||||
my %SystemAddressInfo = $Kernel::OM->Get('Kernel::System::SystemAddress')->SystemAddressGet(
|
||||
ID => $ID
|
||||
);
|
||||
if ( $SystemAddressInfo{Name} eq $SystemAddressName ) {
|
||||
$SystemAddressID = $ID;
|
||||
last ADDRESS;
|
||||
}
|
||||
}
|
||||
if ( !$SystemAddressID ) {
|
||||
$Self->PrintError("Address $SystemAddressName not found\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
}
|
||||
|
||||
# add queue
|
||||
my $Success = $Kernel::OM->Get('Kernel::System::Queue')->QueueAdd(
|
||||
Name => $Self->GetOption('name'),
|
||||
GroupID => $GroupID,
|
||||
SystemAddressID => $SystemAddressID || $Self->GetOption('system-address-id') || undef,
|
||||
Comment => $Self->GetOption('comment'),
|
||||
UnlockTimeout => $Self->GetOption('unlock-timeout'),
|
||||
FirstResponseTime => $Self->GetOption('first-response-time'),
|
||||
UpdateTime => $Self->GetOption('update-time'),
|
||||
SolutionTime => $Self->GetOption('solution-time'),
|
||||
Calendar => $Self->GetOption('calendar'),
|
||||
ValidID => 1,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
# error handling
|
||||
if ( !$Success ) {
|
||||
$Self->PrintError("Can't create queue.\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
85
Perl OTRS/Kernel/System/Console/Command/Admin/Queue/List.pm
Normal file
85
Perl OTRS/Kernel/System/Console/Command/Admin/Queue/List.pm
Normal file
@@ -0,0 +1,85 @@
|
||||
# --
|
||||
# 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::Queue::List;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Queue',
|
||||
'Kernel::System::Valid',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('List existing queues.');
|
||||
$Self->AddOption(
|
||||
Name => 'all',
|
||||
Description => "Show all queues.",
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'verbose',
|
||||
Description => "More detailled output.",
|
||||
Required => 0,
|
||||
HasValue => 0,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Listing Queues...</yellow>\n");
|
||||
|
||||
my $QueueObject = $Kernel::OM->Get('Kernel::System::Queue');
|
||||
my %ValidList = $Kernel::OM->Get('Kernel::System::Valid')->ValidList();
|
||||
|
||||
my $Valid = !$Self->GetOption('all');
|
||||
my %Queues = $QueueObject->QueueList( Valid => $Valid );
|
||||
|
||||
if ( $Self->GetOption('verbose') ) {
|
||||
for ( sort keys %Queues ) {
|
||||
my %Queue = $QueueObject->QueueGet( ID => $_ );
|
||||
|
||||
$Self->Print( sprintf( "%6s", $_ ) . " $Queue{'Name'} " );
|
||||
if ( $Queue{'ValidID'} == 1 ) {
|
||||
$Self->Print("<green>$ValidList{$Queue{'ValidID'}}</green>\n");
|
||||
}
|
||||
else {
|
||||
$Self->Print("<yellow>$ValidList{$Queue{'ValidID'}}</yellow>\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for ( sort keys %Queues ) {
|
||||
$Self->Print(" $Queues{$_}\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
|
||||
63
Perl OTRS/Kernel/System/Console/Command/Admin/Role/Add.pm
Normal file
63
Perl OTRS/Kernel/System/Console/Command/Admin/Role/Add.pm
Normal file
@@ -0,0 +1,63 @@
|
||||
# --
|
||||
# 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::Role::Add;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Group',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Create a new role.');
|
||||
$Self->AddOption(
|
||||
Name => 'name',
|
||||
Description => 'Name of the new role.',
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'comment',
|
||||
Description => 'Comment for the new role.',
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Adding a new role...</yellow>\n");
|
||||
|
||||
my $RID = $Kernel::OM->Get('Kernel::System::Group')->RoleAdd(
|
||||
Name => $Self->GetOption('name'),
|
||||
Comment => $Self->GetOption('comment') || '',
|
||||
ValidID => 1,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
if ($RID) {
|
||||
$Self->Print("<green>Done</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
$Self->PrintError("Can't add role");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,88 @@
|
||||
# --
|
||||
# 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::Role::UserLink;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::User',
|
||||
'Kernel::System::Group',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Connect a user to a role.');
|
||||
$Self->AddOption(
|
||||
Name => 'user-name',
|
||||
Description => 'Name of the user who should be linked to the given role.',
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'role-name',
|
||||
Description => 'Name of the role the given user should be linked to.',
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->{UserName} = $Self->GetOption('user-name');
|
||||
$Self->{RoleName} = $Self->GetOption('role-name');
|
||||
|
||||
# check user
|
||||
$Self->{UserID} = $Kernel::OM->Get('Kernel::System::User')->UserLookup( UserLogin => $Self->{UserName} );
|
||||
if ( !$Self->{UserID} ) {
|
||||
die "User $Self->{UserName} does not exist.\n";
|
||||
}
|
||||
|
||||
# check role
|
||||
$Self->{RoleID} = $Kernel::OM->Get('Kernel::System::Group')->RoleLookup( Role => $Self->{RoleName} );
|
||||
if ( !$Self->{RoleID} ) {
|
||||
die "Role $Self->{RoleName} does not exist.\n";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Trying to link user $Self->{UserName} to role $Self->{RoleName}...</yellow>\n");
|
||||
|
||||
# add user 2 role
|
||||
if (
|
||||
!$Kernel::OM->Get('Kernel::System::Group')->PermissionRoleUserAdd(
|
||||
UID => $Self->{UserID},
|
||||
RID => $Self->{RoleID},
|
||||
Active => 1,
|
||||
UserID => 1,
|
||||
)
|
||||
)
|
||||
{
|
||||
$Self->PrintError("Can't add user to role.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("Done.\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
188
Perl OTRS/Kernel/System/Console/Command/Admin/Service/Add.pm
Normal file
188
Perl OTRS/Kernel/System/Console/Command/Admin/Service/Add.pm
Normal file
@@ -0,0 +1,188 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# $origin: otrs - b9cf29ede488bbc3bf5bd0d49f422ecc65668a0c - Kernel/System/Console/Command/Admin/Service/Add.pm
|
||||
# --
|
||||
# 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::Service::Add;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
# ---
|
||||
# ITSMCore
|
||||
# ---
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
# ---
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Service',
|
||||
# ---
|
||||
# ITSMCore
|
||||
# ---
|
||||
'Kernel::System::DynamicField',
|
||||
'Kernel::System::GeneralCatalog',
|
||||
# ---
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Add new service.');
|
||||
$Self->AddOption(
|
||||
Name => 'name',
|
||||
Description => "Name of the new service.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
# ---
|
||||
# ITSMCore
|
||||
# ---
|
||||
$Self->AddOption(
|
||||
Name => 'criticality',
|
||||
Description => "Criticality of the new service.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'type',
|
||||
Description => "Type of the new service.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
# ---
|
||||
$Self->AddOption(
|
||||
Name => 'parent-name',
|
||||
Description => "Parent service name. If given, the new service will be a subservice of the given parent.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'comment',
|
||||
Description => "Comment for the new service.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Get all services.
|
||||
$Self->{Name} = $Self->GetOption('name');
|
||||
my %ServiceList = $Kernel::OM->Get('Kernel::System::Service')->ServiceList(
|
||||
Valid => 0,
|
||||
UserID => 1,
|
||||
);
|
||||
my %Reverse = reverse %ServiceList;
|
||||
|
||||
$Self->{ParentName} = $Self->GetOption('parent-name');
|
||||
if ( $Self->{ParentName} ) {
|
||||
|
||||
# Check if Parent service exists.
|
||||
$Self->{ParentID} = $Kernel::OM->Get('Kernel::System::Service')->ServiceLookup(
|
||||
Name => $Self->{ParentName},
|
||||
UserID => 1,
|
||||
);
|
||||
die "Parent service $Self->{ParentName} does not exist.\n" if !$Self->{ParentID};
|
||||
|
||||
# Check if Parent::Child service combination exists.
|
||||
my $ServiceName = $Self->{ParentName} . '::' . $Self->{Name};
|
||||
die "Service '$ServiceName' already exists!\n" if $Reverse{$ServiceName};
|
||||
}
|
||||
else {
|
||||
|
||||
# Check if service already exists.
|
||||
die "Service '$Self->{Name}' already exists!\n" if $Reverse{ $Self->{Name} };
|
||||
}
|
||||
# ---
|
||||
# ITSMCore
|
||||
# ---
|
||||
|
||||
# get the dynamic field config for ITSMCriticality
|
||||
my $DynamicFieldConfigArrayRef = $Kernel::OM->Get('Kernel::System::DynamicField')->DynamicFieldListGet(
|
||||
Valid => 1,
|
||||
ObjectType => [ 'Ticket' ],
|
||||
FieldFilter => {
|
||||
ITSMCriticality => 1,
|
||||
},
|
||||
);
|
||||
|
||||
# get the dynamic field values for ITSMCriticality
|
||||
my %PossibleValues;
|
||||
DYNAMICFIELD:
|
||||
for my $DynamicFieldConfig ( @{ $DynamicFieldConfigArrayRef } ) {
|
||||
next DYNAMICFIELD if !IsHashRefWithData($DynamicFieldConfig);
|
||||
|
||||
# get PossibleValues
|
||||
$PossibleValues{ $DynamicFieldConfig->{Name} } = $DynamicFieldConfig->{Config}->{PossibleValues} || {};
|
||||
}
|
||||
|
||||
my %Criticality = %{ $PossibleValues{ITSMCriticality} };
|
||||
|
||||
$Self->{Criticality} = $Criticality{ $Self->GetOption('criticality') };
|
||||
|
||||
if ( !$Self->{Criticality} ) {
|
||||
die "Criticality '" . $Self->GetOption('criticality') . "' does not exist.\n";
|
||||
}
|
||||
|
||||
# get service type list
|
||||
my $ServiceTypeList = $Kernel::OM->Get('Kernel::System::GeneralCatalog')->ItemList(
|
||||
Class => 'ITSM::Service::Type',
|
||||
);
|
||||
|
||||
my %ServiceType = reverse %{$ServiceTypeList};
|
||||
|
||||
$Self->{TypeID} = $ServiceType{ $Self->GetOption('type') };
|
||||
|
||||
if ( !$Self->{TypeID} ) {
|
||||
die "Type '" . $Self->GetOption('type') . "' does not exist.\n";
|
||||
}
|
||||
# ---
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Adding a new service...</yellow>\n");
|
||||
|
||||
# add service
|
||||
if (
|
||||
!$Kernel::OM->Get('Kernel::System::Service')->ServiceAdd(
|
||||
UserID => 1,
|
||||
ValidID => 1,
|
||||
Name => $Self->{Name},
|
||||
Comment => $Self->GetOption('comment'),
|
||||
ParentID => $Self->{ParentID},
|
||||
# ---
|
||||
# ITSMCore
|
||||
# ---
|
||||
TypeID => $Self->{TypeID},
|
||||
Criticality => $Self->{Criticality},
|
||||
# ---
|
||||
)
|
||||
)
|
||||
{
|
||||
$Self->PrintError("Can't add service.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -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::Console::Command::Admin::Service::Add;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Service',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Add new service.');
|
||||
$Self->AddOption(
|
||||
Name => 'name',
|
||||
Description => "Name of the new service.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'parent-name',
|
||||
Description => "Parent service name. If given, the new service will be a subservice of the given parent.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'comment',
|
||||
Description => "Comment for the new service.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Get all services.
|
||||
$Self->{Name} = $Self->GetOption('name');
|
||||
my %ServiceList = $Kernel::OM->Get('Kernel::System::Service')->ServiceList(
|
||||
Valid => 0,
|
||||
UserID => 1,
|
||||
);
|
||||
my %Reverse = reverse %ServiceList;
|
||||
|
||||
$Self->{ParentName} = $Self->GetOption('parent-name');
|
||||
if ( $Self->{ParentName} ) {
|
||||
|
||||
# Check if Parent service exists.
|
||||
$Self->{ParentID} = $Kernel::OM->Get('Kernel::System::Service')->ServiceLookup(
|
||||
Name => $Self->{ParentName},
|
||||
UserID => 1,
|
||||
);
|
||||
die "Parent service $Self->{ParentName} does not exist.\n" if !$Self->{ParentID};
|
||||
|
||||
# Check if Parent::Child service combination exists.
|
||||
my $ServiceName = $Self->{ParentName} . '::' . $Self->{Name};
|
||||
die "Service '$ServiceName' already exists!\n" if $Reverse{$ServiceName};
|
||||
}
|
||||
else {
|
||||
|
||||
# Check if service already exists.
|
||||
die "Service '$Self->{Name}' already exists!\n" if $Reverse{ $Self->{Name} };
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Adding a new service...</yellow>\n");
|
||||
|
||||
# add service
|
||||
if (
|
||||
!$Kernel::OM->Get('Kernel::System::Service')->ServiceAdd(
|
||||
UserID => 1,
|
||||
ValidID => 1,
|
||||
Name => $Self->{Name},
|
||||
Comment => $Self->GetOption('comment'),
|
||||
ParentID => $Self->{ParentID},
|
||||
)
|
||||
)
|
||||
{
|
||||
$Self->PrintError("Can't add service.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,114 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2016 OTRS AG, http://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (AGPL). If you
|
||||
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::Console::Command::Admin::Service::Add;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Service',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Add new service.');
|
||||
$Self->AddOption(
|
||||
Name => 'name',
|
||||
Description => "Name of the new service.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'parent-name',
|
||||
Description => "Parent service name. If given, the new service will be a subservice of the given parent.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'comment',
|
||||
Description => "Comment for the new service.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check if service already exists
|
||||
$Self->{Name} = $Self->GetOption('name');
|
||||
my %ServiceList = $Kernel::OM->Get('Kernel::System::Service')->ServiceList(
|
||||
Valid => 0,
|
||||
UserID => 1,
|
||||
);
|
||||
my %Reverse = reverse %ServiceList;
|
||||
if ( $Reverse{ $Self->{Name} } ) {
|
||||
die "Service '$Self->{Name}' already exists!\n";
|
||||
}
|
||||
|
||||
# check if parent exists (if given)
|
||||
$Self->{ParentName} = $Self->GetOption('parent-name');
|
||||
if ( $Self->{ParentName} ) {
|
||||
$Self->{ParentID} = $Kernel::OM->Get('Kernel::System::Service')->ServiceLookup(
|
||||
Name => $Self->{ParentName},
|
||||
UserID => 1,
|
||||
);
|
||||
if ( !$Self->{ParentID} ) {
|
||||
die "Parent service $Self->{ParentName} does not exist.\n";
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Adding a new service...</yellow>\n");
|
||||
|
||||
# add service
|
||||
if (
|
||||
!$Kernel::OM->Get('Kernel::System::Service')->ServiceAdd(
|
||||
UserID => 1,
|
||||
ValidID => 1,
|
||||
Name => $Self->{Name},
|
||||
Comment => $Self->GetOption('comment'),
|
||||
ParentID => $Self->{ParentID},
|
||||
)
|
||||
)
|
||||
{
|
||||
$Self->PrintError("Can't add service.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=back
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<http://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (AGPL). If you
|
||||
did not receive this file, see L<http://www.gnu.org/licenses/agpl.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,86 @@
|
||||
# --
|
||||
# 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::StandardTemplate::QueueLink;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Queue',
|
||||
'Kernel::System::StandardTemplate',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Link a template to a queue.');
|
||||
$Self->AddOption(
|
||||
Name => 'template-name',
|
||||
Description => "Name of the template which should be linked to the given queue.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'queue-name',
|
||||
Description => "Name of the queue the given template should be linked to.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check template
|
||||
$Self->{TemplateName} = $Self->GetOption('template-name');
|
||||
$Self->{TemplateID} = $Kernel::OM->Get('Kernel::System::StandardTemplate')
|
||||
->StandardTemplateLookup( StandardTemplate => $Self->{TemplateName} );
|
||||
if ( !$Self->{TemplateID} ) {
|
||||
die "Standard template '$Self->{TemplateName}' does not exist.\n";
|
||||
}
|
||||
|
||||
# check queue
|
||||
$Self->{QueueName} = $Self->GetOption('queue-name');
|
||||
$Self->{QueueID} = $Kernel::OM->Get('Kernel::System::Queue')->QueueLookup( Queue => $Self->{QueueName} );
|
||||
if ( !$Self->{QueueID} ) {
|
||||
die "Queue '$Self->{QueueName}' does not exist.\n";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Trying to link template $Self->{TemplateName} to queue $Self->{QueueName}...</yellow>\n");
|
||||
|
||||
if (
|
||||
!$Kernel::OM->Get('Kernel::System::Queue')->QueueStandardTemplateMemberAdd(
|
||||
StandardTemplateID => $Self->{TemplateID},
|
||||
QueueID => $Self->{QueueID},
|
||||
Active => 1,
|
||||
UserID => 1,
|
||||
)
|
||||
)
|
||||
{
|
||||
$Self->PrintError("Can't link template to queue.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,106 @@
|
||||
# --
|
||||
# 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::SystemAddress::Add;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Queue',
|
||||
'Kernel::System::SystemAddress',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Add new system address.');
|
||||
$Self->AddOption(
|
||||
Name => 'name',
|
||||
Description => "Display name of the new system address.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'email-address',
|
||||
Description => "Email address which should be used for the new system address.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'queue-name',
|
||||
Description => "Queue name the address should be linked to.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'comment',
|
||||
Description => "Comment for the new system address.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check if queue already exists
|
||||
$Self->{QueueName} = $Self->GetOption('queue-name');
|
||||
$Self->{QueueID} = $Kernel::OM->Get('Kernel::System::Queue')->QueueLookup(
|
||||
Queue => $Self->{QueueName},
|
||||
);
|
||||
if ( !$Self->{QueueID} ) {
|
||||
die "Queue $Self->{QueueName} does not exist.\n";
|
||||
}
|
||||
|
||||
# check if system address already exists
|
||||
$Self->{EmailAddress} = $Self->GetOption('email-address');
|
||||
my $SystemExists = $Kernel::OM->Get('Kernel::System::SystemAddress')->SystemAddressIsLocalAddress(
|
||||
Address => $Self->{EmailAddress},
|
||||
);
|
||||
if ($SystemExists) {
|
||||
die "SystemAddress $Self->{EmailAddress} already exists.\n";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Adding a new system address...</yellow>\n");
|
||||
|
||||
# add system address
|
||||
if (
|
||||
!$Kernel::OM->Get('Kernel::System::SystemAddress')->SystemAddressAdd(
|
||||
UserID => 1,
|
||||
ValidID => 1,
|
||||
Comment => $Self->GetOption('comment'),
|
||||
Realname => $Self->GetOption('name'),
|
||||
QueueID => $Self->{QueueID},
|
||||
Name => $Self->{EmailAddress},
|
||||
)
|
||||
)
|
||||
{
|
||||
$Self->PrintError("Can't add system address.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,57 @@
|
||||
# --
|
||||
# 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::TicketType::Add;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Type',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Add new ticket type.');
|
||||
$Self->AddOption(
|
||||
Name => 'name',
|
||||
Description => "Name of the new ticket type.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Adding a new ticket type...</yellow>\n");
|
||||
|
||||
# add ticket type
|
||||
if (
|
||||
!$Kernel::OM->Get('Kernel::System::Type')->TypeAdd(
|
||||
UserID => 1,
|
||||
ValidID => 1,
|
||||
Name => $Self->GetOption('name'),
|
||||
)
|
||||
)
|
||||
{
|
||||
$Self->PrintError("Can't add ticket type.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
132
Perl OTRS/Kernel/System/Console/Command/Admin/User/Add.pm
Normal file
132
Perl OTRS/Kernel/System/Console/Command/Admin/User/Add.pm
Normal file
@@ -0,0 +1,132 @@
|
||||
# --
|
||||
# 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::User::Add;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Group',
|
||||
'Kernel::System::User',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Add a user.');
|
||||
$Self->AddOption(
|
||||
Name => 'user-name',
|
||||
Description => "User name for the new user.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'first-name',
|
||||
Description => "First name of the new user.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'last-name',
|
||||
Description => "Last name of the new user.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'email-address',
|
||||
Description => "Email address of the new user.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'password',
|
||||
Description => "Password for the new user. If left empty, a password will be created automatically.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'group',
|
||||
Description => "Name of the group to which the new user should be added (with rw permissions!).",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
Multiple => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check if all groups exist
|
||||
my @Groups = @{ $Self->GetOption('group') // [] };
|
||||
my %GroupList = reverse $Kernel::OM->Get('Kernel::System::Group')->GroupList();
|
||||
|
||||
GROUP:
|
||||
for my $Group (@Groups) {
|
||||
if ( !$GroupList{$Group} ) {
|
||||
die "Group '$Group' does not exist.\n";
|
||||
}
|
||||
$Self->{Groups}->{ $GroupList{$Group} } = $Group;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Adding a new user...</yellow>\n");
|
||||
|
||||
# add user
|
||||
my $UserID = $Kernel::OM->Get('Kernel::System::User')->UserAdd(
|
||||
UserLogin => $Self->GetOption('user-name'),
|
||||
UserFirstname => $Self->GetOption('first-name'),
|
||||
UserLastname => $Self->GetOption('last-name'),
|
||||
UserPw => $Self->GetOption('password'),
|
||||
UserEmail => $Self->GetOption('email-address'),
|
||||
ChangeUserID => 1,
|
||||
UserID => 1,
|
||||
ValidID => 1,
|
||||
);
|
||||
|
||||
if ( !$UserID ) {
|
||||
$Self->PrintError("Can't add user.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
for my $GroupID ( sort keys %{ $Self->{Groups} } ) {
|
||||
|
||||
my $Success = $Kernel::OM->Get('Kernel::System::Group')->PermissionGroupUserAdd(
|
||||
UID => $UserID,
|
||||
GID => $GroupID,
|
||||
Permission => { 'rw' => 1 },
|
||||
UserID => 1,
|
||||
);
|
||||
if ($Success) {
|
||||
$Self->Print( "<green>User added to group '" . $Self->{Groups}->{$GroupID} . "'</green>\n" );
|
||||
}
|
||||
else {
|
||||
$Self->PrintError( "Failed to add user to group '" . $Self->{Groups}->{$GroupID} . "'." );
|
||||
}
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,77 @@
|
||||
# --
|
||||
# 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::User::SetPassword;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::User',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Update the password for an agent.');
|
||||
$Self->AddArgument(
|
||||
Name => 'user',
|
||||
Description => "Specify the user login of the agent to be updated.",
|
||||
Required => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddArgument(
|
||||
Name => 'password',
|
||||
Description => "Set a new password for the agent (a password will be generated otherwise).",
|
||||
Required => 0,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $Login = $Self->GetArgument('user');
|
||||
|
||||
my $UserObject = $Kernel::OM->Get('Kernel::System::User');
|
||||
my %UserList = $UserObject->UserSearch(
|
||||
UserLogin => $Login,
|
||||
);
|
||||
|
||||
if ( !scalar %UserList ) {
|
||||
$Self->PrintError("No user found with login '$Login'!\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
# if no password has been provided, generate one
|
||||
my $Password = $Self->GetArgument('password');
|
||||
if ( !$Password ) {
|
||||
$Password = $UserObject->GenerateRandomPassword( Size => 12 );
|
||||
$Self->Print("<yellow>Generated password '$Password'.</yellow>\n");
|
||||
}
|
||||
|
||||
my $Result = $UserObject->SetPassword(
|
||||
UserLogin => $Login,
|
||||
PW => $Password,
|
||||
);
|
||||
|
||||
if ( !$Result ) {
|
||||
$Self->PrintError("Failed to set password!\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Successfully set password for user '$Login'.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
101
Perl OTRS/Kernel/System/Console/Command/Admin/WebService/Add.pm
Normal file
101
Perl OTRS/Kernel/System/Console/Command/Admin/WebService/Add.pm
Normal file
@@ -0,0 +1,101 @@
|
||||
# --
|
||||
# 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::WebService::Add;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::GenericInterface::Webservice',
|
||||
'Kernel::System::Main',
|
||||
'Kernel::System::YAML',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Create a new web service.');
|
||||
$Self->AddOption(
|
||||
Name => 'name',
|
||||
Description => "The name of the new web service.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'source-path',
|
||||
Description => "Specify the location of the web service YAML configuration file.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $SourcePath = $Self->GetOption('source-path');
|
||||
if ( !-r $SourcePath ) {
|
||||
die "Source file $SourcePath does not exist / is not readable.\n";
|
||||
}
|
||||
|
||||
my $List = $Kernel::OM->Get('Kernel::System::GenericInterface::Webservice')->WebserviceList();
|
||||
my %WebServiceLookup = reverse %{$List};
|
||||
|
||||
my $Name = $Self->GetOption('name');
|
||||
if ( $WebServiceLookup{$Name} ) {
|
||||
die "A web service with name $Name already exists in this system.\n";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Creating web service...</yellow>\n");
|
||||
|
||||
# read config
|
||||
my $Content = $Kernel::OM->Get('Kernel::System::Main')->FileRead(
|
||||
Location => $Self->GetOption('source-path'),
|
||||
);
|
||||
if ( !$Content ) {
|
||||
$Self->PrintError('Could not read YAML source.');
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
my $Config = $Kernel::OM->Get('Kernel::System::YAML')->Load( Data => ${$Content} );
|
||||
|
||||
if ( !$Config ) {
|
||||
$Self->PrintError('Could not parse YAML source.');
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
# add new web service
|
||||
my $ID = $Kernel::OM->Get('Kernel::System::GenericInterface::Webservice')->WebserviceAdd(
|
||||
Name => $Self->GetOption('name'),
|
||||
Config => $Config,
|
||||
ValidID => 1,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
if ( !$ID ) {
|
||||
$Self->PrintError('Could not create web service!');
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,80 @@
|
||||
# --
|
||||
# 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::WebService::Delete;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::GenericInterface::Webservice',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Delete an existing web service.');
|
||||
$Self->AddOption(
|
||||
Name => 'webservice-id',
|
||||
Description => "The ID of an existing web service.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/\A\d+\z/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $WebServiceList = $Kernel::OM->Get('Kernel::System::GenericInterface::Webservice')->WebserviceList();
|
||||
|
||||
my $WebServiceID = $Self->GetOption('webservice-id');
|
||||
if ( !$WebServiceList->{$WebServiceID} ) {
|
||||
die "A web service with the ID $WebServiceID does not exists in this system.\n";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Deleting web service...</yellow>\n");
|
||||
|
||||
# get current web service
|
||||
my $WebServiceID = $Self->GetOption('webservice-id');
|
||||
|
||||
my $WebService =
|
||||
$Kernel::OM->Get('Kernel::System::GenericInterface::Webservice')->WebserviceGet(
|
||||
ID => $WebServiceID,
|
||||
);
|
||||
|
||||
if ( !$WebService ) {
|
||||
$Self->PrintError("Could not get a web service with the ID $WebServiceID from the database!");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
# web service delete
|
||||
my $Success = $Kernel::OM->Get('Kernel::System::GenericInterface::Webservice')->WebserviceDelete(
|
||||
ID => $WebServiceID,
|
||||
UserID => 1,
|
||||
);
|
||||
if ( !$Success ) {
|
||||
$Self->PrintError('Could not delete web service!');
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,95 @@
|
||||
# --
|
||||
# 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::WebService::Dump;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::GenericInterface::Webservice',
|
||||
'Kernel::System::Main',
|
||||
'Kernel::System::YAML',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Print a web service configuration (in YAML format) into a file.');
|
||||
$Self->AddOption(
|
||||
Name => 'webservice-id',
|
||||
Description => "The ID of an existing web service.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/\A\d+\z/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'target-path',
|
||||
Description => "Specify the output location of the web service YAML configuration file.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $WebServiceList = $Kernel::OM->Get('Kernel::System::GenericInterface::Webservice')->WebserviceList();
|
||||
|
||||
my $WebServiceID = $Self->GetOption('webservice-id');
|
||||
if ( !$WebServiceList->{$WebServiceID} ) {
|
||||
die "A web service with the ID $WebServiceID does not exists in this system.\n";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Dumping web service...</yellow>\n");
|
||||
|
||||
# get current web service
|
||||
my $WebServiceID = $Self->GetOption('webservice-id');
|
||||
|
||||
my $WebService =
|
||||
$Kernel::OM->Get('Kernel::System::GenericInterface::Webservice')->WebserviceGet(
|
||||
ID => $WebServiceID,
|
||||
);
|
||||
|
||||
if ( !$WebService ) {
|
||||
$Self->PrintError("Could not get a web service with the ID $WebServiceID from the database!");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
# dump config as string
|
||||
my $Config = $Kernel::OM->Get('Kernel::System::YAML')->Dump( Data => $WebService->{Config} );
|
||||
|
||||
my $TargetPath = $Self->GetOption('target-path');
|
||||
|
||||
# write configuration in a file
|
||||
my $FileLocation = $Kernel::OM->Get('Kernel::System::Main')->FileWrite(
|
||||
Location => $TargetPath,
|
||||
Content => \$Config,
|
||||
Mode => 'utf8',
|
||||
);
|
||||
|
||||
if ( !$FileLocation ) {
|
||||
$Self->PrintError("Could not write file $TargetPath!");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,42 @@
|
||||
# --
|
||||
# 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::WebService::List;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::GenericInterface::Webservice',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('List all web services.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Listing all web services...</yellow>\n");
|
||||
|
||||
my $List = $Kernel::OM->Get('Kernel::System::GenericInterface::Webservice')->WebserviceList();
|
||||
for my $ID ( sort keys %{$List} ) {
|
||||
print " $List->{$ID} ($ID)\n";
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,113 @@
|
||||
# --
|
||||
# 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::WebService::Update;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::GenericInterface::Webservice',
|
||||
'Kernel::System::Main',
|
||||
'Kernel::System::YAML',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Update an existing web service.');
|
||||
$Self->AddOption(
|
||||
Name => 'webservice-id',
|
||||
Description => "The ID of an existing web service.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/\A\d+\z/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'source-path',
|
||||
Description => "Specify the location of the web service YAML configuration file.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $SourcePath = $Self->GetOption('source-path');
|
||||
if ( !-r $SourcePath ) {
|
||||
die "Source file $SourcePath does not exist / is not readable.\n";
|
||||
}
|
||||
|
||||
my $WebServiceList = $Kernel::OM->Get('Kernel::System::GenericInterface::Webservice')->WebserviceList();
|
||||
|
||||
my $WebServiceID = $Self->GetOption('webservice-id');
|
||||
if ( !$WebServiceList->{$WebServiceID} ) {
|
||||
die "A web service with the ID $WebServiceID does not exists in this system.\n";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Updating web service...</yellow>\n");
|
||||
|
||||
# read config
|
||||
my $Content = $Kernel::OM->Get('Kernel::System::Main')->FileRead(
|
||||
Location => $Self->GetOption('source-path'),
|
||||
);
|
||||
if ( !$Content ) {
|
||||
$Self->PrintError('Could not read YAML source.');
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
my $Config = $Kernel::OM->Get('Kernel::System::YAML')->Load( Data => ${$Content} );
|
||||
|
||||
if ( !$Config ) {
|
||||
$Self->PrintError('Could not parse YAML source.');
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
# get current web service
|
||||
my $WebServiceID = $Self->GetOption('webservice-id');
|
||||
|
||||
my $WebService =
|
||||
$Kernel::OM->Get('Kernel::System::GenericInterface::Webservice')->WebserviceGet(
|
||||
ID => $WebServiceID,
|
||||
);
|
||||
|
||||
if ( !$WebService ) {
|
||||
$Self->PrintError("Could not get a web service with the ID $WebServiceID from the database!");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
# update web service
|
||||
my $Success = $Kernel::OM->Get('Kernel::System::GenericInterface::Webservice')->WebserviceUpdate(
|
||||
ID => $WebService->{ID},
|
||||
Name => $WebService->{Name},
|
||||
Config => $Config,
|
||||
ValidID => 1,
|
||||
UserID => 1,
|
||||
);
|
||||
if ( !$Success ) {
|
||||
$Self->PrintError('Could not update web service!');
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user