Bug 19073: (bug 15758 follow-up) Dereference correct value from Koha::Object.
[koha.git] / tools / manage-marc-import.pl
index 249cabe..55707aa 100755 (executable)
@@ -63,7 +63,7 @@ my %cookies = parse CGI::Cookie($cookie);
 our $sessionID = $cookies{'CGISESSID'}->value;
 our $dbh = C4::Context->dbh;
 
-my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
+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") {
@@ -234,15 +234,24 @@ sub commit_batch {
     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,
@@ -263,16 +272,25 @@ sub commit_batch {
 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,