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

(-)a/Koha/Authority.pm (-50 lines)
Lines 45-98 sub _type { Link Here
45
    return 'AuthHeader';
45
    return 'AuthHeader';
46
}
46
}
47
47
48
=head2 get_all_authorities_iterator
49
50
    my $it = Koha::Authority->get_all_authorities_iterator();
51
52
This will provide an iterator object that will, one by one, provide the
53
Koha::Authority of each authority.
54
55
The iterator is a Koha::MetadataIterator object.
56
57
=cut
58
59
sub get_all_authorities_iterator {
60
    my $database = Koha::Database->new();
61
    my $schema   = $database->schema();
62
    my $rs =
63
      $schema->resultset('AuthHeader')->search( { marcxml => { '!=', undef } },
64
        { columns => [qw/ authid authtypecode marcxml /] } );
65
    my $next_func = sub {
66
        my $row = $rs->next();
67
        return if !$row;
68
        my $authid       = $row->authid;
69
        my $authtypecode = $row->authtypecode;
70
        my $marcxml      = $row->marcxml;
71
72
        my $record = eval {
73
            MARC::Record->new_from_xml(
74
                StripNonXmlChars($marcxml),
75
                'UTF-8',
76
                (
77
                    C4::Context->preference("marcflavour") eq "UNIMARC"
78
                    ? "UNIMARCAUTH"
79
                    : C4::Context->preference("marcflavour")
80
                )
81
            );
82
        };
83
        confess $@ if ($@);
84
        $record->encoding('UTF-8');
85
86
        # I'm not sure why we don't use the authtypecode from the database,
87
        # but this is how the original code does it.
88
        require C4::AuthoritiesMarc;
89
        $authtypecode = C4::AuthoritiesMarc::GuessAuthTypeCode($record);
90
91
        my $auth = __PACKAGE__->new( $record, $authid, $authtypecode );
92
93
        return $auth;
94
      };
95
      return Koha::MetadataIterator->new($next_func);
96
}
97
98
1;
48
1;
(-)a/Koha/MetadataRecord/Authority.pm (-3 / +54 lines)
Lines 52-64 Create a new Koha::MetadataRecord::Authority object based on the provided record Link Here
52
=cut
52
=cut
53
53
54
sub new {
54
sub new {
55
    my $class = shift;
55
    my ( $class, $record, $params ) = @_;
56
    my $record = shift;
57
56
57
    $params //= {};
58
    my $self = $class->SUPER::new(
58
    my $self = $class->SUPER::new(
59
        {
59
        {
60
            'record' => $record,
60
            'record' => $record,
61
            'schema' => lc C4::Context->preference("marcflavour")
61
            'schema' => lc C4::Context->preference("marcflavour"),
62
            %$params,
62
        }
63
        }
63
    );
64
    );
64
65
Lines 154-157 sub authorized_heading { Link Here
154
    return;
155
    return;
155
}
156
}
156
157
158
=head2 get_all_authorities_iterator
159
160
    my $it = Koha::Authority->get_all_authorities_iterator();
161
162
This will provide an iterator object that will, one by one, provide the
163
Koha::Authority of each authority.
164
165
The iterator is a Koha::MetadataIterator object.
166
167
=cut
168
169
sub get_all_authorities_iterator {
170
    my $database = Koha::Database->new();
171
    my $schema   = $database->schema();
172
    my $rs =
173
      $schema->resultset('AuthHeader')->search( { marcxml => { '!=', undef } },
174
        { columns => [qw/ authid authtypecode marcxml /] } );
175
    my $next_func = sub {
176
        my $row = $rs->next();
177
        return if !$row;
178
        my $authid       = $row->authid;
179
        my $authtypecode = $row->authtypecode;
180
        my $marcxml      = $row->marcxml;
181
182
        my $record = eval {
183
            MARC::Record->new_from_xml(
184
                StripNonXmlChars($marcxml),
185
                'UTF-8',
186
                (
187
                    C4::Context->preference("marcflavour") eq "UNIMARC"
188
                    ? "UNIMARCAUTH"
189
                    : C4::Context->preference("marcflavour")
190
                )
191
            );
192
        };
193
        confess $@ if ($@);
194
        $record->encoding('UTF-8');
195
196
        # I'm not sure why we don't use the authtypecode from the database,
197
        # but this is how the original code does it.
198
        require C4::AuthoritiesMarc;
199
        $authtypecode = C4::AuthoritiesMarc::GuessAuthTypeCode($record);
200
201
        my $auth = __PACKAGE__->new( $record, { authid => $authid, id => $authid, authtypecode => $authtypecode } );
202
203
        return $auth;
204
      };
205
      return Koha::MetadataIterator->new($next_func);
206
}
207
157
1;
208
1;
(-)a/misc/search_tools/rebuild_elastic_search.pl (-4 / +3 lines)
Lines 84-90 Full documentation. Link Here
84
use autodie;
84
use autodie;
85
use Getopt::Long;
85
use Getopt::Long;
86
use C4::Context;
86
use C4::Context;
87
use Koha::Authority;
87
use Koha::MetadataRecord::Authority;
88
use Koha::BiblioUtils;
88
use Koha::BiblioUtils;
89
use Koha::ElasticSearch::Indexer;
89
use Koha::ElasticSearch::Indexer;
90
use MARC::Field;
90
use MARC::Field;
Lines 144-154 if ($index_authorities) { Link Here
144
        $next = sub {
144
        $next = sub {
145
            my $r = shift @biblionumbers;
145
            my $r = shift @biblionumbers;
146
            return () unless defined $r;
146
            return () unless defined $r;
147
            my $a = Koha::Authority->get_from_authid($r);
147
            my $a = Koha::MetadataRecord::Authority->get_from_authid($r);
148
            return ($r, $a->record);
148
            return ($r, $a->record);
149
        };
149
        };
150
    } else {
150
    } else {
151
        my $records = Koha::Authority->get_all_authorities_iterator();
151
        my $records = Koha::MetadataRecord::Authority->get_all_authorities_iterator();
152
        $next = sub {
152
        $next = sub {
153
            $records->next();
153
            $records->next();
154
        }
154
        }
155
- 

Return to bug 16708