1# -- 2# Copyright (C) 2001-2020 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 9package Kernel::System::Console::Command::Admin::Package::Uninstall; 10 11use strict; 12use warnings; 13 14use parent qw(Kernel::System::Console::BaseCommand Kernel::System::Console::Command::Admin::Package::List); 15 16our @ObjectDependencies = ( 17 'Kernel::System::Cache', 18 'Kernel::System::Package', 19); 20 21sub Configure { 22 my ( $Self, %Param ) = @_; 23 24 $Self->Description('Uninstall an OTRS package.'); 25 $Self->AddOption( 26 Name => 'force', 27 Description => 'Force package uninstallation even if validation fails.', 28 Required => 0, 29 HasValue => 0, 30 ); 31 $Self->AddArgument( 32 Name => 'location', 33 Description => 34 "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).", 35 Required => 1, 36 ValueRegex => qr/.*/smx, 37 ); 38 39 return; 40} 41 42sub Run { 43 my ( $Self, %Param ) = @_; 44 45 $Self->Print("<yellow>Uninstalling package...</yellow>\n"); 46 47 my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache'); 48 49 # Enable in-memory cache to improve SysConfig performance, which is normally disabled for commands. 50 $CacheObject->Configure( 51 CacheInMemory => 1, 52 ); 53 54 my $FileString = $Self->_PackageContentGet( Location => $Self->GetArgument('location') ); 55 return $Self->ExitCodeError() if !$FileString; 56 57 # get package file from db 58 # parse package 59 my %Structure = $Kernel::OM->Get('Kernel::System::Package')->PackageParse( 60 String => $FileString, 61 ); 62 63 # just un-install it if PackageIsRemovable flag is enable 64 if ( 65 defined $Structure{PackageIsRemovable} 66 && !$Structure{PackageIsRemovable}->{Content} 67 ) 68 { 69 my $Error = "Not possible to remove this package!\n"; 70 71 # exchange message if package should not be visible 72 if ( 73 defined $Structure{PackageIsVisible} 74 && !$Structure{PackageIsVisible}->{Content} 75 ) 76 { 77 $Error = "No such package!\n"; 78 } 79 $Self->PrintError($Error); 80 return $Self->ExitCodeError(); 81 } 82 83 # intro screen 84 if ( $Structure{IntroUninstall} ) { 85 my %Data = $Self->_PackageMetadataGet( 86 Tag => $Structure{IntroUninstall}, 87 AttributeFilterKey => 'Type', 88 AttributeFilterValue => 'pre', 89 ); 90 if ( $Data{Description} ) { 91 print "+----------------------------------------------------------------------------+\n"; 92 print "| $Structure{Name}->{Content}-$Structure{Version}->{Content}\n"; 93 print "$Data{Title}"; 94 print "$Data{Description}"; 95 print "+----------------------------------------------------------------------------+\n"; 96 } 97 } 98 99 # Uninstall 100 my $Success = $Kernel::OM->Get('Kernel::System::Package')->PackageUninstall( 101 String => $FileString, 102 Force => $Self->GetOption('force'), 103 ); 104 105 if ( !$Success ) { 106 $Self->PrintError("Package uninstallation failed."); 107 return $Self->ExitCodeError(); 108 } 109 110 # intro screen 111 if ( $Structure{IntroUninstallPost} ) { 112 my %Data = $Self->_PackageMetadataGet( 113 Tag => $Structure{IntroUninstall}, 114 AttributeFilterKey => 'Type', 115 AttributeFilterValue => 'post', 116 ); 117 if ( $Data{Description} ) { 118 print "+----------------------------------------------------------------------------+\n"; 119 print "| $Structure{Name}->{Content}-$Structure{Version}->{Content}\n"; 120 print "$Data{Title}"; 121 print "$Data{Description}"; 122 print "+----------------------------------------------------------------------------+\n"; 123 } 124 } 125 126 # Disable in memory cache. 127 $CacheObject->Configure( 128 CacheInMemory => 0, 129 ); 130 131 $Self->Print("<green>Done.</green>\n"); 132 return $Self->ExitCodeOk(); 133} 134 1351; 136