#
# This file is part of Koha.
#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
#
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
use strict;
use warnings;
# standard or CPAN modules used
-use CGI;
+use CGI qw ( -utf8 );
use CGI::Cookie;
use MARC::File::USMARC;
use C4::Matcher;
use C4::BackgroundJob;
use C4::Labels::Batch;
+use Koha::BiblioFrameworks;
my $script_name = "/cgi-bin/koha/tools/manage-marc-import.pl";
our $sessionID = $cookies{'CGISESSID'}->value;
our $dbh = C4::Context->dbh;
-# Frameworks selection loop
-{
- my $frameworks = getframeworks;
- my $arrayref = [];
- while ( my ($key, $value) = each %$frameworks ) {
- push @$arrayref, { value => $key, label => $value->{frameworktext} };
- }
- $template->param( frameworks => $arrayref );
-}
+my $frameworks = Koha::BiblioFrameworks->search({ tagfield => { 'not' => undef } }, { join => 'marc_tag_structure', group_by=>'frameworkcode',order_by => ['frameworktext'] });
+$template->param( frameworks => $frameworks );
if ($op eq "create_labels") {
#create a batch of labels, then lose $op & $import_batch_id so we get back to import batch list.
did_clean => 1,
import_batch_id => $import_batch_id,
);
+} elsif ($op eq "delete-batch") {
+ DeleteBatch($import_batch_id);
+ import_batches_list($template, $offset, $results_per_page);
+ $template->param(
+ did_delete => 1,
+ );
} elsif ($op eq "redo-matching") {
my $new_matcher_id = $input->param('new_matcher_id');
my $current_matcher_id = $input->param('current_matcher_id');
my ($template, $import_batch_id, $framework) = @_;
my $job = undef;
- $dbh->{AutoCommit} = 0;
- my $callback = sub {};
- if ($runinbackground) {
- $job = put_in_background($import_batch_id);
- $callback = progress_callback($job, $dbh);
- }
- my ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored) =
- BatchCommitRecords($import_batch_id, $framework, 50, $callback);
- $dbh->commit();
+ my ( $num_added, $num_updated, $num_items_added,
+ $num_items_replaced, $num_items_errored, $num_ignored );
+ my $schema = Koha::Database->new->schema;
+ $schema->storage->txn_do(
+ sub {
+ my $callback = sub { };
+ if ($runinbackground) {
+ $job = put_in_background($import_batch_id);
+ $callback = progress_callback( $job, $dbh );
+ }
+ (
+ $num_added, $num_updated, $num_items_added,
+ $num_items_replaced, $num_items_errored, $num_ignored
+ )
+ = BatchCommitRecords( $import_batch_id, $framework, 50,
+ $callback );
+ }
+ );
my $results = {
did_commit => 1,
sub revert_batch {
my ($template, $import_batch_id) = @_;
- $dbh->{AutoCommit} = 0;
my $job = undef;
- my $callback = sub {};
- if ($runinbackground) {
- $job = put_in_background($import_batch_id);
- $callback = progress_callback($job, $dbh);
- }
- my ($num_deleted, $num_errors, $num_reverted, $num_items_deleted, $num_ignored) =
- BatchRevertRecords($import_batch_id, 50, $callback);
- $dbh->commit();
+ my (
+ $num_deleted, $num_errors, $num_reverted,
+ $num_items_deleted, $num_ignored
+ );
+ my $schema = Koha::Database->new->schema;
+ $schema->txn_do(
+ sub {
+ my $callback = sub { };
+ if ($runinbackground) {
+ $job = put_in_background($import_batch_id);
+ $callback = progress_callback( $job, $dbh );
+ }
+ (
+ $num_deleted, $num_errors, $num_reverted,
+ $num_items_deleted, $num_ignored
+ ) = BatchRevertRecords( $import_batch_id, 50, $callback );
+ }
+ );
my $results = {
did_revert => 1,
my $import_batch_id = shift;
my $batch = GetImportBatch($import_batch_id);
- my $job = C4::BackgroundJob->new($sessionID, $batch->{'file_name'}, $ENV{'SCRIPT_NAME'}, $batch->{'num_records'});
+ my $job = C4::BackgroundJob->new($sessionID, $batch->{'file_name'}, '/cgi-bin/koha/tools/manage-marc-import.pl', $batch->{'num_records'});
my $jobID = $job->id();
# fork off
close STDERR;
} else {
# fork failed, so exit immediately
- warn "fork failed while attempting to run $ENV{'SCRIPT_NAME'} as a background job";
+ warn "fork failed while attempting to run tools/manage-marc-import.pl as a background job";
exit 0;
}
return $job;