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

(-)a/Koha/BackgroundJob/CreateEHoldingsFromBiblios.pm (-66 / +136 lines)
Lines 47-52 sub job_type { Link Here
47
    return 'create_eholdings_from_biblios';
47
    return 'create_eholdings_from_biblios';
48
}
48
}
49
49
50
51
my $fix_coverage = sub {
52
    my $coverage = shift || q{};
53
    my @coverages = split '-', $coverage;
54
    return ($coverages[0], (@coverages > 1 ? $coverages[1] : q{}));
55
};
56
57
sub _get_unimarc_mapping {
58
    my ($biblio)          = @_;
59
    my $record            = $biblio->metadata->record;
60
    my $biblio_id         = $biblio->biblionumber;
61
    my $publication_title = $biblio->title;
62
    my $print_identifier =
63
         $record->subfield( '010', 'a' )
64
      || $record->subfield( '010', 'z' )
65
      || $record->subfield( '011', 'a' )
66
      || $record->subfield( '011', 'y' );
67
    my $online_identifier               = $print_identifier;
68
    my $date_first_issue_online         = $record->subfield( '955', 'a' );
69
    my $date_last_issue_online          = $record->subfield( '955', 'k' );
70
    my $num_first_vol_online            = $record->subfield( '955', 'd' );
71
    my $num_last_vol_online             = $record->subfield( '955', 'n' );
72
    my $num_first_issue_online          = $record->subfield( '955', 'e' );
73
    my $num_last_issue_online           = $record->subfield( '955', 'o' );
74
    my $title_url                       = $record->subfield( '856', 'u' );
75
    my $first_author                    = $biblio->author;
76
    my $embargo_info                    = $record->subfield( '371', 'a' );
77
    my $coverage_depth                  = $title_url ? 'fulltext' : 'print';
78
    my $notes                           = $record->subfield( '336', 'a' );
79
    my $publisher_name                  = $record->subfield( '214', 'c' );
80
    my $label_pos67                     = substr( $record->leader, 6, 2 );
81
    my $publication_type                = $label_pos67 eq 'am' ? 'monograph' : $label_pos67 eq 'as' ? 'serial' : '';
82
    my $date_monograph_published_print  = $record->subfield( '214', 'd' ) || substr( $record->subfield(100, 'a'), 9, 4 ) || '';
83
    my $date_monograph_published_online = $date_monograph_published_print;
84
    my $monograph_volume                = $record->subfield( '200', 'v' );
85
    my $monograph_edition               = $record->subfield( '205', 'a' );
86
    my $first_editor                    = $publisher_name;
87
    my $parent_publication_title_id     = '';                                  # FIXME ?
88
    my $preceeding_publication_title_id = '';                                  # FIXME ?
89
    my $access_type                     = $record->subfield( '856', 'y' );
90
91
    return {
92
        biblio_id                       => $biblio_id,
93
        publication_title               => $publication_title,
94
        print_identifier                => $print_identifier,
95
        online_identifier               => $online_identifier,
96
        date_first_issue_online         => $date_first_issue_online,
97
        num_first_vol_online            => $num_first_vol_online,
98
        num_first_issue_online          => $num_first_issue_online,
99
        date_last_issue_online          => $date_last_issue_online,
100
        num_last_vol_online             => $num_last_vol_online,
101
        num_last_issue_online           => $num_last_issue_online,
102
        title_url                       => $title_url,
103
        first_author                    => $first_author,
104
        embargo_info                    => $embargo_info,
105
        coverage_depth                  => $coverage_depth,
106
        notes                           => $notes,
107
        publisher_name                  => $publisher_name,
108
        publication_type                => $publication_type,
109
        date_monograph_published_print  => $date_monograph_published_print,
110
        date_monograph_published_online => $date_monograph_published_online,
111
        monograph_volume                => $monograph_volume,
112
        monograph_edition               => $monograph_edition,
113
        first_editor                    => $first_editor,
114
        parent_publication_title_id     => $parent_publication_title_id,
115
        preceeding_publication_title_id => $preceeding_publication_title_id,
116
        access_type                     => $access_type,
117
    };
118
}
119
120
sub _get_marc21_mapping {
121
    my ($biblio)          = @_;
122
    my $record            = $biblio->metadata->record;
123
    my $biblio_id         = $biblio->biblionumber;
124
    my $publication_title = $biblio->title;
125
    my $print_identifier =
126
         $record->subfield( '020', 'a' )
127
      || $record->subfield( '020', 'z' )
128
      || $record->subfield( '022', 'a' )
129
      || $record->subfield( '022', 'y' );
130
    my $online_identifier = $print_identifier;
131
    my ( $date_first_issue_online, $date_last_issue_online ) =
132
      $fix_coverage->( $record->subfield( '866', 'a' ) );
133
    my ( $num_first_vol_online, $num_last_vol_online ) =
134
      $fix_coverage->( $record->subfield( '863', 'a' ) );
135
    my ( $num_first_issue_online, $num_last_issue_online ) = ( '', '' );    # FIXME ?
136
    my $title_url                       = $record->subfield( '856', 'u' );
137
    my $first_author                    = $biblio->author;
138
    my $embargo_info                    = '';                                  # FIXME ?
139
    my $coverage_depth                  = $title_url ? 'fulltext' : 'print';
140
    my $notes                           = $record->subfield( '852', 'z' );
141
    my $publisher_name                  = $record->subfield( '260', 'b' );
142
    my $publication_type                = '';                                  # FIXME ?
143
    my $date_monograph_published_print  = '';                                  # FIXME ?
144
    my $date_monograph_published_online = '';                                  # FIXME ?
145
    my $monograph_volume                = '';                                  # FIXME ?
146
    my $monograph_edition               = '';                                  # FIXME ?
147
    my $first_editor                    = '';                                  # FIXME ?
148
    my $parent_publication_title_id     = '';                                  # FIXME ?
149
    my $preceeding_publication_title_id = '';                                  # FIXME ?
150
    my $access_type                     = '';                                  # FIXME ?
151
152
    return {
153
        biblio_id                       => $biblio_id,
154
        publication_title               => $publication_title,
155
        print_identifier                => $print_identifier,
156
        online_identifier               => $online_identifier,
157
        date_first_issue_online         => $date_first_issue_online,
158
        num_first_vol_online            => $num_first_vol_online,
159
        num_first_issue_online          => $num_first_issue_online,
160
        date_last_issue_online          => $date_last_issue_online,
161
        num_last_vol_online             => $num_last_vol_online,
162
        num_last_issue_online           => $num_last_issue_online,
163
        title_url                       => $title_url,
164
        first_author                    => $first_author,
165
        embargo_info                    => $embargo_info,
166
        coverage_depth                  => $coverage_depth,
167
        notes                           => $notes,
168
        publisher_name                  => $publisher_name,
169
        publication_type                => $publication_type,
170
        date_monograph_published_print  => $date_monograph_published_print,
171
        date_monograph_published_online => $date_monograph_published_online,
172
        monograph_volume                => $monograph_volume,
173
        monograph_edition               => $monograph_edition,
174
        first_editor                    => $first_editor,
175
        parent_publication_title_id     => $parent_publication_title_id,
176
        preceeding_publication_title_id => $preceeding_publication_title_id,
177
        access_type                     => $access_type,
178
    };
179
}
180
50
=head3 process
181
=head3 process
51
182
52
Process the import.
183
Process the import.
Lines 86-97 sub process { Link Here
86
        return $self->finish( $data );
217
        return $self->finish( $data );
87
    }
