Bugzilla – Attachment 4798 Details for
Bug 5981
OPAC: Add limits to search history
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
proposed patch for T::TT + fix for missing bracket
0001-Bug-5981-MT-4231-Adds-limits-to-search-history.patch (text/plain), 17.03 KB, created by
Paul Poulain
on 2011-08-01 16:17:43 UTC
(
hide
)
Description:
proposed patch for T::TT + fix for missing bracket
Filename:
MIME Type:
Creator:
Paul Poulain
Created:
2011-08-01 16:17:43 UTC
Size:
17.03 KB
patch
obsolete
>From 2d20e787f8da76f62379d3f8cb0b9006e15c407b Mon Sep 17 00:00:00 2001 >From: Matthias Meusburger <matthias.meusburger@biblibre.com> >Date: Fri, 6 Aug 2010 17:18:40 +0200 >Subject: [PATCH] Bug 5981 : MT 4231: Adds limits to search history > >--- > C4/Auth.pm | 11 ++- > C4/Search.pm | 48 +++++++++-- > installer/data/mysql/kohastructure.sql | 2 + > installer/data/mysql/updatedatabase.pl | 10 ++ > .../prog/en/modules/opac-search-history.tt | 5 +- > kohaversion.pl | 2 +- > opac/opac-search-history.pl | 44 +++++----- > opac/opac-search.pl | 90 ++++++++++++++++++- > 8 files changed, 172 insertions(+), 40 deletions(-) > >diff --git a/C4/Auth.pm b/C4/Auth.pm >index f580e53..eb73b01 100644 >--- a/C4/Auth.pm >+++ b/C4/Auth.pm >@@ -130,8 +130,8 @@ Output.pm module. > =cut > > my $SEARCH_HISTORY_INSERT_SQL =<<EOQ; >-INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, total, time ) >-VALUES ( ?, ?, ?, ?, ?, FROM_UNIXTIME(?)) >+INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, limit_desc, limit_cgi, total, time ) >+VALUES ( ?, ?, ?, ?, ?, ?, ?, FROM_UNIXTIME(?)) > EOQ > sub get_template_and_user { > my $in = shift; >@@ -368,6 +368,7 @@ sub get_template_and_user { > IntranetmainUserblock => C4::Context->preference("IntranetmainUserblock"), > LibraryName => C4::Context->preference("LibraryName"), > LoginBranchname => (C4::Context->userenv?C4::Context->userenv->{"branchname"}:"insecure"), >+ TemplateEncoding => C4::Context->preference("TemplateEncoding"), > advancedMARCEditor => C4::Context->preference("advancedMARCEditor"), > canreservefromotherbranches => C4::Context->preference('canreservefromotherbranches'), > intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), >@@ -381,9 +382,10 @@ sub get_template_and_user { > virtualshelves => C4::Context->preference("virtualshelves"), > StaffSerialIssueDisplayCount => C4::Context->preference("StaffSerialIssueDisplayCount"), > NoZebra => C4::Context->preference('NoZebra'), >+ IntranetXSLTDetailsDisplay => C4::Context->preference("IntranetXSLTDetailsDisplay"), >+ IntranetXSLTResultsDisplay => C4::Context->preference("IntranetXSLTResultsDisplay"), > ); >- } >- else { >+ } else { > warn "template type should be OPAC, here it is=[" . $in->{'type'} . "]" unless ( $in->{'type'} eq 'opac' ); > #TODO : replace LibraryName syspref with 'system name', and remove this html processing > my $LibraryNameTitle = C4::Context->preference("LibraryName"); >@@ -442,6 +444,7 @@ sub get_template_and_user { > OPACFinesTab => C4::Context->preference("OPACFinesTab"), > OpacTopissue => C4::Context->preference("OpacTopissue"), > RequestOnOpac => C4::Context->preference("RequestOnOpac"), >+ TemplateEncoding => "" . C4::Context->preference("TemplateEncoding"), > 'Version' => C4::Context->preference('Version'), > hidelostitems => C4::Context->preference("hidelostitems"), > mylibraryfirst => (C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv) ? C4::Context->userenv->{'branch'} : '', >diff --git a/C4/Search.pm b/C4/Search.pm >index c3cff65..49e03fa 100644 >--- a/C4/Search.pm >+++ b/C4/Search.pm >@@ -1238,6 +1238,11 @@ sub buildQuery { > $truncated_operand .= $index_plus_comma . "rltrn:@$rightlefttruncated "; > $previous_truncation_operand = 1; > } >+ if ( scalar @$regexpr ) { >+ $truncated_operand .= "and " if $previous_truncation_operand; >+ $truncated_operand .= $index_plus_comma . "regExpr-1:@$regexpr "; >+ $previous_truncation_operand = 1; >+ } > } > $operand = $truncated_operand if $truncated_operand; > warn "TRUNCATED OPERAND: >$truncated_operand<" if $DEBUG; >@@ -2534,15 +2539,46 @@ sub enabled_staff_search_views > ); > } > >-sub AddSearchHistory{ >- my ($borrowernumber,$session,$query_desc,$query_cgi, $total)=@_; >+=head2 enabled_opac_search_views >+ >+%hash = enabled_opac_search_views() >+ >+This function returns a hash that contains two flags obtained from the system >+preferences, used to determine whether a particular opac search results view >+is enabled. >+ >+=over 2 >+ >+=item C<Output arg:> >+ >+ * $hash{can_view_MARC} is true only if the MARC view is enabled >+ * $hash{can_view_ISBD} is true only if the ISBD view is enabled >+ >+=item C<usage in the script:> >+ >+=back >+ >+$template->param ( C4::Search::enabled_opac_search_views ); >+ >+=cut >+ >+sub enabled_opac_search_views >+{ >+ return ( >+ can_opac_view_MARC => C4::Context->preference('OPACviewMARC'), # 1 if the opac search allows the MARC view >+ can_opac_view_ISBD => C4::Context->preference('OPACviewISBD'), # 1 if the opac search allows the ISBD view >+ ); >+} >+ >+sub AddSearchHistory { >+ my ( $borrowernumber, $session, $query_desc, $query_cgi, $limit_desc, $limit_cgi, $total ) = @_; > my $dbh = C4::Context->dbh; > > # Add the request the user just made >- my $sql = "INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, total, time) VALUES(?, ?, ?, ?, ?, NOW())"; >- my $sth = $dbh->prepare($sql); >- $sth->execute($borrowernumber, $session, $query_desc, $query_cgi, $total); >- return $dbh->last_insert_id(undef, 'search_history', undef,undef,undef); >+ my $sql = "INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, limit_desc, limit_cgi, total, time) VALUES(?, ?, ?, ?, ?, ?, ?, NOW())"; >+ my $sth = $dbh->prepare($sql); >+ $sth->execute( $borrowernumber, $session, $query_desc, $query_cgi, $limit_desc, $limit_cgi, $total ); >+ return $dbh->last_insert_id( undef, 'search_history', undef, undef, undef ); > } > > sub GetSearchHistory{ >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index e3c6f42..8929419 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -1633,6 +1633,8 @@ CREATE TABLE IF NOT EXISTS `search_history` ( > `sessionid` varchar(32) NOT NULL, > `query_desc` varchar(255) NOT NULL, > `query_cgi` varchar(255) NOT NULL, >+ `limit_desc` varchar(255) DEFAULT NULL, >+ `limit_cgi` varchar(255) DEFAULT NULL, > `total` int(11) NOT NULL, > `time` timestamp NOT NULL default CURRENT_TIMESTAMP, > KEY `userid` (`userid`), >diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl >index 9cbc8db..8b36416 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/installer/data/mysql/updatedatabase.pl >@@ -4369,6 +4369,16 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { > print "Upgrade to $DBversion done (Add syspref ShowReviewerPhoto)\n"; > SetVersion($DBversion); > } >+$DBversion = "3.05.00.005"; >+if (C4::Context->preference("Version") < TransformToNum($DBversion)) { >+ $dbh->do(q{ >+ ALTER TABLE `search_history` ADD `limit_desc` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `query_cgi` , >+ ADD `limit_cgi` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `limit_desc` >+ }); >+ print "Upgrade to $DBversion done (adding limits to the opac search history)\n"; >+ SetVersion ($DBversion); >+} >+ > > =head1 FUNCTIONS > >diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-search-history.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-search-history.tt >index e9f6be1..6de4756 100644 >--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-search-history.tt >+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-search-history.tt >@@ -47,7 +47,8 @@ > [% FOREACH recentSearche IN recentSearches %] > <tr> > <td>[% recentSearche.time %]</td> >- <td><a href="/cgi-bin/koha/opac-search.pl?[% recentSearche.query_cgi |html %]">[% recentSearche.query_desc |html %]</a></td> >+ <td><a href="/cgi-bin/koha/opac-search.pl?[% recentSearche.query_cgi |html %][% recentSearche.limit_cgi|html %]">[% recentSearche.query_desc|html %] [% recentSearche.limit_desc|html %]</a></td> >+ > <td>[% recentSearche.total %]</td> > </tr> > [% END %] >@@ -65,7 +66,7 @@ > [% FOREACH previousSearche IN previousSearches %] > <tr> > <td>[% previousSearche.time %]</td> >- <td><a href="/cgi-bin/koha/opac-search.pl?[% previousSearche.query_cgi |html %]">[% previousSearche.query_desc |html %]</a></td> >+ <td><a href="/cgi-bin/koha/opac-search.pl?[% previousSearche.query_cgi |html %][% previousSearche.limit_cgi|html %]">[% previousSearche.query_desc|html %] [% previousSearche.limit_desc|html %]</a></td> > <td>[% previousSearche.total %]</td> > </tr> > [% END %] >diff --git a/kohaversion.pl b/kohaversion.pl >index 00bdbec..9021eb0 100644 >--- a/kohaversion.pl >+++ b/kohaversion.pl >@@ -16,7 +16,7 @@ the kohaversion is divided in 4 parts : > use strict; > > sub kohaversion { >- our $VERSION = '3.05.00.004'; >+ our $VERSION = '3.05.00.005'; > # version needs to be set this way > # so that it can be picked up by Makefile.PL > # during install >diff --git a/opac/opac-search-history.pl b/opac/opac-search-history.pl >index 65141b9..d52e57d 100755 >--- a/opac/opac-search-history.pl >+++ b/opac/opac-search-history.pl >@@ -113,28 +113,28 @@ if (!$loggedinuser) { > # Showing search history > } else { > >- my $date = C4::Dates->new(); >- my $dateformat = $date->DHTMLcalendar() . " %H:%i:%S"; # Current syspref date format + standard time format >- >- # Getting the data with date format work done by mysql >- my $query = "SELECT userid, sessionid, query_desc, query_cgi, total, DATE_FORMAT(time, \"$dateformat\") as time FROM search_history WHERE userid = ? AND sessionid = ?"; >- my $sth = $dbh->prepare($query); >- $sth->execute($loggedinuser, $cgi->cookie("CGISESSID")); >- my $searches = $sth->fetchall_arrayref({}); >- $template->param(recentSearches => $searches); >- >- # Getting searches from previous sessions >- $query = "SELECT COUNT(*) FROM search_history WHERE userid = ? AND sessionid != ?"; >- $sth = $dbh->prepare($query); >- $sth->execute($loggedinuser, $cgi->cookie("CGISESSID")); >- >- # If at least one search from previous sessions has been performed >- if ($sth->fetchrow_array > 0) { >- $query = "SELECT userid, sessionid, query_desc, query_cgi, total, DATE_FORMAT(time, \"$dateformat\") as time FROM search_history WHERE userid = ? AND sessionid != ?"; >- $sth = $dbh->prepare($query); >- $sth->execute($loggedinuser, $cgi->cookie("CGISESSID")); >- my $previoussearches = $sth->fetchall_arrayref({}); >- $template->param(previousSearches => $previoussearches); >+ my $date = C4::Dates->new(); >+ my $dateformat = $date->DHTMLcalendar() . " %H:%i:%S"; # Current syspref date format + standard time format >+ >+ # Getting the data with date format work done by mysql >+ my $query = "SELECT userid, sessionid, query_desc, query_cgi, limit_desc, limit_cgi, total, DATE_FORMAT(time, \"$dateformat\") as time FROM search_history WHERE userid = ? AND sessionid = ?"; >+ my $sth = $dbh->prepare($query); >+ $sth->execute( $loggedinuser, $cgi->cookie("CGISESSID") ); >+ my $searches = $sth->fetchall_arrayref( {} ); >+ $template->param( recentSearches => $searches ); >+ >+ # Getting searches from previous sessions >+ $query = "SELECT COUNT(*) FROM search_history WHERE userid = ? AND sessionid != ?"; >+ $sth = $dbh->prepare($query); >+ $sth->execute( $loggedinuser, $cgi->cookie("CGISESSID") ); >+ >+ # If at least one search from previous sessions has been performed >+ if ( $sth->fetchrow_array > 0 ) { >+ $query = "SELECT userid, sessionid, query_desc, query_cgi, limit_desc, limit_cgi, total, DATE_FORMAT(time, \"$dateformat\") as time FROM search_history WHERE userid = ? AND sessionid != ?"; >+ $sth = $dbh->prepare($query); >+ $sth->execute( $loggedinuser, $cgi->cookie("CGISESSID") ); >+ my $previoussearches = $sth->fetchall_arrayref( {} ); >+ $template->param( previousSearches => $previoussearches ); > > } > >diff --git a/opac/opac-search.pl b/opac/opac-search.pl >index cd34610..3a16159 100755 >--- a/opac/opac-search.pl >+++ b/opac/opac-search.pl >@@ -538,11 +538,91 @@ for (my $i=0;$i<@servers;$i++) { > } > } > } >- ## If there's just one result, redirect to the detail page >- if ($total == 1 && $format ne 'rss2' >- && $format ne 'opensearchdescription' && $format ne 'atom') { >- my $biblionumber=$newresults[0]->{biblionumber}; >- if (C4::Context->preference('BiblioDefaultView') eq 'isbd') { >+ my $tag_quantity; >+ if ( C4::Context->preference('TagsEnabled') >+ and $tag_quantity = C4::Context->preference('TagsShowOnList') ) { >+ foreach (@newresults) { >+ my $bibnum = $_->{biblionumber} or next; >+ $_->{itemsissued} = CountItemsIssued($bibnum); >+ $_->{'TagLoop'} = get_tags( >+ { biblionumber => $bibnum, >+ approved => 1, >+ 'sort' => '-weight', >+ limit => $tag_quantity >+ } >+ ); >+ } >+ } >+ foreach (@newresults) { >+ $_->{coins} = GetCOinSBiblio( $_->{'biblionumber'} ); >+ } >+ >+ if ( $results_hashref->{$server}->{"hits"} ) { >+ $total = $total + $results_hashref->{$server}->{"hits"}; >+ } >+ >+ # Opac search history >+ my $newsearchcookie; >+ if ( C4::Context->preference('EnableOpacSearchHistory') ) { >+ my @recentSearches; >+ >+ # Getting the (maybe) already sent cookie >+ my $searchcookie = $cgi->cookie('KohaOpacRecentSearches'); >+ if ($searchcookie) { >+ $searchcookie = uri_unescape($searchcookie); >+ if ( thaw($searchcookie) ) { >+ @recentSearches = @{ thaw($searchcookie) }; >+ } >+ } >+ >+ # Adding the new search if needed >+ if ( not defined $borrowernumber or $borrowernumber eq '' ) { >+ >+ # To a cookie (the user is not logged in) >+ >+ if ( not defined $params->{'offset'} or $params->{'offset'} eq '' ) { >+ push @recentSearches, >+ { "query_desc" => $query_desc || "unknown", >+ "query_cgi" => $query_cgi || "unknown", >+ "limit_desc" => $limit_desc, >+ "limit_cgi" => $limit_cgi, >+ "time" => time(), >+ "total" => $total >+ }; >+ $template->param( ShowOpacRecentSearchLink => 1 ); >+ } >+ >+ # Only the 15 more recent searches are kept >+ # TODO: This has been done because of cookies' max size, which is >+ # usually 4KB. A real check on cookie actual size would be better >+ # than setting an arbitrary limit on the number of searches >+ shift @recentSearches if (@recentSearches > 15); >+ >+ # 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 ) ), >+ -expires => '' >+ ); >+ $cookie = [ $cookie, $newsearchcookie ]; >+ } else { >+ >+ # To the session (the user is logged in) >+ if ( not defined $params->{'offset'} or $params->{'offset'} eq '' ) { >+ AddSearchHistory( $borrowernumber, $cgi->cookie("CGISESSID"), $query_desc, $query_cgi, $limit_desc, $limit_cgi, $total ); >+ $template->param( ShowOpacRecentSearchLink => 1 ); >+ } >+ } >+ } >+ ## If there's just one result, redirect to the detail page >+ if ( $total == 1 >+ && $format ne 'rss2' >+ && $format ne 'opensearchdescription' >+ && $format ne 'atom' ) { >+ my $biblionumber = $newresults[0]->{biblionumber}; >+ if ( C4::Context->preference('BiblioDefaultView') eq 'isbd' ) { > print $cgi->redirect("/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=$biblionumber"); > } elsif (C4::Context->preference('BiblioDefaultView') eq 'marc') { > print $cgi->redirect("/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=$biblionumber"); >-- >1.7.4.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 5981
:
3485
|
3657
|
4798
|
4860
|
5277
|
5422
|
5659
|
10087
|
10316
|
10632