Bugzilla – Attachment 23714 Details for
Bug 11430
Search history: Delete selected lines
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11430: delete search history by id - API changes
Bug-11430-delete-search-history-by-id---API-change.patch (text/plain), 4.71 KB, created by
Jonathan Druart
on 2013-12-20 15:35:45 UTC
(
hide
)
Description:
Bug 11430: delete search history by id - API changes
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2013-12-20 15:35:45 UTC
Size:
4.71 KB
patch
obsolete
>From 8f2463201981686a9c6a429d3146685533b65a1b Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Fri, 20 Dec 2013 15:06:08 +0100 >Subject: [PATCH] Bug 11430: delete search history by id - API changes > >Bug 10807 adds a search history for authorities and bug 10862 adds the >search history on the staff interface. > >This one allows the user to select the search history lines he wants to >delete. > >This change is done for the OPAC and intranet interface. The user is now >allow to delete one or more lines of his/her search history. > >Test plan (for intranet, opac: bootstrap and prog themes): >1/ launch some search (catalogue and authority) >2/ verify the lines is added to your search history >3/ delete one or more lines of the history and verify they have been >deleted >4/ at the OPAC: logout and do again steps 1-3. >5/ prove t/db_dependent/Search/History.t >--- > C4/Search/History.pm | 74 ++++++++++++++++++++++++++++++++++++++++++++------ > 1 file changed, 66 insertions(+), 8 deletions(-) > >diff --git a/C4/Search/History.pm b/C4/Search/History.pm >index 9dd5eb4..93bc5bf 100644 >--- a/C4/Search/History.pm >+++ b/C4/Search/History.pm >@@ -50,12 +50,15 @@ sub build_new_cookie_value { > } > > # To a cookie (the user is not logged in) >+ my $now = dt_from_string; >+ my $id = $now->year . $now->month . $now->day . $now->hour . $now->minute . $now->second . int(rand(100)); > push @recent_searches, { > query_desc => $query_desc, > query_cgi => $query_cgi, > total => "$total", > type => $type, >- time => output_pref({ dt => dt_from_string(), dateformat => 'iso' }), >+ time => output_pref({ dt => $now, dateformat => 'iso' }), >+ id => $id, > }; > > shift @recent_searches if (@recent_searches > 15); >@@ -65,22 +68,34 @@ sub build_new_cookie_value { > > sub delete { > my ( $params ) = @_; >+ my $id = $params->{id}; > my $userid = $params->{userid}; > my $sessionid = $params->{sessionid}; > my $type = $params->{type} || q{}; > my $previous = $params->{previous} || 0; > >- unless ( $userid ) { >- warn "ERROR: userid is required for history search"; >+ unless ( ref( $id ) ) { >+ $id = $id ? [ $id ] : []; >+ } >+ >+ unless ( $userid or @$id ) { >+ warn "ERROR: userid or id is required for history deletion"; > return; > } > > my $dbh = C4::Context->dbh; > my $query = q{ > DELETE FROM search_history >- WHERE userid = ? >+ WHERE 1 > }; > >+ $query .= q{ AND id IN ( } . join( q{,}, (q{?}) x @$id ) . q{ )} >+ if @$id; >+ >+ $query .= q{ >+ AND userid = ? >+ } if $userid; >+ > if ( $sessionid ) { > $query .= $previous > ? q{ AND sessionid != ?} >@@ -92,20 +107,55 @@ sub delete { > > $dbh->do( > $query, {}, >- $userid, >+ ( @$id ? ( @$id ) : () ), >+ ( $userid ? $userid : () ), > ( $sessionid ? $sessionid : () ), > ( $type ? $type : () ) > ); > } > >+sub delete_from_cookie { >+ my ( $params ) = @_; >+ my $cookie = $params->{cookie}; >+ my $id = $params->{id}; >+ >+ return unless $cookie; >+ >+ unless ( ref( $id ) ) { >+ $id = $id ? [ $id ] : []; >+ } >+ return unless @$id; >+ >+ my @searches; >+ if ( $cookie ){ >+ $cookie = uri_unescape( $cookie ); >+ if (decode_json( $cookie )) { >+ @searches = @{decode_json( $cookie )} >+ } >+ } >+ >+ @searches = map { >+ my $search = $_; >+ ( grep { $_ != $search->{id} } @$id ) ? $search : () >+ } @searches; >+ >+ return uri_escape( encode_json( \@searches ) ); >+ >+} >+ > sub get { > my ( $params ) = @_; >+ my $id = $params->{id}; > my $userid = $params->{userid}; > my $sessionid = $params->{sessionid}; > my $type = $params->{type}; > my $previous = $params->{previous}; > >- unless ( $userid ) { >+ unless ( ref( $id ) ) { >+ $id = $id ? [ $id ] : []; >+ } >+ >+ unless ( $userid or @$id ) { > warn "ERROR: userid is required for history search"; > return; > } >@@ -113,9 +163,16 @@ sub get { > my $query = q{ > SELECT * > FROM search_history >- WHERE userid = ? >+ WHERE 1 > }; > >+ $query .= q{ AND id IN ( } . join( q{,}, (q{?}) x @$id ) . q{ )} >+ if @$id; >+ >+ $query .= q{ >+ AND userid = ? >+ } if $userid; >+ > if ( $sessionid ) { > $query .= $previous > ? q{ AND sessionid != ?} >@@ -128,7 +185,8 @@ sub get { > my $dbh = C4::Context->dbh; > my $sth = $dbh->prepare( $query ); > $sth->execute( >- $userid, >+ ( @$id ? ( @$id ) : () ), >+ ( $userid ? $userid : () ), > ( $sessionid ? $sessionid : () ), > ( $type ? $type : () ) > ); >-- >1.7.10.4
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 11430
:
23713
|
23714
|
23715
|
23716
|
23717
|
23718
|
25499
|
25500
|
25501
|
25502
|
25503
|
25504
|
25618
|
28636
|
28637
|
28638
|
28639
|
28640
|
28641
|
28642
|
29042
|
29043
|
29044
|
29045
|
29046
|
29047
|
29048
|
29059
|
29081
|
29082
|
29083
|
29084
|
29085
|
29106
|
29107
|
29108
|
29109
|
29110
|
29592
|
29635
|
29636
|
29637
|
29638
|
29639
|
29640
|
33831
|
33832
|
33833
|
33834
|
33835
|
33836
|
36444
|
36820
|
36821
|
36822