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 (+3 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');
3
(-)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 / +167 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
#
3
# This Koha test module is a stub!  
4
# Add more tests here!!!
5
t::lib::Mocks::mock_preference( 'HoldsLog', 1 );
6
7
use Modern::Perl;
8
9
use CGI qw ( -utf8 );
10
use Test::MockModule;
11
use List::MoreUtils qw/all any none/;
12
use Test::More tests => 2; 
13
14
use t::lib::Mocks;
15
use t::lib::TestBuilder;
16
17
18
use C4::Auth;
19
use Koha::AuthUtils qw/hash_password/;
20
use Koha::Database;
21
22
23
24
my $query = new CGI;
25
26
my $schema = Koha::Database->schema;
27
$schema->storage->txn_begin;
28
my $builder = t::lib::TestBuilder->new;
29
my $dbh1     = C4::Context->dbh({AutoCommit => 0});
30
$dbh1->{RaiseError} = 1;
31
32
warn "Dumper : ".$dbh1->{AutoCommit};
33
warn Data::Dumper::Dumper($dbh1);
34
35
my $hash1 = hash_password('password');
36
37
my $patron = $builder->build( { source => 'Borrower' } );
38
Koha::Patrons->find( $patron->{borrowernumber} )->update_password( $patron->{userid}, $hash1 );
39
40
my $session = C4::Auth::get_session("");
41
$session->flush;
42
43
sub myMockedget_from_session {
44
    my $expected_recent_searches = [
45
        {
46
            'time' => 1374978877,
47
            'query_cgi' => 'cgi_test',
48
            'total' => 2,
49
            'query_desc' => 'kw,wrdl: history, '
50
        }
51
    ];   
52
    return @{$expected_recent_searches};
53
 
54
}
55
56
my $getfrom = new Test::MockModule( 'C4::Search::History' );
57
$getfrom->mock( 'get_from_session', \&myMockedget_from_session );
58
59
my $cgi = new Test::MockModule( 'CGI');
60
$cgi->mock('cookie', sub {
61
   my ($self, $key2) = @_;
62
  if (!ref($key2) && $key2 eq 'CGISESSID'){
63
         return 'ID';
64
   }
65
});
66
67
68
69
70
sub MockedCheckauth {
71
    my ($query,$authnotrequired,$flagsrequired,$type) = @_;
72
    # return vars
73
    my $userid = $patron->{userid};
74
    my $sessionID = 234;
75
    # we don't need to bother about permissions for this test
76
    my $flags = {
77
        superlibrarian    => 1, acquisition       => 0,
78
        borrowers         => 0, 
79
        catalogue         => 1, circulate         => 0,
80
        coursereserves    => 0, editauthorities   => 0,
81
        editcatalogue     => 0, management        => 0,
82
        parameters        => 0, permissions       => 0,
83
        plugins           => 0, reports           => 0,
84
        reserveforothers  => 0, serials           => 0,
85
        staffaccess       => 0, tools             => 0,
86
        updatecharges     => 0
87
    };
88
89
    my $session_cookie = $query->cookie(
90
        -name => 'CGISESSID',
91
        -value    => '9884013ae2c441d12e0bc9376242d2a8',
92
        -HttpOnly => 1
93
    );
94
    return ( $userid, $session_cookie, $sessionID, $flags );
95
}
96
# Mock checkauth, build the scenario
97
my $auth = new Test::MockModule( 'C4::Auth' );
98
$auth->mock( 'checkauth', \&MockedCheckauth );
99
100
101
warn "Dumper : ".$dbh1->{AutoCommit};
102
103
$query->param('koha_login_context', 'opac');
104
$query->param('userid', $patron->{userid}); 
105
$query->param('password', 'password');
106
107
warn "Dumper : $dbh1->{AutoCommit}";
108
109
t::lib::Mocks::mock_preference('addSearchHistoryToTheFirstLoggedUser', 0);
110
$query->cookie(
111
        -name     => 'CGISESSID',
112
        -value    => $session->id,
113
        -HttpOnly => 1
114
);
115
my $result = $schema->resultset('SearchHistory')->search()->count;
116
117
my ( $template, $loggedinuser, $cookies ) = get_template_and_user(
118
    {
119
        template_name   => "opac-user.tt",
120
        query           => $query,
121
        type            => "opac",
122
        authnotrequired => 0,
123
        debug           => 1
124
    }
125
);  
126
127
warn "Dumper : $dbh1->{AutoCommit}";
128
my $result2 = $schema->resultset('SearchHistory')->search()->count;
129
is($result2, $result, 'no new search added to borrower');
130
131
132
133
134
135
t::lib::Mocks::mock_preference('addSearchHistoryToTheFirstLoggedUser', 1);
136
137
$query->param('koha_login_context', 'opac');
138
$query->param('userid', $patron->{userid});
139
$query->param('password', 'password');
140
$query->cookie(
141
        -name     => 'CGISESSID',
142
        -value    => $session->id,
143
        -HttpOnly => 1
144
);
145
146
147
warn "Dumper : $dbh1->{AutoCommit}";
148
$result = $schema->resultset('SearchHistory')->search()->count;
149
150
( $template, $loggedinuser, $cookies ) = get_template_and_user(
151
    {
152
        template_name   => "opac-user.tt",
153
        query           => $query,
154
        type            => "opac",
155
        authnotrequired => 0,
156
        debug           => 1
157
    }
158
);
159
$result2 = $schema->resultset('SearchHistory')->search()->count;
160
is($result2, $result+1, 'new search added to borrower');
161
$result = $schema->resultset('SearchHistory')->search(undef, { query_cgi => 'cgi_test'});
162
warn "count : ".Data::Dumper::Dumper($result->count);
163
$result->delete_all();
164
warn "count : ".Data::Dumper::Dumper($result->count);
165
166
warn "Dumper : $dbh1->{AutoCommit}";
167

Return to bug 8010