Bug 28167: Remove uninitialized variable warnings from circ/set-library.pl
authorJoonas Kylmälä <joonas.kylmala@iki.fi>
Mon, 29 Aug 2022 20:39:13 +0000 (20:39 +0000)
committerArthur Suzuki <arthur.suzuki@biblibre.com>
Mon, 14 Nov 2022 16:48:03 +0000 (17:48 +0100)
With UseCashRegisters syspref disabled going to the page
/cgi-bin/koha/circ/set-library.pl in staff interface and setting a
library gives the following errors in plack-intranet-error.log:

Use of uninitialized value $register_id in string ne at /kohadevbox/koha/circ/set-library.pl line 79.
Use of uninitialized value $referer in pattern match (m//) at /kohadevbox/koha/circ/set-library.pl line 114.

In the if clause $userenv_register_id appears to be typoed, it should have
been $register_id as $userenv_register_id is always defined. As for the
$referer variable, it is undef if there is no referer so let's just initialize
it to an empty string for the regex so it doesn't give the warning.

To test:
 1) Go directly to /cgi-bin/koha/circ/set-library.pl by typing it in
    the URL bar and set a library
 2) Make sure plack-intranet-error.log doesn't contain the above mentioned errors
    after applying this patch

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit 8e25fa1dc5267f6fb6148412f0774c6880a2e7c3)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 513b1160bcfef9ff6b482b96c0607f3e61ad961d)
Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com>
circ/set-library.pl

index b03759b..9d2823d 100755 (executable)
@@ -76,7 +76,7 @@ if ( $branch and my $library = Koha::Libraries->find($branch) ) {
             old_desk => $old_desk_name,
         };
     }
-    if ( defined($userenv_register_id)
+    if ( defined($register_id)
         && ( $userenv_register_id ne $register_id ) )
     {
         my $old_register_name = C4::Context->userenv->{'register_name'} || '';
@@ -110,7 +110,7 @@ foreach ($query->param()) {
       };
 }
 
-my $referer =  $query->param('oldreferer') || $ENV{HTTP_REFERER};
+my $referer =  $query->param('oldreferer') || $ENV{HTTP_REFERER} || '';
 $referer =~ /set-library\.pl/ and undef $referer;   # avoid sending them back to this same page.
 
 if (scalar @updated and not scalar @recycle_loop) {