"Fossies" - the Fresh Open Source Software Archive

Member "otrs-5.0.40/Kernel/System/Console/Command/Admin/SystemAddress/Add.pm" (12 Dec 2019, 2946 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 and the last Fossies "Diffs" side-by-side code changes report: rel-6_0_25_vs_rel-6_0_26.

    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::SystemAddress::Add;
   10 
   11 use strict;
   12 use warnings;
   13 
   14 use base qw(Kernel::System::Console::BaseCommand);
   15 
   16 our @ObjectDependencies = (
   17     'Kernel::System::Queue',
   18     'Kernel::System::SystemAddress',
   19 );
   20 
   21 sub Configure {
   22     my ( $Self, %Param ) = @_;
   23 
   24     $Self->Description('Add new system address.');
   25     $Self->AddOption(
   26         Name        => 'name',
   27         Description => "Display name of the new system address.",
   28         Required    => 1,
   29         HasValue    => 1,
   30         ValueRegex  => qr/.*/smx,
   31     );
   32     $Self->AddOption(
   33         Name        => 'email-address',
   34         Description => "Email address which should be used for the new system address.",
   35         Required    => 1,
   36         HasValue    => 1,
   37         ValueRegex  => qr/.*/smx,
   38     );
   39     $Self->AddOption(
   40         Name        => 'queue-name',
   41         Description => "Queue name the address should be linked to.",
   42         Required    => 1,
   43         HasValue    => 1,
   44         ValueRegex  => qr/.*/smx,
   45     );
   46     $Self->AddOption(
   47         Name        => 'comment',
   48         Description => "Comment for the new system address.",
   49         Required    => 0,
   50         HasValue    => 1,
   51         ValueRegex  => qr/.*/smx,
   52     );
   53 
   54     return;
   55 }
   56 
   57 sub PreRun {
   58     my ( $Self, %Param ) = @_;
   59 
   60     # check if queue already exists
   61     $Self->{QueueName} = $Self->GetOption('queue-name');
   62     $Self->{QueueID}   = $Kernel::OM->Get('Kernel::System::Queue')->QueueLookup(
   63         Queue => $Self->{QueueName},
   64     );
   65     if ( !$Self->{QueueID} ) {
   66         die "Queue $Self->{QueueName} does not exist.\n";
   67     }
   68 
   69     # check if system address already exists
   70     $Self->{EmailAddress} = $Self->GetOption('email-address');
   71     my $SystemExists = $Kernel::OM->Get('Kernel::System::SystemAddress')->SystemAddressIsLocalAddress(
   72         Address => $Self->{EmailAddress},
   73     );
   74     if ($SystemExists) {
   75         die "SystemAddress $Self->{EmailAddress} already exists.\n";
   76     }
   77 
   78     return;
   79 }
   80 
   81 sub Run {
   82     my ( $Self, %Param ) = @_;
   83 
   84     $Self->Print("<yellow>Adding a new system address...</yellow>\n");
   85 
   86     # add system address
   87     if (
   88         !$Kernel::OM->Get('Kernel::System::SystemAddress')->SystemAddressAdd(
   89             UserID   => 1,
   90             ValidID  => 1,
   91             Comment  => $Self->GetOption('comment'),
   92             Realname => $Self->GetOption('name'),
   93             QueueID  => $Self->{QueueID},
   94             Name     => $Self->{EmailAddress},
   95         )
   96         )
   97     {
   98         $Self->PrintError("Can't add system address.");
   99         return $Self->ExitCodeError();
  100     }
  101 
  102     $Self->Print("<green>Done.</green>\n");
  103     return $Self->ExitCodeOk();
  104 }
  105 
  106 1;