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

(-)a/misc/cronjobs/mana_send_pairs.pl (-21 / +36 lines)
Lines 33-68 if (C4::Context->preference("Mana") == 1){ Link Here
33
    #It is used to exlude huge borrower such as libraries or instution (because the issues won't have any connection)
33
    #It is used to exlude huge borrower such as libraries or instution (because the issues won't have any connection)
34
    my $current_issues_max = 50;
34
    my $current_issues_max = 50;
35
35
36
    #choose the field to select depending on marc flavour
37
    my $marcflavour = C4::Context->preference("marcflavour");
38
    my %fields;
39
    my %inds1;
40
    if ($marcflavour eq "UNIMARC"){
41
        %fields = (isbn => "010", issn => "011", ismn => "013", isrn => "015", isrc => "016", upc => "072", ean => "073");
42
        %inds1 = (isbn => "", issn => "", ismn => "", isrn => "", isrc => "", upc => "", ean => "");
43
    }
44
    else{
45
        #if nor UNIMARC, assume MARC21
46
        %fields = (isbn => "020", issn => "022", ismn => "024", isrn => "027", isrc => "024", upc => "024", ean => "024");
47
        %inds1 = (isbn => "", issn => "", ismn => " and \@ind1=\"2\"", isrn => "", isrc => " and \@ind1=\"0\"", upc => " and \@ind1=\"1\"", ean => " and \@ind1=\"3\"");
48
    }
49
36
    my $dbh = C4::Context->dbh;
50
    my $dbh = C4::Context->dbh;
37
    my $query_part1 = "
51
    my $query = q{
38
    SELECT
52
    SELECT
39
        ExtractValue(biblio_metadata1.metadata, '//datafield[\@tag=\"010\"]/subfield[\@code=\"a\"]') as isbn1,
53
        ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="}.$fields{isbn}.q{"}.$inds1{isbn}.q{]/subfield[@code="a"]') as isbn1,
40
        ExtractValue(biblio_metadata2.metadata, '//datafield[\@tag=\"010\"]/subfield[\@code=\"a\"]') as isbn2,
54
        ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="}.$fields{isbn}.q{"}.$inds1{isbn}.q{]/subfield[@code="a"]') as isbn2,
41
        ExtractValue(biblio_metadata1.metadata, '//datafield[\@tag=\"011\"]/subfield[\@code=\"a\"]') as issn1,
55
        ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="}.$fields{issn}.q{"}.$inds1{issn}.q{]/subfield[@code="a"]') as issn1,
42
        ExtractValue(biblio_metadata2.metadata, '//datafield[\@tag=\"011\"]/subfield[\@code=\"a\"]') as issn2,
56
        ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="}.$fields{issn}.q{"}.$inds1{issn}.q{]/subfield[@code="a"]') as issn2,
43
        ExtractValue(biblio_metadata1.metadata, '//datafield[\@tag=\"013\"]/subfield[\@code=\"a\"]') as ismn1,
57
        ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="}.$fields{ismn}.q{"}.$inds1{ismn}.q{]/subfield[@code="a"]') as ismn1,
44
        ExtractValue(biblio_metadata2.metadata, '//datafield[\@tag=\"013\"]/subfield[\@code=\"a\"]') as ismn2,
58
        ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="}.$fields{ismn}.q{"}.$inds1{ismn}.q{]/subfield[@code="a"]') as ismn2,
45
        ExtractValue(biblio_metadata1.metadata, '//datafield[\@tag=\"015\"]/subfield[\@code=\"a\"]') as isrn1,
59
        ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="}.$fields{isrn}.q{"}.$inds1{isrn}.q{]/subfield[@code="a"]') as isrn1,
46
        ExtractValue(biblio_metadata2.metadata, '//datafield[\@tag=\"015\"]/subfield[\@code=\"a\"]') as isrn2,
60
        ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="}.$fields{isrn}.q{"}.$inds1{isrn}.q{]/subfield[@code="a"]') as isrn2,
47
        ExtractValue(biblio_metadata1.metadata, '//datafield[\@tag=\"016\"]/subfield[\@code=\"a\"]') as isrc1,
61
        ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="}.$fields{isrc}.q{"}.$inds1{isrc}.q{]/subfield[@code="a"]') as isrc1,
48
        ExtractValue(biblio_metadata2.metadata, '//datafield[\@tag=\"016\"]/subfield[\@code=\"a\"]') as isrc2,
