"Fossies" - the Fresh Open Source Software Archive

Member "otrs-5.0.40/Kernel/System/Console/Command/Admin/Service/Add.pm" (12 Dec 2019, 2913 Bytes) of package /linux/www/otrs-5.0.40.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Add.pm" see the Fossies "Dox" file reference documentation.

    1 # --
    2 # Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
    3 # --
    4 # This software comes with ABSOLUTELY NO WARRANTY. For details, see
    5 # the enclosed file COPYING for license information (GPL). If you
    6 # did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
    7 # --
    8 
    9 package Kernel::System::Console::Command::Admin::Service::Add;
   10 
   11 use strict;
   12 use warnings;
   13 
   14 use base qw(Kernel::System::Console::BaseCommand);
   15 
   16 our @ObjectDependencies = (
   17     'Kernel::System::Service',
   18 );
   19 
   20 sub Configure {
   21     my ( $Self, %Param ) = @_;
   22 
   23     $Self->Description('Add new service.');
   24     $Self->AddOption(
   25         Name        => 'name',
   26         Description => "Name of the new service.",
   27         Required    => 1,
   28         HasValue    => 1,
   29         ValueRegex  => qr/.*/smx,
   30     );
   31     $Self->AddOption(
   32         Name        => 'parent-name',
   33         Description => "Parent service name. If given, the new service will be a subservice of the given parent.",
   34         Required    => 0,
   35         HasValue    => 1,
   36         ValueRegex  => qr/.*/smx,
   37     );
   38     $Self->AddOption(
   39         Name        => 'comment',
   40         Description => "Comment for the new service.",
   41         Required    => 0,
   42         HasValue    => 1,
   43         ValueRegex  => qr/.*/smx,
   44     );
   45 
   46     return;
   47 }
   48 
   49 sub PreRun {
   50     my ( $Self, %Param ) = @_;
   51 
   52     # Get all services.
   53     $Self->{Name} = $Self->GetOption('name');
   54     my %ServiceList = $Kernel::OM->Get('Kernel::System::Service')->ServiceList(
   55         Valid  => 0,
   56         UserID => 1,
   57     );
   58     my %Reverse = reverse %ServiceList;
   59 
   60     $Self->{ParentName} = $Self->GetOption('parent-name');
   61     if ( $Self->{ParentName} ) {
   62 
   63         # Check if Parent service exists.
   64         $Self->{ParentID} = $Kernel::OM->Get('Kernel::System::Service')->ServiceLookup(
   65             Name   => $Self->{ParentName},
   66             UserID => 1,
   67         );
   68         die "Parent service $Self->{ParentName} does not exist.\n" if !$Self->{ParentID};
   69 
   70         # Check if Parent::Child service combination exists.
   71         my $ServiceName = $Self->{ParentName} . '::' . $Self->{Name};
   72         die "Service '$ServiceName' already exists!\n" if $Reverse{$ServiceName};
   73     }
   74     else {
   75 
   76         # Check if service already exists.
   77         die "Service '$Self->{Name}' already exists!\n" if $Reverse{ $Self->{Name} };
   78     }
   79 
   80     return;
   81 }
   82 
   83 sub Run {
   84     my ( $Self, %Param ) = @_;
   85 
   86     $Self->Print("<yellow>Adding a new service...</yellow>\n");
   87 
   88     # add service
   89     if (
   90         !$Kernel::OM->Get('Kernel::System::Service')->ServiceAdd(
   91             UserID   => 1,
   92             ValidID  => 1,
   93             Name     => $Self->{Name},
   94             Comment  => $Self->GetOption('comment'),
   95             ParentID => $Self->{ParentID},
   96         )
   97         )
   98     {
   99         $Self->PrintError("Can't add service.");
  100         return $Self->ExitCodeError();
  101     }
  102 
  103     $Self->Print("<green>Done.</green>\n");
  104     return $Self->ExitCodeOk();
  105 }
  106 
  107 1;