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

(-)a/Koha/Exporter/Record.pm (-2 / +16 lines)
Lines 78-83 sub _get_record_for_export { Link Here
78
    my $record_type        = $params->{record_type};
78
    my $record_type        = $params->{record_type};
79
    my $record_id          = $params->{record_id};
79
    my $record_id          = $params->{record_id};
80
    my $conditions         = $params->{record_conditions};
80
    my $conditions         = $params->{record_conditions};
81
    my $set_deleted_conditions = $params->{set_deleted_record_conditions};
81
    my $dont_export_fields = $params->{dont_export_fields};
82
    my $dont_export_fields = $params->{dont_export_fields};
82
    my $clean              = $params->{clean};
83
    my $clean              = $params->{clean};
83
84
Lines 115-122 sub _get_record_for_export { Link Here
115
            }
116
            }
116
        }
117
        }
117
    }
118
    }
118
119
    return if $conditions && !_record_match_conditions($record, $conditions);
119
    return if $conditions && !_record_match_conditions($record, $conditions);
120
121
    if (
122
        $record_type ne 'deleted_bibs' &&
123
        $set_deleted_conditions &&
124
        _record_match_conditions($record, $set_deleted_conditions)
125
    ) {
126
        _record_set_deleted($record)
127
    }
128
120
    C4::Biblio::RemoveAllNsb($record) if $clean;
129
    C4::Biblio::RemoveAllNsb($record) if $clean;
121
    return $record;
130
    return $record;
122
}
131
}
Lines 144-152 sub _get_deleted_biblio_for_export { Link Here
144
        Koha::Logger->get->warn("Failed to load MARCXML for deleted biblio with biblionumber \"$biblionumber\": $@");
153
        Koha::Logger->get->warn("Failed to load MARCXML for deleted biblio with biblionumber \"$biblionumber\": $@");
145
        return;
154
        return;
146
    }
155
    }
156
    _record_set_deleted($record);
157
    return $record;
158
}
147
159
148
    # Set deleted flag (record status, position 05)