62
        ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="}.$fields{isrc}.q{"}.$inds1{isrc}.q{]/subfield[@code="a"]') as isrc2,
49
        ExtractValue(biblio_metadata1.metadata, '//datafield[\@tag=\"072\"]/subfield[\@code=\"a\"]') as upc1,
63
        ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="}.$fields{upc}.q{"}.$inds1{upc}.q{]/subfield[@code="a"]') as upc1,
50
        ExtractValue(biblio_metadata2.metadata, '//datafield[\@tag=\"072\"]/subfield[\@code=\"a\"]') as upc2,
64
        ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="}.$fields{upc}.q{"}.$inds1{upc}.q{]/subfield[@code="a"]') as upc2,
51
        ExtractValue(biblio_metadata1.metadata, '//datafield[\@tag=\"073\"]/subfield[\@code=\"a\"]') as ean1,
65
        ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="}.$fields{ean}.q{"}.$inds1{ean}.q{]/subfield[@code="a"]') as ean1,
52
        ExtractValue(biblio_metadata2.metadata, '//datafield[\@tag=\"073\"]/subfield[\@code=\"a\"]') as ean2
66
        ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="}.$fields{ean}.q{"}.$inds1{ean}.q{]/subfield[@code="a"]') as ean2
53
    FROM
67
    FROM
54
        issues AS issues1
68
        issues AS issues1
55
    JOIN
69
    JOIN
56
        (SELECT borrowernumber FROM issues GROUP BY borrowernumber HAVING COUNT(*) < $current_issues_max) AS number ON number.borrowernumber=issues1.borrowernumber
70
        (SELECT borrowernumber FROM issues GROUP BY borrowernumber HAVING COUNT(*) < $current_issues_max) AS number ON number.borrowernumber=issues1.borrowernumber
57
    JOIN
71
    LEFT JOIN
58
        issues AS issues2 ON issues1.borrowernumber=issues2.borrowernumber
72
        issues AS issues2 ON issues1.borrowernumber=issues2.borrowernumber
59
    JOIN
73
    LEFT JOIN
60
        items AS items1 ON issues1.itemnumber=items1.itemnumber
74
        items AS items1 ON issues1.itemnumber=items1.itemnumber
61
    JOIN
75
    LEFT JOIN
62
        biblio_metadata AS biblio_metadata1 ON items1.biblionumber=biblio_metadata1.biblionumber
76
        biblio_metadata AS biblio_metadata1 ON items1.biblionumber=biblio_metadata1.biblionumber
63
    JOIN
77
    LEFT JOIN
64
        items AS items2 ON issues2.itemnumber=items2.itemnumber
78
        items AS items2 ON issues2.itemnumber=items2.itemnumber
65
    JOIN
79
    LEFT JOIN
66
        biblio_metadata AS biblio_metadata2 ON items2.biblionumber=biblio_metadata2.biblionumber
80
        biblio_metadata AS biblio_metadata2 ON items2.biblionumber=biblio_metadata2.biblionumber
67
    WHERE
81
    WHERE
68
        issues1.issuedate LIKE ?
82
        issues1.issuedate LIKE ?
Lines 70-76 if (C4::Context->preference("Mana") == 1){ Link Here
70
        AND (DATE(issues1.issuedate) != DATE(issues2.issuedate) OR items1.biblionumber < items2.biblionumber)
84
        AND (DATE(issues1.issuedate) != DATE(issues2.issuedate) OR items1.biblionumber < items2.biblionumber)
71
        AND biblio_metadata1.format='marcxml'
85
        AND biblio_metadata1.format='marcxml'
72
        AND biblio_metadata2.format='marcxml'
86
        AND biblio_metadata2.format='marcxml'
73
    ";
87
    };
88
74
    my $query_part2 = $query_part1;
89
    my $query_part2 = $query_part1;
75
    $query_part2 =~ s/issues AS issues2/old_issues AS issues2/;
90
    $query_part2 =~ s/issues AS issues2/old_issues AS issues2/;
76
91
(-)a/opac/svc/mana/getSuggestion (-17 / +47 lines)
Lines 108-127 else{ Link Here
108
        if ($documentids) { $found = 1; };
108
        if ($documentids) { $found = 1; };
109
    }
109
    }
