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

(-)a/C4/BackgroundJob.pm (+38 lines)
Lines 260-265 sub fetch { Link Here
260
    return $self;
260
    return $self;
261
}
261
}
262
262
263
=head2 set
264
265
=over 4
266
267
$job->set($hashref);
268
269
=back
270
271
Set some variables into the hashref.
272
These variables can be retrieved using the get method.
273
274
=cut
275
276
sub set {
277
    my ($self, $hashref) = @_;
278
    while ( my ($k, $v) = each %$hashref ) {
279
        $self->{$k} = $v;
280
    }
281
    $self->_serialize();
282
}
283
284
=head2 get
285
286
=over 4
287
288
$job->get($hashref);
289
290
=back
291
292
Get a variable which has been previously stored with the set method.
293
294
=cut
295
296
sub get {
297
    my ($self, $key) = @_;
298
    return $self->{$key};
299
}
300
263
1;
301
1;
264
__END__
302
__END__
265
303
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt (-1 / +8 lines)
Lines 64-70 $(document).ready(function(){ Link Here
64
<div id="doc3" class="yui-t7">
64
<div id="doc3" class="yui-t7">
65
    <div id="bd">
65
    <div id="bd">
66
        <div id="yui-main">
66
        <div id="yui-main">
67
            [% IF ( show ) %]<h1>Batch item modification</h1>[% ELSE %]<h1>Batch item modification results</h1>[% END %]
67
            [% IF ( show ) %]
68
              <h1>Batch item modification</h1>
69
            [% ELSE %]
70
              <h1>Batch item modification results</h1>
71
              <div class="dialog message">
72
              [% modified_items %] item(s) modified (with [% modified_fields %] fields modified)
73
              </div>
74
            [% END %]
68
[% IF ( barcode_not_unique ) %]<div class="dialog alert"><strong>Error saving item</strong>: Barcode must be unique.</div>[% END %]
75
[% IF ( barcode_not_unique ) %]<div class="dialog alert"><strong>Error saving item</strong>: Barcode must be unique.</div>[% END %]
69
[% IF ( no_next_barcode ) %]<div class="dialog alert"><strong>Error saving items</strong>: Unable to automatically determine values for barcodes. No item has been inserted.</div>[% END %]
76
[% IF ( no_next_barcode ) %]<div class="dialog alert"><strong>Error saving items</strong>: Unable to automatically determine values for barcodes. No item has been inserted.</div>[% END %]
70
[% IF ( book_on_loan ) %]<div class="dialog alert"><strong>Cannot Delete</strong>: item is checked out.</div>[% END %]
77
[% IF ( book_on_loan ) %]<div class="dialog alert"><strong>Cannot Delete</strong>: item is checked out.</div>[% END %]
(-)a/tools/batchMod.pl (-24 / +47 lines)
Lines 84-89 my $deleted_items = 0; # Number of deleted items Link Here
84
my $deleted_records = 0;   # Number of deleted records ( with no items attached )
84
my $deleted_records = 0;   # Number of deleted records ( with no items attached )
85
my $not_deleted_items = 0; # Number of items that could not be deleted
85
my $not_deleted_items = 0; # Number of items that could not be deleted
86
my @not_deleted;           # List of the itemnumbers that could not be deleted
86
my @not_deleted;           # List of the itemnumbers that could not be deleted
87
my $modified_items = 0;    # Numbers of modified items
88
my $modified_fields = 0;   # Numbers of modified fields
87
89
88
my %cookies = parse CGI::Cookie($cookie);
90
my %cookies = parse CGI::Cookie($cookie);
89
my $sessionID = $cookies{'CGISESSID'}->value;
91
my $sessionID = $cookies{'CGISESSID'}->value;
Lines 160-166 if ($op eq "action") { Link Here
160
162
161
		$job->progress($i) if $runinbackground;
163
		$job->progress($i) if $runinbackground;
162
		my $itemdata = GetItem($itemnumber);
164
		my $itemdata = GetItem($itemnumber);
163
		if ($input->param("del")){
165
        if ( $del ){
164
			my $return = DelItemCheck(C4::Context->dbh, $itemdata->{'biblionumber'}, $itemdata->{'itemnumber'});
166
			my $return = DelItemCheck(C4::Context->dbh, $itemdata->{'biblionumber'}, $itemdata->{'itemnumber'});
165
			if ($return == 1) {
167
			if ($return == 1) {
166
			    $deleted_items++;
168
			    $deleted_items++;
Lines 184-197 if ($op eq "action") { Link Here
184
                            }
186
                            }
185
                        }
187
                        }
186
		} else {
188
		} else {
187
		    if ($values_to_modify || $values_to_blank) {
189
            if ($values_to_modify || $values_to_blank) {
188
			my $localmarcitem = Item2Marc($itemdata);
190
                my $localmarcitem = Item2Marc($itemdata);
189
			UpdateMarcWith( $marcitem, $localmarcitem );
191
190
			eval{
192
                my $modified = UpdateMarcWith( $marcitem, $localmarcitem );
191
                            if ( my $item = ModItemFromMarc( $localmarcitem, $itemdata->{biblionumber}, $itemnumber ) ) {
193
                if ( $modified ) {
192
                                LostItem($itemnumber, 'MARK RETURNED', 'CHARGE FEE') if $item->{itemlost};
194
                    eval {
193
                            }
195
                        if ( my $item = ModItemFromMarc( $localmarcitem, $itemdata->{biblionumber}, $itemnumber ) ) {
194
                        };
196
                            LostItem($itemnumber, 'MARK RETURNED', 'CHARGE FEE') if $item->{itemlost};
197
                        }
198
                    };
199
                }
200
                if ( $runinbackground ) {
201
                    $modified_items++ if $modified;
202
                    $modified_fields += $modified;
203
                    $job->set({
204
                        modified_items  => $modified_items,
205
                        modified_fields => $modified_fields,
206
                    });
207
                }
195
		    }
208
		    }
196
		}
209
		}
197
		$i++;
210
		$i++;
Lines 559-579 sub BuildItemsData{ Link Here
559
# And $tag>10
572
# And $tag>10
560
sub UpdateMarcWith {
573
sub UpdateMarcWith {
561
  my ($marcfrom,$marcto)=@_;
574
  my ($marcfrom,$marcto)=@_;
562
  #warn "FROM :",$marcfrom->as_formatted;
575
    my (  $itemtag,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", "");
563
	my (  $itemtag,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", "");
576
    my $fieldfrom=$marcfrom->field($itemtag);
564
	my $fieldfrom=$marcfrom->field($itemtag);
577
    my @fields_to=$marcto->field($itemtag);
565
	my @fields_to=$marcto->field($itemtag);
578
    my $modified = 0;
566
    foreach my $subfield ($fieldfrom->subfields()){
579
    foreach my $subfield ( $fieldfrom->subfields() ) {
567
		foreach my $field_to_update (@fields_to){
580
        foreach my $field_to_update ( @fields_to ) {
568
		    if ($subfield->[1]){
581
            if ( $subfield->[1] ) {
569
			$field_to_update->update($subfield->[0]=>$subfield->[1]);
582
                unless ( $field_to_update->subfield($subfield->[0]) ~~ $subfield->[1] ) {
570
		    }
583
                    $modified++;
571
		    else {
584
                    $field_to_update->update( $subfield->[0] => $subfield->[1] );
572
			$field_to_update->delete_subfield(code=> $subfield->[0]);
585
                }
573
		    }
586
            }
574
		}
587
            else {
588
                $modified++;
589
                $field_to_update->delete_subfield( code => $subfield->[0] );
590
            }
591
        }
575
    }
592
    }
576
  #warn "TO edited:",$marcto->as_formatted;
593
    return $modified;
577
}
594
}
578
595
579
sub find_value {
596
sub find_value {
Lines 608-613 sub add_saved_job_results_to_template { Link Here
608
    my $job = C4::BackgroundJob->fetch($sessionID, $completedJobID);
625
    my $job = C4::BackgroundJob->fetch($sessionID, $completedJobID);
609
    my $results = $job->results();
626
    my $results = $job->results();
610
    add_results_to_template($template, $results);
627
    add_results_to_template($template, $results);
628
629
    my $fields = $job->get("modified_fields");
630
    my $items = $job->get("modified_items");
631
    $template->param(
632
        modified_items => $items,
633
        modified_fields => $fields,
634
    );
611
}
635
}
612
636
613
sub put_in_background {
637
sub put_in_background {
614
- 

Return to bug 10601