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::FileSearch; 10 11use strict; 12use warnings; 13 14use parent qw(Kernel::System::Console::BaseCommand); 15 16our @ObjectDependencies = ( 17 'Kernel::System::Package', 18); 19 20sub Configure { 21 my ( $Self, %Param ) = @_; 22 23 $Self->Description('Find a file in an installed OTRS package.'); 24 $Self->AddArgument( 25 Name => 'search-path', 26 Description => "Filename or path to search for.", 27 Required => 1, 28 ValueRegex => qr/.*/smx, 29 ); 30 31 return; 32} 33 34sub Run { 35 my ( $Self, %Param ) = @_; 36 37 $Self->Print("<yellow>Searching in installed OTRS packages...</yellow>\n"); 38 39 my $Hit = 0; 40 my $Filepath = $Self->GetArgument('search-path'); 41 42 PACKAGE: 43 for my $Package ( $Kernel::OM->Get('Kernel::System::Package')->RepositoryList() ) { 44 45 # Just show if PackageIsVisible flag is enabled. 46 if ( 47 defined $Package->{PackageIsVisible} 48 && !$Package->{PackageIsVisible}->{Content} 49 ) 50 { 51 next PACKAGE; 52 } 53 for my $File ( @{ $Package->{Filelist} } ) { 54 if ( $File->{Location} =~ m{\Q$Filepath\E}smx ) { 55 print 56 "+----------------------------------------------------------------------------+\n"; 57 print "| File: $File->{Location}\n"; 58 print "| Name: $Package->{Name}->{Content}\n"; 59 print "| Version: $Package->{Version}->{Content}\n"; 60 print "| Vendor: $Package->{Vendor}->{Content}\n"; 61 print "| URL: $Package->{URL}->{Content}\n"; 62 print "| License: $Package->{License}->{Content}\n"; 63 print 64 "+----------------------------------------------------------------------------+\n"; 65 $Hit++; 66 } 67 } 68 } 69 if ($Hit) { 70 $Self->Print("<green>Done.</green>\n"); 71 return $Self->ExitCodeOk(); 72 } 73 74 $Self->PrintError("File $Filepath was not found in an installed OTRS package.\n"); 75 return $Self->ExitCodeError(); 76} 77 781; 79