use JSON rather than Storable for the OPAC search history cookie
To test: Exercise the OPAC search history functionality, after turning on the EnableOpacSearchHistory syspref: - Clear the KohaOpacRecentSearches cookie - As an anonymous user, conduct a variety of searches, including ones that include non-ASCII characters - Check the search history and verified that all searches are listed - Log into the OPAC - Verify that current and past searches are listed in search history. Signed-off-by: Galen Charlton <gmc@esilibrary.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com> Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> Signed-off-by: Galen Charlton <gmc@esilibrary.com> (cherry picked from commit a18b097b000428b143ee1647124566cc8a70f2b6) Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
This commit is contained in:
parent
c169ac6882
commit
73fc8f439f
|
|
@ -20,7 +20,7 @@ package C4::Auth;
|
|||
use strict;
|
||||
#use warnings; FIXME - Bug 2505
|
||||
use Digest::MD5 qw(md5_base64);
|
||||
use Storable qw(thaw freeze);
|
||||
use JSON qw/encode_json decode_json/;
|
||||
use URI::Escape;
|
||||
use CGI::Session;
|
||||
|
||||
|
|
@ -268,7 +268,7 @@ sub get_template_and_user {
|
|||
my $searchcookie = $in->{'query'}->cookie('KohaOpacRecentSearches');
|
||||
if ($searchcookie){
|
||||
$searchcookie = uri_unescape($searchcookie);
|
||||
my @recentSearches = @{thaw($searchcookie) || []};
|
||||
my @recentSearches = @{decode_json($searchcookie) || []};
|
||||
if (@recentSearches) {
|
||||
my $sth = $dbh->prepare($SEARCH_HISTORY_INSERT_SQL);
|
||||
$sth->execute( $borrowernumber,
|
||||
|
|
@ -282,7 +282,8 @@ sub get_template_and_user {
|
|||
# And then, delete the cookie's content
|
||||
my $newsearchcookie = $in->{'query'}->cookie(
|
||||
-name => 'KohaOpacRecentSearches',
|
||||
-value => freeze([]),
|
||||
-value => encode_json([]),
|
||||
-HttpOnly => 1,
|
||||
-expires => ''
|
||||
);
|
||||
$cookie = [$cookie, $newsearchcookie];
|
||||
|
|
@ -320,7 +321,7 @@ sub get_template_and_user {
|
|||
my $searchcookie = $in->{'query'}->cookie('KohaOpacRecentSearches');
|
||||
if ($searchcookie){
|
||||
$searchcookie = uri_unescape($searchcookie);
|
||||
my @recentSearches = @{thaw($searchcookie) || []};
|
||||
my @recentSearches = @{decode_json($searchcookie) || []};
|
||||
# We show the link in opac
|
||||
if (@recentSearches) {
|
||||
$template->param(ShowOpacRecentSearchLink => 1);
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ use warnings;
|
|||
|
||||
use C4::Auth qw(:DEFAULT get_session);
|
||||
use CGI;
|
||||
use Storable qw(freeze thaw);
|
||||
use JSON qw/decode_json encode_json/;
|
||||
use C4::Context;
|
||||
use C4::Output;
|
||||
use C4::Log;
|
||||
|
|
@ -55,7 +55,7 @@ if (!$loggedinuser) {
|
|||
# Deleting cookie's content
|
||||
my $recentSearchesCookie = $cgi->cookie(
|
||||
-name => 'KohaOpacRecentSearches',
|
||||
-value => freeze([]),
|
||||
-value => encode_json([]),
|
||||
-expires => ''
|
||||
);
|
||||
|
||||
|
|
@ -69,8 +69,8 @@ if (!$loggedinuser) {
|
|||
|
||||
# Getting the cookie
|
||||
my $searchcookie = $cgi->cookie('KohaOpacRecentSearches');
|
||||
if ($searchcookie && thaw(uri_unescape($searchcookie))) {
|
||||
my @recentSearches = @{thaw(uri_unescape($searchcookie))};
|
||||
if ($searchcookie && decode_json(uri_unescape($searchcookie))) {
|
||||
my @recentSearches = @{decode_json(uri_unescape($searchcookie))};
|
||||
if (@recentSearches) {
|
||||
|
||||
# As the dates are stored as unix timestamps, let's do some formatting
|
||||
|
|
|
|||
|
|
@ -38,8 +38,7 @@ use C4::Tags qw(get_tags);
|
|||
use C4::Branch; # GetBranches
|
||||
use POSIX qw(ceil floor strftime);
|
||||
use URI::Escape;
|
||||
use Storable qw(thaw freeze);
|
||||
|
||||
use JSON qw/decode_json encode_json/;
|
||||
|
||||
my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
|
||||
# create a new CGI object
|
||||
|
|
@ -528,8 +527,8 @@ for (my $i=0;$i<@servers;$i++) {
|
|||
my $searchcookie = $cgi->cookie('KohaOpacRecentSearches');
|
||||
if ($searchcookie){
|
||||
$searchcookie = uri_unescape($searchcookie);
|
||||
if (thaw($searchcookie)) {
|
||||
@recentSearches = @{thaw($searchcookie)};
|
||||
if (decode_json($searchcookie)) {
|
||||
@recentSearches = @{decode_json($searchcookie)};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -538,8 +537,8 @@ for (my $i=0;$i<@servers;$i++) {
|
|||
# To a cookie (the user is not logged in)
|
||||
if (!$offset) {
|
||||
push @recentSearches, {
|
||||
"query_desc" => $query_desc || "unknown",
|
||||
"query_cgi" => $query_cgi || "unknown",
|
||||
"query_desc" => Encode::decode_utf8($query_desc) || "unknown",
|
||||
"query_cgi" => Encode::decode_utf8($query_cgi) || "unknown",
|
||||
"time" => time(),
|
||||
"total" => $total
|
||||
};
|
||||
|
|
@ -550,8 +549,8 @@ for (my $i=0;$i<@servers;$i++) {
|
|||
# Pushing the cookie back
|
||||
$newsearchcookie = $cgi->cookie(
|
||||
-name => 'KohaOpacRecentSearches',
|
||||
# We uri_escape the whole freezed structure so we're sure we won't have any encoding problems
|
||||
-value => uri_escape(freeze(\@recentSearches)),
|
||||
# We uri_escape the whole serialized structure so we're sure we won't have any encoding problems
|
||||
-value => uri_escape( encode_json(\@recentSearches) ),
|
||||
-expires => ''
|
||||
);
|
||||
$cookie = [$cookie, $newsearchcookie];
|
||||
|
|
|
|||
Loading…
Reference in New Issue