Bug 34760: Confirm session ID is set to save OPAC search history to logged in user

This patch confirms that a session ID has been set before trying to save search history to a logged in user on the OPAC.

This depends on EnableOpacSearchHistory system preference being enabled.

Apply the patch and test that you don't see an Error 500 page at any point through this plan:

1. Do an OPAC search, ensure you are not logged in
2. Confirm your search was saved to search history
3. Do another search, then log in
4. Confirm you are brought back to the search results after logging in
5. Confirm all search history from the session is visible

Sponsored-by: Toi Ohomai Institute of Technology
Signed-off-by: Salah Ghedda <salah.ghedda@inLibro.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit e7707b768b)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
(cherry picked from commit f11452e2dc)
Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
This commit is contained in:
Aleisha Amohia 2023-09-11 20:47:34 +00:00 committed by Matt Blenkinsop
parent 6de1ded81f
commit 58b17792e4

View file

@ -717,24 +717,29 @@ for (my $i=0;$i<@servers;$i++) {
$query_cgi_history =~ s/;/&/g;
my $query_desc_history = join ", ", grep { defined $_ } $query_desc, $limit_desc;
unless ( $borrowernumber ) {
my $new_searches = C4::Search::History::add_to_session({
cgi => $cgi,
query_desc => $query_desc_history,
query_cgi => $query_cgi_history,
total => $total,
type => "biblio",
});
} else {
if ( $borrowernumber and $cgi->cookie("CGISESSID") ) {
# To the session (the user is logged in)
C4::Search::History::add({
userid => $borrowernumber,
sessionid => $cgi->cookie("CGISESSID"),
query_desc => $query_desc_history,
query_cgi => $query_cgi_history,
total => $total,
type => "biblio",
});
C4::Search::History::add(
{
userid => $borrowernumber,
sessionid => $cgi->cookie("CGISESSID"),
query_desc => $query_desc_history,
query_cgi => $query_cgi_history,
total => $total,
type => "biblio",
}
);
} else {
my $new_searches = C4::Search::History::add_to_session(
{
cgi => $cgi,
query_desc => $query_desc_history,
query_cgi => $query_cgi_history,
total => $total,
type => "biblio",
}
);
}
}
$template->param( EnableOpacSearchHistory => 1 );