From 5e5a625ea49d0f693631113db8224b355bb7c367 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 20 Oct 2020 14:40:50 -0300 Subject: [PATCH] Bug 26751: Fix fatal exception if only one repo defined This patch fixes this nasty problem with how XML is parsed: if more than one entry is found, repo => [] is generated. If only one, repo => {}. To test: 1. Have more than one entries in the plugins_repo entry: ByWater Solutions bywatersolutions github Theke Solutions thekesolutions github PTFS Europe ptfs-europe github 2. Search for plugins => SUCCESS: Searching works! 3. Leave only one entry 4. Restart all to refresh things 5. Try searching for plugins => FAIL: Fatal error 6. Apply this patch 7. Repeat 5 => SUCCESS: It doesn't explode anymore! 8. Sign off :-D Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall https://bugs.koha-community.org/show_bug.cgi?id=12446 --- plugins/plugins-home.pl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/plugins-home.pl b/plugins/plugins-home.pl index 15c538b553..0ef8f289dc 100755 --- a/plugins/plugins-home.pl +++ b/plugins/plugins-home.pl @@ -66,6 +66,12 @@ if ($plugins_enabled) { my @results; if ($plugin_search) { my $repos = C4::Context->config('plugin_repos'); + + # Fix data structure if only one repo defined + if ( ref($repos->{repo}) eq 'HASH' ) { + $repos = { repo => [ $repos->{repo} ] }; + } + foreach my $r ( @{ $repos->{repo} } ) { if ( $r->{service} eq 'github' ) { my $url = "https://api.github.com/search/repositories?q=$plugin_search+user:$r->{org_name}+in:name,description"; -- 2.24.1 (Apple Git-126)