218
    }
88
219
89
    my $fix_coverage = sub {
90
        my $coverage = shift || q{};
91
        my @coverages = split '-', $coverage;
92
        return ($coverages[0], (@coverages > 1 ? $coverages[1] : q{}));
93
    };
94
95
    my %existing_biblio_ids = map {
220
    my %existing_biblio_ids = map {
96
        my $resource = $_;
221
        my $resource = $_;
97
        map { $_->biblio_id => $resource->resource_id } $resource->title
222
        map { $_->biblio_id => $resource->resource_id } $resource->title
Lines 115-180 sub process { Link Here
115
                return;
240
                return;
116
            }
241
            }
117
            my $biblio = Koha::Biblios->find($biblio_id);
242
            my $biblio = Koha::Biblios->find($biblio_id);
118
            my $record = $biblio->metadata->record;
243
            my $eholding_title = C4::Context->preference('marcflavour') eq 'UNIMARC'
119
            my $publication_title = $biblio->title;
244
                ? _get_unimarc_mapping($biblio)
120
            my $print_identifier =
245
                : _get_marc21_mapping($biblio);
121
                 $record->subfield( '020', 'a' )
122
              || $record->subfield( '020', 'z' )
123
              || $record->subfield( '022', 'a' )
124
              || $record->subfield( '022', 'y' );
125
            my $online_identifier = $print_identifier;
126
            my ( $date_first_issue_online, $date_last_issue_online ) =
127
              $fix_coverage->( $record->subfield( '866', 'a' ) );
128
            my ( $num_first_vol_online, $num_last_vol_online ) =
129
              $fix_coverage->( $record->subfield( '863', 'a' ) );
130
            my ( $num_first_issue_online, $num_last_issue_online ) =
131
              ( '', '' );    # FIXME ?
132
            my $title_url = $record->subfield( '856', 'u' );
133
            my $first_author = $biblio->author;
134
            my $embargo_info     = '';                                 # FIXME ?
135
            my $coverage_depth   = $title_url ? 'fulltext' : 'print';
136
            my $notes            = $record->subfield( '852', 'z' );
137
            my $publisher_name   = $record->subfield( '260', 'b' );
138
            my $publication_type = '';                                 # FIXME ?
139
            my $date_monograph_published_print  = '';                  # FIXME ?
140
            my $date_monograph_published_online = '';                  # FIXME ?
141
            my $monograph_volume                = '';                  # FIXME ?
142
            my $monograph_edition               = '';                  # FIXME ?
143
            my $first_editor                    = '';                  # FIXME ?
144
            my $parent_publication_title_id     = '';                  # FIXME ?
145
            my $preceeding_publication_title_id = '';                  # FIXME ?
146
            my $access_type                     = '';                  # FIXME ?
147
148
            my $eholding_title = {
149
                biblio_id                       => $biblio_id,
150
                publication_title               => $publication_title,
151
                print_identifier                => $print_identifier,
152
                online_identifier               => $online_identifier,
153
                date_first_issue_online         => $date_first_issue_online,
154
                num_first_vol_online            => $num_first_vol_online,
155
                num_first_issue_online          => $num_first_issue_online,
156
                date_last_issue_online          => $date_last_issue_online,
157
                num_last_vol_online             => $num_last_vol_online,
158
                num_last_issue_online           => $num_last_issue_online,
159
                title_url                       => $title_url,
160
                first_author                    => $first_author,
161
                embargo_info                    => $embargo_info,
162
                coverage_depth                  => $coverage_depth,
163
                notes                           => $notes,
164
                publisher_name                  => $publisher_name,
165
                publication_type                => $publication_type,
166
                date_monograph_published_print  => $date_monograph_published_print,
167
                date_monograph_published_online => $date_monograph_published_online,
168
                monograph_volume                => $monograph_volume,
169
                monograph_edition               => $monograph_edition,
170
                first_editor                    => $first_editor,
171
                parent_publication_title_id     => $parent_publication_title_id,
172
                preceeding_publication_title_id => $preceeding_publication_title_id,
173
                access_type                     => $access_type,
174
              };
175
              $eholding_title = Koha::ERM::EHoldings::Title->new($eholding_title)->store;
176
              Koha::ERM::EHoldings::Resource->new({ title_id => $eholding_title->title_id, package_id => $package_id })->store;
177
246
247
            $eholding_title = Koha::ERM::EHoldings::Title->new($eholding_title)->store;
248
            Koha::ERM::EHoldings::Resource->new({ title_id => $eholding_title->title_id, package_id => $package_id })->store;
178
            $report->{total_success}++;
249
            $report->{total_success}++;
179
        } catch {
250
        } catch {
180
            push @messages, {
251
            push @messages, {
181
- 

Return to bug 32782