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

(-)a/.gitignore (+3 lines)
Line 0 Link Here
1
*~
2
\#*#
3
.#*
(-)a/C4/ImportBatch.pm (-4 / +28 lines)
Lines 237-245 sub GetImportRecordMarcXML { Link Here
237
sub AddImportBatch {
237
sub AddImportBatch {
238
    my ($params) = @_;
238
    my ($params) = @_;
239
239
240
    # Get ID of logged in user.  if called from a batch job,
241
    # no user session exists and C4::Context->userenv() returns
242
    # the scalar '0'.
243
    my $userenv = C4::Context->userenv();
244
    my $usernumber = (ref($userenv) eq 'HASH') ? $userenv->{'number'} : 0;
245
    $usernumber ||= 0;
246
    $params->{borrowernumber} = $usernumber;
247
240
    my (@fields, @vals);
248
    my (@fields, @vals);
241
    foreach (qw( matcher_id template_id branchcode
249
    foreach (qw( matcher_id template_id branchcode
242
                 overlay_action nomatch_action item_action
250
                 overlay_action nomatch_action item_action borrowernumber
243
                 import_status batch_type file_name comments record_type )) {
251
                 import_status batch_type file_name comments record_type )) {
244
        if (exists $params->{$_}) {
252
        if (exists $params->{$_}) {
245
            push @fields, $_;
253
            push @fields, $_;
Lines 1028-1040 start at the given offset. Link Here
1028
=cut
1036
=cut
1029
1037
1030
sub GetImportBatchRangeDesc {
1038
sub GetImportBatchRangeDesc {
1031
    my ($offset, $results_per_group) = @_;
1039
    my ($offset, $results_per_group, $no_filter) = @_;
1032
1040
1033
    my $dbh = C4::Context->dbh;
1041
    my $dbh = C4::Context->dbh;
1034
    my $query = "SELECT * FROM import_batches
1042
    my $query = "SELECT * FROM import_batches
1035
                                    WHERE batch_type IN ('batch', 'webservice')
1043
                                    WHERE batch_type IN ('batch', 'webservice')";
1036
                                    ORDER BY import_batch_id DESC";
1044
1037
    my @params;
1045
    my @params;
1046
1047
    if(C4::Context->preference("StageFilterByUser") && !$no_filter) {
1048
        my $userenv = C4::Context->userenv();
1049
        my $usernumber = (ref($userenv) eq 'HASH') ? $userenv->{'number'} : 0;
1050
        $usernumber ||= 0;
1051
        
1052
        $query .= " AND borrowernumber = ?";
1053
        push(@params, $usernumber);
1054
    }
1055
    
1056
    if(C4::Context->preference("StageHideCleanedImported") && !$no_filter) {
1057
        $query .= " AND import_status NOT IN ('cleaned', 'imported')";
1058
    }
1059
    
1060
    $query .= " ORDER BY import_batch_id DESC";
1061
1038
    if ($results_per_group){
1062
    if ($results_per_group){
1039
        $query .= " LIMIT ?";
1063
        $query .= " LIMIT ?";
1040
        push(@params, $results_per_group);
1064
        push(@params, $results_per_group);
(-)a/installer/data/mysql/atomicupdate/bug_18129-stage-with-username-syspref.sql (+2 lines)
Line 0 Link Here
1
INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type`) VALUES ('StageFilterByUser', '0', '', 'Filter staged batches by user', 'YesNo');
2
INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type`) VALUES ('StageHideCleanedImported', '0', '', 'Hide staged batches when cleaned or imported', 'YesNo');
(-)a/installer/data/mysql/atomicupdate/bug_18129-stage-with-username.sql (+1 lines)
Line 0 Link Here
1
ALTER TABLE `import_batches` ADD `borrowernumber` int(11);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref (+12 lines)
Lines 231-236 Cataloging: Link Here
231
                  yes: "do"
231
                  yes: "do"
232
                  no: "don't"
232
                  no: "don't"
233
            - attempt to match aggressively by trying all variations of the ISSNs in the imported record as a phrase in the ISSN fields of already cataloged records.  Note that this preference has no effect if UseQueryParser is on.
233
            - attempt to match aggressively by trying all variations of the ISSNs in the imported record as a phrase in the ISSN fields of already cataloged records.  Note that this preference has no effect if UseQueryParser is on.
234
        -
235
            - In list of staged batches of MARC records,
236
            - pref: StageFilterByUser
237
              choices:
238
                  yes: "show only batches uploaded by logged in user."
239
                  no: "show all batches regardless of user."
240
        -
241
            - pref: StageHideCleanedImported
242
              choices:
243
                  yes: "Hide"
244
                  no: "Do not hide"
245
            - cleaned and imported batches of MARC records by default.
234
246
235
    Exporting:
247
    Exporting:
236
        -
248
        -
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt (+20 lines)
Lines 1-3 Link Here
1
[% USE Koha %]
1
[% BLOCK final_match_link %]
2
[% BLOCK final_match_link %]
2
    [% IF ( record.record_type == 'biblio' ) %]
3
    [% IF ( record.record_type == 'biblio' ) %]
3
        <a target="_blank" href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% record.final_match_id %]">[% record.final_match_id %]</a>
4
        <a target="_blank" href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% record.final_match_id %]">[% record.final_match_id %]</a>
Lines 212-217 $(document).ready(function(){ Link Here
212
   <div class="dialog message">
213
   <div class="dialog message">
213
     <p>No records have been staged.</p>
214
     <p>No records have been staged.</p>
214
     <p><a href="/cgi-bin/koha/tools/stage-marc-import.pl">Stage MARC records for import</a>.</p>
215
     <p><a href="/cgi-bin/koha/tools/stage-marc-import.pl">Stage MARC records for import</a>.</p>
216
     [% IF Koha.Preference( 'StageFilterByUser' ) %]
217
     <p>
218
       [% UNLESS ( no_filter ) %]
219
         <a href="[% batch_lis.script_name %]?no_filter=1">Show unfiltered list</a>.
220
       [% END %]
221
     </p>
222
  [% END %]
215
   </div>
223
   </div>
216
   [% END %]
224
   [% END %]
217
[% END %]
225
[% END %]
Lines 247-252 $(document).ready(function(){ Link Here
247
<fieldset class="rows" id="staged-record-matching-rules">
255
<fieldset class="rows" id="staged-record-matching-rules">
248
  <ol>
256
  <ol>
249
    <li><span class="label">File name:</span> [% file_name %]</li>
257
    <li><span class="label">File name:</span> [% file_name %]</li>
258
    <li><span class="label">User:</span> [% user_name %]</li>
250
    <li><span class="label">Comments:</span> [% IF ( comments ) %][% comments %][% ELSE %](none)[% END %]</li>
259
    <li><span class="label">Comments:</span> [% IF ( comments ) %][% comments %][% ELSE %](none)[% END %]</li>
251
    <li><span class="label">Type:</span> [% IF ( record_type == 'auth' ) %]Authority records[% ELSE %]Bibliographic records[% END %]</li>
260
    <li><span class="label">Type:</span> [% IF ( record_type == 'auth' ) %]Authority records[% ELSE %]Bibliographic records[% END %]</li>
252
    <li><span class="label">Staged:</span> [% upload_timestamp %]</li>
261
    <li><span class="label">Staged:</span> [% upload_timestamp %]</li>
Lines 411-416 $(document).ready(function(){ Link Here
411
<br style="clear:both;" />
420
<br style="clear:both;" />
412
421
413
[% IF ( batch_list ) %]
422
[% IF ( batch_list ) %]
423
  [% IF Koha.Preference( 'StageFilterByUser' ) %]
424
    <p>
425
    [% IF ( no_filter ) %]
426
      <a href="[% batch_lis.script_name %]?no_filter=0">Filter by logged in user</a>
427
    [% ELSE %]
428
      <a href="[% batch_lis.script_name %]?no_filter=1">Do not filter list</a>
429
    [% END %]
430
    </p>
431
  [% END %]
414
  [% IF ( pages ) %]
432
  [% IF ( pages ) %]
415
<div class="pages">
433
<div class="pages">
416
Page 
434
Page 
Lines 427-432 Page Link Here
427
  <tr>
445
  <tr>
428
    <th>#</th>
446
    <th>#</th>
429
    <th>File name</th>
447
    <th>File name</th>
448
    <th>User</th>
430
    <th>Comments</th>
449
    <th>Comments</th>
431
    <th>Type</th>
450
    <th>Type</th>
432
    <th>Status</th>
451
    <th>Status</th>
Lines 439-444 Page Link Here
439
    <tr>
458
    <tr>
440
    <td>[% batch_lis.import_batch_id %]</td>
459
    <td>[% batch_lis.import_batch_id %]</td>
441
    <td><a href="[% batch_lis.script_name %]?import_batch_id=[% batch_lis.import_batch_id %]">[% batch_lis.file_name %]</a></td>
460
    <td><a href="[% batch_lis.script_name %]?import_batch_id=[% batch_lis.import_batch_id %]">[% batch_lis.file_name %]</a></td>
461
    <td>[% batch_lis.user_name %]</td>
442
    <td>[% batch_lis.comments %]</td>
462
    <td>[% batch_lis.comments %]</td>
443
    <td>[% IF ( batch_lis.record_type == 'auth' ) %]Authority[% ELSE %]Bibliographic[% END %]</td>
463
    <td>[% IF ( batch_lis.record_type == 'auth' ) %]Authority[% ELSE %]Bibliographic[% END %]</td>
444
    <td>
464
    <td>
(-)a/t/ImportBatch.t (-1 / +60 lines)
Lines 21-27 use File::Temp qw|tempfile|; Link Here
21
use MARC::Field;
21
use MARC::Field;
22
use MARC::File::XML;
22
use MARC::File::XML;
23
use MARC::Record;
23
use MARC::Record;
24
use Test::More tests => 3;
24
use Test::More tests => 4;
25
use t::lib::Mocks;
25
use t::lib::Mocks;
26
26
27
BEGIN {
27
BEGIN {
Lines 30-35 BEGIN { Link Here
30
30
31
t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
31
t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
32
32
33
subtest 'StageFilterByUser' => sub {
34
    plan tests => 5;
35
36
    # Set current user to "user1"
37
    C4::Context->_new_userenv('USER1-ENV');
38
    C4::Context->set_userenv('12345', 'user1', '12345', '', '', '', '', 1, '', '');
39
    C4::Context->set_preference( 'StageFilterByUser', '1');
40
    C4::Context->set_preference( 'StageHideCleanedImported', '1');
41
42
    my $file = create_file({ two => 1, format => 'marc'});
43
    my ($errors, $recs) = C4::ImportBatch::RecordsFromISO2709File($file, 'biblio', 'UTF-8');
44
    
45
    my ($batch_id) = C4::ImportBatch::BatchStageMarcRecords('biblio', 'UTF-8', $recs,
46
                                                          'file1.mrc', undef, undef, '',
47
                                                          '', 1, 0, 0, undef);
48
49
    my $batch_list_user1 = C4::ImportBatch::GetImportBatchRangeDesc(0, 100000);
50
    is( find_id_in_batch_list($batch_id, $batch_list_user1), 1, "Found one batch from user1");
51
    
52
    # Set current user to "user2"
53
    C4::Context->_new_userenv('USER2-ENV');
54
    C4::Context->set_userenv('23456', 'user2', '23456', '', '', '', '', 1, '', '');
55
56
    my $batch_list_user2 = C4::ImportBatch::GetImportBatchRangeDesc(0, 100000);
57
    is( find_id_in_batch_list($batch_id, $batch_list_user2), 0, "Did not see batches from user1 when logged in as user2");
58
59
    $batch_list_user2 = C4::ImportBatch::GetImportBatchRangeDesc(0, 100000, 1);
60
    is( find_id_in_batch_list($batch_id, $batch_list_user2), 1, "Can see batch from user1 as user2 when filter is disabled");
61
62
    # Set current user back to "user1"
63
    C4::Context->_new_userenv('USER1-ENV');
64
    C4::Context->set_userenv('12345', 'user1', '12345', '', '', '', '', 1, '', '');
65
66
    C4::Context->set_preference( 'StageHideCleanedImported', '1');
67
    C4::ImportBatch::SetImportBatchStatus($batch_id, 'imported');
68
69
    $batch_list_user1 = C4::ImportBatch::GetImportBatchRangeDesc(0, 100000);
70
    is( find_id_in_batch_list($batch_id, $batch_list_user1), 0, "Did not see imported batch from user1 hen hidden");
71
72
    C4::Context->set_preference( 'StageHideCleanedImported', '0');
73
    C4::ImportBatch::SetImportBatchStatus($batch_id, 'imported');
74
75
    $batch_list_user1 = C4::ImportBatch::GetImportBatchRangeDesc(0, 100000);
76
    is( find_id_in_batch_list($batch_id, $batch_list_user1), 1, "Did see imported batch from user1 when not hidden");
77
    
78
    C4::ImportBatch::DeleteBatch($batch_id);
79
};
80
33
subtest 'RecordsFromISO2709File' => sub {
81
subtest 'RecordsFromISO2709File' => sub {
34
    plan tests => 4;
82
    plan tests => 4;
35
83
Lines 99-101 sub create_file { Link Here
99
    close $fh;
147
    close $fh;
100
    return $name;
148
    return $name;
101
}
149
}
150
151
sub find_id_in_batch_list {
152
    my ($batch_id, $batch_list) = @_;
153
    my $found = 0;
154
    foreach my $batch (@$batch_list) {
155
        if($batch->{import_batch_id} == $batch_id) {
156
            $found = 1;
157
        }
158
    }
159
    return $found;
160
}
(-)a/tools/manage-marc-import.pl (-6 / +22 lines)
Lines 32-37 use C4::Auth; Link Here
32
use C4::AuthoritiesMarc;
32
use C4::AuthoritiesMarc;
33
use C4::Output;
33
use C4::Output;
34
use C4::Biblio;
34
use C4::Biblio;
35
use C4::Members;
35
use C4::ImportBatch;
36
use C4::ImportBatch;
36
use C4::Matcher;
37
use C4::Matcher;
37
use C4::BackgroundJob;
38
use C4::BackgroundJob;
Lines 42-47 my $script_name = "/cgi-bin/koha/tools/manage-marc-import.pl"; Link Here
42
43
43
my $input = new CGI;
44
my $input = new CGI;
44
my $op = $input->param('op') || '';
45
my $op = $input->param('op') || '';
46
my $no_filter = $input->param('no_filter') || 0;
45
my $completedJobID = $input->param('completedJobID');
47
my $completedJobID = $input->param('completedJobID');
46
our $runinbackground = $input->param('runinbackground');
48
our $runinbackground = $input->param('runinbackground');
47
my $import_batch_id = $input->param('import_batch_id') || '';
49
my $import_batch_id = $input->param('import_batch_id') || '';
Lines 91-97 if ($op) { Link Here
91
if ($op eq "") {
93
if ($op eq "") {
92
    # displaying a list
94
    # displaying a list
93
    if ($import_batch_id eq '') {
95
    if ($import_batch_id eq '') {
94
        import_batches_list($template, $offset, $results_per_page);
96
        import_batches_list($template, $offset, $results_per_page, $no_filter);
95
    } else {
97
    } else {
96
        import_records_list($template, $import_batch_id, $offset, $results_per_page);
98
        import_records_list($template, $import_batch_id, $offset, $results_per_page);
97
    }
99
    }
Lines 112-125 if ($op eq "") { Link Here
112
    import_records_list($template, $import_batch_id, $offset, $results_per_page);
114
    import_records_list($template, $import_batch_id, $offset, $results_per_page);
113
} elsif ($op eq "clean-batch") {
115
} elsif ($op eq "clean-batch") {
114
    CleanBatch($import_batch_id);
116
    CleanBatch($import_batch_id);
115
    import_batches_list($template, $offset, $results_per_page);
117
    import_batches_list($template, $offset, $results_per_page, $no_filter);
116
    $template->param( 
118
    $template->param( 
117
        did_clean       => 1,
119
        did_clean       => 1,
118
        import_batch_id => $import_batch_id,
120
        import_batch_id => $import_batch_id,
119
    );
121
    );
120
} elsif ($op eq "delete-batch") {
122
} elsif ($op eq "delete-batch") {
121
    DeleteBatch($import_batch_id);
123
    DeleteBatch($import_batch_id);
122
    import_batches_list($template, $offset, $results_per_page);
124
    import_batches_list($template, $offset, $results_per_page, $no_filter);
123
    $template->param(
125
    $template->param(
124
        did_delete      => 1,
126
        did_delete      => 1,
125
    );
127
    );
Lines 203-213 sub create_labelbatch_from_importbatch { Link Here
203
}
205
}
204
206
205
sub import_batches_list {
207
sub import_batches_list {
206
    my ($template, $offset, $results_per_page) = @_;
208
    my ($template, $offset, $results_per_page, $no_filter) = @_;
207
    my $batches = GetImportBatchRangeDesc($offset, $results_per_page);
209
    my $batches = GetImportBatchRangeDesc($offset, $results_per_page, $no_filter);
208
210
209
    my @list = ();
211
    my @list = ();
210
    foreach my $batch (@$batches) {
212
    foreach my $batch (@$batches) {
213
        my $borrower = GetMember(borrowernumber => $batch->{'borrowernumber'});
214
        my $user_name = "";
215
        if($borrower) {
216
            $user_name = $borrower->{'userid'};
217
        }
218
        
211
        push @list, {
219
        push @list, {
212
            import_batch_id => $batch->{'import_batch_id'},
220
            import_batch_id => $batch->{'import_batch_id'},
213
            num_records => $batch->{'num_records'},
221
            num_records => $batch->{'num_records'},
Lines 218-223 sub import_batches_list { Link Here
218
            comments => $batch->{'comments'},
226
            comments => $batch->{'comments'},
219
            can_clean => ($batch->{'import_status'} ne 'cleaned') ? 1 : 0,
227
            can_clean => ($batch->{'import_status'} ne 'cleaned') ? 1 : 0,
220
            record_type => $batch->{'record_type'},
228
            record_type => $batch->{'record_type'},
229
            user_name => $user_name,
221
        };
230
        };
222
    }
231
    }
223
    $template->param(batch_list => \@list); 
232
    $template->param(batch_list => \@list); 
Lines 227-232 sub import_batches_list { Link Here
227
    $template->param(range_top => $offset + $results_per_page - 1);
236
    $template->param(range_top => $offset + $results_per_page - 1);
228
    $template->param(num_results => $num_batches);
237
    $template->param(num_results => $num_batches);
229
    $template->param(results_per_page => $results_per_page);
238
    $template->param(results_per_page => $results_per_page);
239
    $template->param(no_filter => $no_filter);
230
240
231
}
241
}
232
242
Lines 354-359 sub import_records_list { Link Here
354
    my $batch = GetImportBatch($import_batch_id);
364
    my $batch = GetImportBatch($import_batch_id);
355
    $template->param(import_batch_id => $import_batch_id);
365
    $template->param(import_batch_id => $import_batch_id);
356
366
367
    my $borrower = GetMember(borrowernumber => $batch->{'borrowernumber'});
368
    my $user_name = "";
369
    if($borrower) {
370
        $user_name = $borrower->{'userid'};
371
    }
372
    $template->param("user_name" => $user_name);
373
        
357
    my $overlay_action = GetImportBatchOverlayAction($import_batch_id);
374
    my $overlay_action = GetImportBatchOverlayAction($import_batch_id);
358
    $template->param("overlay_action_${overlay_action}" => 1);
375
    $template->param("overlay_action_${overlay_action}" => 1);
359
    $template->param(overlay_action => $overlay_action);
376
    $template->param(overlay_action => $overlay_action);
360
- 

Return to bug 18129