Bug 8198 - Need to track the call to "C4::Context->userenv->{'xxxx'} without check if it is undefined
Summary: Need to track the call to "C4::Context->userenv->{'xxxx'} without check if it...
Status: NEW
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: Main
Hardware: All All
: P5 - low minor (vote)
Assignee: Christophe Croullebois
QA Contact:
URL:
Keywords:
Depends on: 9980 10217
Blocks:
  Show dependency treegraph
 
Reported: 2012-06-06 14:13 UTC by Christophe Croullebois
Modified: 2020-07-21 20:52 UTC (History)
4 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christophe Croullebois 2012-06-06 14:13:36 UTC
linked with bug 8197, all the lines like that will return a koha error if session cookies have been deleted.
It would be nice to correct all the relevant lines.
Comment 1 David Cook 2012-07-13 01:47:36 UTC
Also linked with Bug 8434.
Comment 2 Jonathan Druart 2015-03-31 15:30:00 UTC
Maybe the following change would do the trick:

diff --git a/C4/Context.pm b/C4/Context.pm
index cc93af4..14ce1c7 100644
--- a/C4/Context.pm
+++ b/C4/Context.pm
@@ -1085,7 +1085,7 @@ sub userenv {
     if (defined $var and defined $context->{"userenv"}->{$var}) {
         return $context->{"userenv"}->{$var};
     } else {
-        return;
+        return {};
     }
 }

Need to be confirmed.
Comment 3 Katrin Fischer 2019-04-28 15:26:37 UTC
Is this still valid?
Comment 4 Jonathan Druart 2019-04-28 23:49:11 UTC
(In reply to Katrin Fischer from comment #3)
> Is this still valid?

Yes, it could be a code cleaning.

So far we have to test if userenv is defined before accessing a key, for instance:
  C4/Accounts.pm:    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;

My fix would still be valid, but we still need a test:
  C4/Accounts.pm:    my $branchcode = exist C4::Context->userenv->{branch} ? C4::Context->userenv->{'branch'} : undef;

which actually makes less sense.

A better approach could be to have a ->logged_in_user method, to retrieve a Koha::Patron object, representing the logged in user. But it is a quite huge work, and nobody will sign it off, and rebases will be tricky ;)

Lowering severity for now.