View | Details | Raw Unified | Return to bug 8010
Collapse All | Expand All

(-)a/C4/Auth.pm (-24 / +26 lines)
Lines 330-360 sub get_template_and_user { Link Here
330
                # We show the link in opac
330
                # We show the link in opac
331
                $template->param( EnableOpacSearchHistory => 1 );
331
                $template->param( EnableOpacSearchHistory => 1 );
332
            }
332
            }
333
            if (C4::Context->preference('addSearchHistoryToTheFirstLoggedUser'))
334
            {
335
                # And if there are searches performed when the user was not logged in,
336
                # we add them to the logged-in search history
337
                my @recentSearches = C4::Search::History::get_from_session( { cgi => $in->{'query'} } );
338
                if (@recentSearches) {
339
                    my $dbh   = C4::Context->dbh;
340
                    my $query = q{
341
                        INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, type,  total, time )
342
                        VALUES (?, ?, ?, ?, ?, ?, ?)
343
                    };
344
                    my $sth = $dbh->prepare($query);
345
                    $sth->execute( $borrowernumber,
346
                        $in->{query}->cookie("CGISESSID"),
347
                        $_->{query_desc},
348
                        $_->{query_cgi},
349
                        $_->{type} || 'biblio',
350
                        $_->{total},
351
                        $_->{time},
352
                    ) foreach @recentSearches;
353
354
                    # clear out the search history from the session now that
355
                    # we've saved it to the database
356
                 }
357
              }
358
              C4::Search::History::set_to_session( { cgi => $in->{'query'}, search_history => [] } );
333
359
334
            # And if there are searches performed when the user was not logged in,
335
            # we add them to the logged-in search history
336
            my @recentSearches = C4::Search::History::get_from_session( { cgi => $in->{'query'} } );
337
            if (@recentSearches) {
338
                my $dbh   = C4::Context->dbh;
339
                my $query = q{
340
                    INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, type,  total, time )
341
                    VALUES (?, ?, ?, ?, ?, ?, ?)
342
                };
343
344
                my $sth = $dbh->prepare($query);
345
                $sth->execute( $borrowernumber,
346
                    $in->{query}->cookie("CGISESSID"),
347
                    $_->{query_desc},
348
                    $_->{query_cgi},
349
                    $_->{type} || 'biblio',
350
                    $_->{total},
351
                    $_->{time},
352
                ) foreach @recentSearches;
353
354
                # clear out the search history from the session now that
355
                # we've saved it to the database
356
                C4::Search::History::set_to_session( { cgi => $in->{'query'}, search_history => [] } );
357
            }
358
        } elsif ( $in->{type} eq 'intranet' and C4::Context->preference('EnableSearchHistory') ) {
360
        } elsif ( $in->{type} eq 'intranet' and C4::Context->preference('EnableSearchHistory') ) {
359
            $template->param( EnableSearchHistory => 1 );
361
            $template->param( EnableSearchHistory => 1 );
360
        }
362
        }