110
    if ($found == 0){
110
    if ($found == 0){
111
       #choose the field to select depending on marc flavour
112
        my $marcflavour = C4::Context->preference("marcflavour");
113
        my %fields;
114
        my %inds1;
115
        if ($marcflavour eq "UNIMARC"){
116
            %fields = (isbn => "010", issn => "011", ismn => "013", isrn => "015", isrc => "016", upc => "072", ean => "073");
117
            %inds1 = (isbn => "", issn => "", ismn => "", isrn => "", isrc => "", upc => "", ean => "");
118
        }
119
        else{
120
            #if nor UNIMARC, assume MARC21
121
            %fields = (isbn => "020", issn => "022", ismn => "024", isrn => "027", isrc => "024", upc => "024", ean => "024");
122
            %inds1 = (isbn => "", issn => "", ismn => " and \@ind1=\"2\"", isrn => "", isrc => " and \@ind1=\"0\"", upc => " and \@ind1=\"1\"", ean => " and \@ind1=\"3\"");
123
        }
124
111
        my $dbh = C4::Context->dbh;
125
        my $dbh = C4::Context->dbh;
112
        my $query = "
126
        my $query = q{
113
            SELECT
127
            SELECT
114
              ExtractValue(metadata, '//datafield[\@tag=\"010\"]/subfield[\@code=\"a\"]') as isbn,
128
              ExtractValue(metadata, '//datafield[@tag="}.$fields{isbn}.q{"}.$inds1{isbn}.q{]/subfield[\@code="a"]') as isbn,
115
              ExtractValue(metadata, '//datafield[\@tag=\"011\"]/subfield[\@code=\"a\"]') as issn,
129
              ExtractValue(metadata, '//datafield[@tag="}.$fields{issn}.q{"}.$inds1{issn}.q{]/subfield[\@code="a"]') as issn,
116
              ExtractValue(metadata, '//datafield[\@tag=\"013\"]/subfield[\@code=\"a\"]') as ismn,
130
              ExtractValue(metadata, '//datafield[@tag="}.$fields{ismn}.q{"}.$inds1{ismn}.q{]/subfield[@code="a"]') as ismn,
117
              ExtractValue(metadata, '//datafield[\@tag=\"015\"]/subfield[\@code=\"a\"]') as isrn,
131
              ExtractValue(metadata, '//datafield[@tag="}.$fields{isrn}.q{"}.$inds1{isrn}.q{]/subfield[@code="a"]') as isrn,
118
              ExtractValue(metadata, '//datafield[\@tag=\"016\"]/subfield[\@code=\"a\"]') as isrc,
132
              ExtractValue(metadata, '//datafield[@tag="}.$fields{isrc}.q{"}.$inds1{isrc}.q{]/subfield[@code="a"]') as isrc,
119
              ExtractValue(metadata, '//datafield[\@tag=\"072\"]/subfield[\@code=\"a\"]') as upc,
133
              ExtractValue(metadata, '//datafield[@tag="}.$fields{upc}.q{"}.$inds1{upc}.q{]/subfield[@code="a"]') as upc,
120
              ExtractValue(metadata, '//datafield[\@tag=\"073\"]/subfield[\@code=\"a\"]') as ean
134
              ExtractValue(metadata, '//datafield[@tag="}.$fields{ean}.q{"}.$inds1{ean}.q{]/subfield[@code="a"]') as ean
121
            FROM biblio_metadata
135
            FROM biblio_metadata
122
            WHERE biblionumber = ?
136
            WHERE biblionumber="}.$biblionumber.q{"
123
              AND format=\"marcxml\"
137
              AND format="marcxml"
124
        ";
138
        };
125
        my $sth = $dbh->prepare( $query );
139
        my $sth = $dbh->prepare( $query );
126
        $sth->execute($biblionumber);
140
        $sth->execute($biblionumber);
127
        my $row = $sth->fetchrow_hashref;
141
        my $row = $sth->fetchrow_hashref;
Lines 154-159 else{ Link Here
154
            $idtype = "ean";
168
            $idtype = "ean";
155
            $documentids = $row->{ean};
169
            $documentids = $row->{ean};
156
        }
170
        }
171
        elsif ($row->{ean}){
172
            $idtype = "ean";
173
            $documentid = $row->{ean};
174
        }
157
        else{
175
        else{
158
            die "error: no propper identifier";
176
            die "error: no propper identifier";
159
        }
177
        }
Lines 197-207 else{ Link Here
197
215
198
        #create the list of owned suggested resources
216
        #create the list of owned suggested resources
199
        my $ownedbiblioitem;
217
        my $ownedbiblioitem;
218
        my $marcflavour = C4::Context->preference("marcflavour");
200
        foreach my $resource ( @{ $resources } ){
219
        foreach my $resource ( @{ $resources } ){
201
            my $found = 0;
220
            my $found = 0;
202
221
203
            #isbn, issn and ean can be search for with Koha::Biblioitems->search
222
            #isbn and issn can be search for with Koha::Biblioitems->search, ean too for unimarc but not for marc21
204
            if ($resource->{idtype} eq "isbn" || $resource->{idtype} eq "issn" || $resource->{idtype} eq "ean"){
223
            if ($resource->{idtype} eq "isbn" || $resource->{idtype} eq "issn" || ($resource->{idtype} eq "ean" && $marcflavour eq "UNIMARC")){
205
                #isbn processsing
224
                #isbn processsing
206
                if ( $resource->{idtype} eq "isbn" ){
225
                if ( $resource->{idtype} eq "isbn" ){
207
                    $documentid= C4::Koha::NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 1 });
226
                    $documentid= C4::Koha::NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 1 });
Lines 247-258 else{ Link Here
247
            # other id need to be search with sql
266
            # other id need to be search with sql
248
            if ($found != 1) {
267
            if ($found != 1) {
249
                my @params;
268
                my @params;
250
                my %field=("isbn" => "010", "issn" => "011", "ismn" => "013", "isrn" => "015", "isrc" => "016", "upc" => "072", "ean" => "073");
269
270
                #choose the field to select depending on marc flavour
271
                my %fields;
272
                my %inds1;
273
                if ($marcflavour eq "UNIMARC"){
274
                    %fields = (isbn => "010", issn => "011", ismn => "013", isrn => "015", isrc => "016", upc => "072", ean => "073");
275
                    %inds1 = (isbn => "", issn => "", ismn => "", isrn => "", isrc => "", upc => "", ean => "");
276
                }
277
                else{
278
                    #if nor UNIMARC, assume MARC21
279
                    %fields = (isbn => "020", issn => "022", ismn => "024", isrn => "027", isrc => "024", upc => "024", ean => "024");
280
                    %inds1 = (isbn => "", issn => "", ismn => " and \@ind1=\"2\"", isrn => "", isrc => " and \@ind1=\"0\"", upc => " and \@ind1=\"1\"", ean => " and \@ind1=\"3\"");
281
                }
251
282
252
                #pattern to be tolerent on the hyphens
283
                #pattern to be tolerent on the hyphens
253
                my $pattern="";
284
                my $pattern="";
254
                foreach my $p (split('', $resource->{documentid})){
285
                foreach my $p (split('', $resource->{documentid})){
255
                    $pattern .= "$p-*";
286
                    $pattern .= "$p-?";
256
                }
287
                }
257
288
258
                my $dbh = C4::Context->dbh;
289
                my $dbh = C4::Context->dbh;
Lines 260-266 else{ Link Here
260
                    SELECT biblioitems.biblionumber as biblionumber
291
                    SELECT biblioitems.biblionumber as biblionumber
261
                    FROM biblioitems
292
                    FROM biblioitems
262
                    LEFT JOIN biblio_metadata ON biblioitems.biblionumber=biblio_metadata.biblionumber
293
                    LEFT JOIN biblio_metadata ON biblioitems.biblionumber=biblio_metadata.biblionumber
263
                    WHERE ExtractValue(biblio_metadata.metadata, '//datafield[@tag="}.$field{$resource->{idtype}}.q{"]/subfield[@code="a"]') REGEXP "}.$pattern.q{"
294
                    WHERE ExtractValue(biblio_metadata.metadata, '//datafield[@tag="}.$fields{$resource->{idtype}}.q{"}.$inds1{$resource->{idtype}}.q{]/subfield[@code="a"]') REGEXP "}.$pattern.q{"
264
                      AND biblio_metadata.format="marcxml"
295
                      AND biblio_metadata.format="marcxml"
265
                };
296
                };
266
                my $sth = $dbh->prepare( $query );
297
                my $sth = $dbh->prepare( $query );
267
- 

Return to bug 18618