@@ -, +, @@ currently logged in user. SysPref to turn on filtering of staged import list so that only batches staged by logged in user is visible. SysPref to remove Cleaned/Imported batches from staged import list. Link near list to ignore filter, in case one needs to see all batches. --- .gitignore | 3 ++ C4/ImportBatch.pm | 32 ++++++++++-- .../bug_18129-stage-with-username-syspref.sql | 2 + .../atomicupdate/bug_18129-stage-with-username.sql | 1 + .../en/modules/admin/preferences/cataloguing.pref | 12 +++++ .../prog/en/modules/tools/manage-marc-import.tt | 20 +++++++ t/ImportBatch.t | 61 +++++++++++++++++++++- tools/manage-marc-import.pl | 27 ++++++++-- 8 files changed, 148 insertions(+), 10 deletions(-) create mode 100644 .gitignore create mode 100644 installer/data/mysql/atomicupdate/bug_18129-stage-with-username-syspref.sql create mode 100644 installer/data/mysql/atomicupdate/bug_18129-stage-with-username.sql --- a/.gitignore +++ a/.gitignore @@ -0,0 +1,3 @@ +*~ +\#*# +.#* --- a/C4/ImportBatch.pm +++ a/C4/ImportBatch.pm @@ -237,9 +237,17 @@ sub GetImportRecordMarcXML { sub AddImportBatch { my ($params) = @_; + # Get ID of logged in user. if called from a batch job, + # no user session exists and C4::Context->userenv() returns + # the scalar '0'. + my $userenv = C4::Context->userenv(); + my $usernumber = (ref($userenv) eq 'HASH') ? $userenv->{'number'} : 0; + $usernumber ||= 0; + $params->{borrowernumber} = $usernumber; + my (@fields, @vals); foreach (qw( matcher_id template_id branchcode - overlay_action nomatch_action item_action + overlay_action nomatch_action item_action borrowernumber import_status batch_type file_name comments record_type )) { if (exists $params->{$_}) { push @fields, $_; @@ -1028,13 +1036,29 @@ start at the given offset. =cut sub GetImportBatchRangeDesc { - my ($offset, $results_per_group) = @_; + my ($offset, $results_per_group, $no_filter) = @_; my $dbh = C4::Context->dbh; my $query = "SELECT * FROM import_batches - WHERE batch_type IN ('batch', 'webservice') - ORDER BY import_batch_id DESC"; + WHERE batch_type IN ('batch', 'webservice')"; + my @params; + + if(C4::Context->preference("StageFilterByUser") && !$no_filter) { + my $userenv = C4::Context->userenv(); + my $usernumber = (ref($userenv) eq 'HASH') ? $userenv->{'number'} : 0; + $usernumber ||= 0; + + $query .= " AND borrowernumber = ?"; + push(@params, $usernumber); + } + + if(C4::Context->preference("StageHideCleanedImported") && !$no_filter) { + $query .= " AND import_status NOT IN ('cleaned', 'imported')"; + } + + $query .= " ORDER BY import_batch_id DESC"; + if ($results_per_group){ $query .= " LIMIT ?"; push(@params, $results_per_group); --- a/installer/data/mysql/atomicupdate/bug_18129-stage-with-username-syspref.sql +++ a/installer/data/mysql/atomicupdate/bug_18129-stage-with-username-syspref.sql @@ -0,0 +1,2 @@ +INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type`) VALUES ('StageFilterByUser', '0', '', 'Filter staged batches by user', 'YesNo'); +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 +++ a/installer/data/mysql/atomicupdate/bug_18129-stage-with-username.sql @@ -0,0 +1, @@ +ALTER TABLE `import_batches` ADD `borrowernumber` int(11); --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref @@ -231,6 +231,18 @@ Cataloging: yes: "do" no: "don't" - 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. + - + - In list of staged batches of MARC records, + - pref: StageFilterByUser + choices: + yes: "show only batches uploaded by logged in user." + no: "show all batches regardless of user." + - + - pref: StageHideCleanedImported + choices: + yes: "Hide" + no: "Do not hide" + - cleaned and imported batches of MARC records by default. Exporting: - --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt @@ -1,3 +1,4 @@ +[% USE Koha %] [% INCLUDE 'doc-head-open.inc' %]