160
sub _record_set_deleted {
161
    my ($record) = @_;
149
    my $leader = $record->leader;
162
    my $leader = $record->leader;
163
    # Set deleted flag (record status, position 05)
150
    substr $leader, 5, 1, 'd';
164
    substr $leader, 5, 1, 'd';
151
    $record->leader($leader);
165
    $record->leader($leader);
152
    return $record;
166
    return $record;
(-)a/misc/export_records.pl (+13 lines)
Lines 59-64 my ( Link Here
59
    $start_accession,
59
    $start_accession,
60
    $end_accession,
60
    $end_accession,
61
    $marc_conditions,
61
    $marc_conditions,
62
    $set_deleted_marc_conditions,
62
    $embed_see_from_headings,
63
    $embed_see_from_headings,
63
    $report_id,
64
    $report_id,
64
    @report_params,
65
    @report_params,
Lines 91-96 GetOptions( Link Here
91
    'start_accession=s'       => \$start_accession,
92
    'start_accession=s'       => \$start_accession,
92
    'end_accession=s'         => \$end_accession,
93
    'end_accession=s'         => \$end_accession,
93
    'marc_conditions=s'       => \$marc_conditions,
94
    'marc_conditions=s'       => \$marc_conditions,
95
    'set_deleted_marc_conditions=s' => \$set_deleted_marc_conditions,
94
    'embed_see_from_headings' => \$embed_see_from_headings,
96
    'embed_see_from_headings' => \$embed_see_from_headings,
95
    'report_id=s'             => \$report_id,
97
    'report_id=s'             => \$report_id,
96
    'report_param=s'          => \@report_params,
98
    'report_param=s'          => \@report_params,
Lines 181-186 my @marc_conditions; Link Here
181
if ($marc_conditions) {
183
if ($marc_conditions) {
182
    @marc_conditions = _parse_marc_conditions($marc_conditions);
184
    @marc_conditions = _parse_marc_conditions($marc_conditions);
183
}
185
}
186
my @set_deleted_marc_conditions;
187
if ($set_deleted_marc_conditions) {
188
    @set_deleted_marc_conditions = _parse_marc_conditions($set_deleted_marc_conditions);
189
}
184
190
185
my $dbh = C4::Context->dbh;
191
my $dbh = C4::Context->dbh;
186
192
Lines 373-378 if ($deleted_barcodes) { Link Here
373
            record_type             => $record_type,
379
            record_type             => $record_type,
374
            record_ids              => \@record_ids,
380
            record_ids              => \@record_ids,
375
            record_conditions       => @marc_conditions ? \@marc_conditions : undef,
381
            record_conditions       => @marc_conditions ? \@marc_conditions : undef,
382
            set_deleted_record_conditions => @set_deleted_marc_conditions ? \@set_deleted_marc_conditions : undef,
376
            deleted_record_ids      => \@deleted_record_ids,
383
            deleted_record_ids      => \@deleted_record_ids,
377
            format                  => $output_format,
384
            format                  => $output_format,
378
            csv_profile_id          => $csv_profile_id,
385
            csv_profile_id          => $csv_profile_id,
Lines 519-524 Print a brief help message. Link Here
519
                                "exists(<marc_target>)" will include marc records where
526
                                "exists(<marc_target>)" will include marc records where
520
                                no <marc_target> exists.
527
                                no <marc_target> exists.
521
528
529
=item B<--set_deleted_marc_conditions>
530
531
 --set_deleted_marc_conditions=CONDITIONS Set record deleted flag for biblios with MARC
532
                                data matching CONDITIONS.Only include biblios with MARC data matching CONDITIONS.
533
                                See --marc_conditions for more information about the CONDITIONS format.
534
522
=item B<--embed_see_from_headings>
535
=item B<--embed_see_from_headings>
523
536
524
 --embed_see_from_headings      Embed see from (non-preferred form) headings in bibliographic record.
537
 --embed_see_from_headings      Embed see from (non-preferred form) headings in bibliographic record.
(-)a/t/db_dependent/Exporter/Record.t (-2 / +31 lines)
Lines 319-325 subtest '_get_biblio_for_export' => sub { Link Here
319
};
319
};
320
320
321
subtest '_get_record_for_export MARC field conditions' => sub {
321
subtest '_get_record_for_export MARC field conditions' => sub {
322
    plan tests => 11;
322
    plan tests => 13;
323
323
324
    my $biblio = $builder->build_sample_biblio(
324
    my $biblio = $builder->build_sample_biblio(
325
        {
325
        {
Lines 444-449 subtest '_get_record_for_export MARC field conditions' => sub { Link Here
444
        }
444
        }
445
    );
445
    );
446
    is( $record, undef, "Record condition \"not_exists(035a)\" should not match" );
446
    is( $record, undef, "Record condition \"not_exists(035a)\" should not match" );
447
448
    ## Deleted conditions
449
450
    $record = Koha::Exporter::Record::_get_record_for_export(
451
        {
452
            record_id => $biblionumber,
453
            set_deleted_record_conditions => [['080', 'a', '=', '12345']],
454
            record_type => 'bibs',
455
        }
456
    );
457
    is(
458
        substr($record->leader, 5, 1),
459
        'd',
460
        "Record deleted condition \"080a=12345\" should match and deleted flag should be set"
461
    );
462
463
    $record = Koha::Exporter::Record::_get_record_for_export(
464
        {
465
            record_id => $biblionumber,
466
            set_deleted_record_conditions => [['080', 'a', '!=', '12345']],
467
            record_type => 'bibs',
468
        }
469
    );
470
    # Position 5, record status, should be 'n' but Koha record created by
471
    # Koha (build_sample_biblio) for some reaso has it set it to ' '
472
    isnt(
473
        substr($record->leader, 5, 1),
474
        'd',
475
        "Record deleted condition \"080a!=12345\" should not match and deleted flag should not be set"
476
    );
447
};
477
};
448
478
449
$schema->storage->txn_rollback;
479
$schema->storage->txn_rollback;
450
- 

Return to bug 23009