(-)a/installer/data/mysql/atomicupdate/bug_8010-add_LoadSearchHistoryToTheFirstLoggedUser_syspref.sql (+2 lines)
Line 0 Link Here
1
INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
2
('addSearchHistoryToTheFirstLoggedUser', '1', NULL, 'If ON, the next user will automatically get the last seaches in his history', 'YesNo');
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 234-239 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
234
('LinkerModule','Default','Default|FirstMatch|LastMatch','Chooses which linker module to use (see documentation).','Choice'),
234
('LinkerModule','Default','Default|FirstMatch|LastMatch','Chooses which linker module to use (see documentation).','Choice'),
235
('LinkerOptions','','','A pipe-separated list of options for the linker.','free'),
235
('LinkerOptions','','','A pipe-separated list of options for the linker.','free'),
236
('LinkerRelink','1',NULL,'If ON the authority linker will relink headings that have previously been linked every time it runs.','YesNo'),
236
('LinkerRelink','1',NULL,'If ON the authority linker will relink headings that have previously been linked every time it runs.','YesNo'),
237
('LoadSearchHistoryToTheFirstLoggedUser', '1', NULL, 'If ON, the next user will automatically get the last seaches in his history', 'YesNo'),
237
('LocalCoverImages','0','1','Display local cover images on intranet details pages.','YesNo'),
238
('LocalCoverImages','0','1','Display local cover images on intranet details pages.','YesNo'),
238
('LocalHoldsPriority',  '0', NULL,  'Enables the LocalHoldsPriority feature',  'YesNo'),
239
('LocalHoldsPriority',  '0', NULL,  'Enables the LocalHoldsPriority feature',  'YesNo'),
239
('LocalHoldsPriorityItemControl',  'holdingbranch',  'holdingbranch|homebranch',  'decides if the feature operates using the item''s home or holding library.',  'Choice'),
240
('LocalHoldsPriorityItemControl',  'holdingbranch',  'holdingbranch|homebranch',  'decides if the feature operates using the item''s home or holding library.',  'Choice'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref (+8 lines)
Lines 80-85 Searching: Link Here
80
            - patron search history in the staff client.
80
            - patron search history in the staff client.
81
    Search Form:
81
    Search Form:
82
        -
82
        -
83
            - Load the unlogged history to the next user.
84
            - pref : LoadSearchHistoryToTheFirstLoggedUser
85
              default: 0
86
              choices:
87
                   yes: "Load"
88
                   no : "Don't load"
89
            - history to the next client.
90
        -
83
            - Show tabs in OPAC and staff-side advanced search for limiting searches on the
91
            - Show tabs in OPAC and staff-side advanced search for limiting searches on the
84
            - pref: AdvancedSearchTypes
92
            - pref: AdvancedSearchTypes
85
              class: long
93
              class: long
(-)a/t/db_dependent/Auth2.t (-1 / +148 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use CGI qw ( -utf8 );
21
use Test::MockModule;
22
use List::MoreUtils qw/all any none/;
23
use Test::More tests => 2;
24
use t::lib::Mocks;
25
use t::lib::TestBuilder;
26
27
use C4::Auth;
28
use Koha::AuthUtils qw/hash_password/;
29
use Koha::Database;
30
31
my $query = new CGI;
32
33
my $schema = Koha::Database->schema;
34
$schema->storage->txn_begin;
35
my $builder = t::lib::TestBuilder->new;
36
37
# Borrower Creation
38
my $hash1 = hash_password('password');
39
my $patron = $builder->build( { source => 'Borrower' } );
40
Koha::Patrons->find( $patron->{borrowernumber} )->update_password( $patron->{userid}, $hash1 );
41
42
my $session = C4::Auth::get_session("");
43
$session->flush;
44
45
sub myMockedget_from_session {
46
    my $expected_recent_searches = [
47
        {
48
            'time' => 1374978877,
49
            'query_cgi' => 'cgi_test',
50
            'total' => 2,
51
            'query_desc' => 'kw,wrdl: history, '
52
        }
53
    ];
54
    return @{$expected_recent_searches};
55
56
}
57
58
my $getfrom = new Test::MockModule( 'C4::Search::History' );
59
$getfrom->mock( 'get_from_session', \&myMockedget_from_session );
60
61
my $cgi = new Test::MockModule( 'CGI');
62
$cgi->mock('cookie', sub {
63
   my ($self, $key2) = @_;
64
  if (!ref($key2) && $key2 eq 'CGISESSID'){
65
         return 'ID';
66
   }
67
});
68
69
sub MockedCheckauth {
70
    my ($query,$authnotrequired,$flagsrequired,$type) = @_;
71
    my $userid = $patron->{userid};
72
    my $sessionID = 234;
73
    my $flags = {
74
        superlibrarian    => 1, acquisition       => 0,
75
        borrowers         => 0,
76
        catalogue         => 1, circulate         => 0,
77
        coursereserves    => 0, editauthorities   => 0,
78
        editcatalogue     => 0, management        => 0,
79
        parameters        => 0, permissions       => 0,
80
        plugins           => 0, reports           => 0,
81
        reserveforothers  => 0, serials           => 0,
82
        staffaccess       => 0, tools             => 0,
83
        updatecharges     => 0
84
    };
85
86
    my $session_cookie = $query->cookie(
87
        -name => 'CGISESSID',
88
        -value    => '9884013ae2c441d12e0bc9376242d2a8',
89
        -HttpOnly => 1
90
    );
91
    return ( $userid, $session_cookie, $sessionID, $flags );
92
}
93
94
# Mock checkauth, build the scenario
95
my $auth = new Test::MockModule( 'C4::Auth' );
96
$auth->mock( 'checkauth', \&MockedCheckauth );
97
98
$query->param('koha_login_context', 'opac');
99
$query->param('userid', $patron->{userid});
100
$query->param('password', 'password');
101
102
t::lib::Mocks::mock_preference('addSearchHistoryToTheFirstLoggedUser', 0);
103
$query->cookie(
104
        -name     => 'CGISESSID',
105
        -value    => $session->id,
106
        -HttpOnly => 1
107
);
108
my $result = $schema->resultset('SearchHistory')->search()->count;
109
110
my ( $template, $loggedinuser, $cookies ) = get_template_and_user(
111
    {
112
        template_name   => "opac-user.tt",
113
        query           => $query,
114
        type            => "opac",
115
        authnotrequired => 0,
116
        debug           => 1
117
    }
118
);
119
120
my $result2 = $schema->resultset('SearchHistory')->search()->count;
121
is($result2, $result, 'no new search added to borrower');
122
t::lib::Mocks::mock_preference('addSearchHistoryToTheFirstLoggedUser', 1);
123
124
$query->param('koha_login_context', 'opac');
125
$query->param('userid', $patron->{userid});
126
$query->param('password', 'password');
127
$query->cookie(
128
        -name     => 'CGISESSID',
129
        -value    => $session->id,
130
        -HttpOnly => 1
131
);
132
133
$result = $schema->resultset('SearchHistory')->search()->count;
134
135
( $template, $loggedinuser, $cookies ) = get_template_and_user(
136
    {
137
        template_name   => "opac-user.tt",
138
        query           => $query,
139
        type            => "opac",
140
        authnotrequired => 0,
141
        debug           => 1
142
    }
143
);
144
145
$result2 = $schema->resultset('SearchHistory')->search()->count;
146
is($result2, $result+1, 'new search added to borrower');
147
$result = $schema->resultset('SearchHistory')->search(undef, { query_cgi => 'cgi_test'});
148
$result->delete_all();

Return to bug 8010