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

(-)a/Koha/Import/OAI/Authorities.pm (-1 / +1 lines)
Lines 36-42 This object represents a collection of OAI-PMH records being imported as authori Link Here
36
=cut
36
=cut
37
37
38
sub _type {
38
sub _type {
39
    return 'ImportOAIAuthority';
39
    return 'ImportOaiAuthority';
40
}
40
}
41
41
42
=head3 object_class
42
=head3 object_class
(-)a/Koha/Import/OAI/Authority.pm (-1 / +1 lines)
Lines 35-41 This object represents an OAI-PMH record being imported as an authority Link Here
35
=cut
35
=cut
36
36
37
sub _type {
37
sub _type {
38
    return 'ImportOAIAuthority';
38
    return 'ImportOaiAuthority';
39
}
39
}
40
40
41
1;
41
1;
(-)a/Koha/OAI/Client/Harvester.pm (-3 lines)
Lines 32-38 use open qw( :std :utf8 ); Link Here
32
32
33
use C4::Biblio          qw( AddBiblio GetFrameworkCode ModBiblio DelBiblio );
33
use C4::Biblio          qw( AddBiblio GetFrameworkCode ModBiblio DelBiblio );
34
use C4::AuthoritiesMarc qw (AddAuthority GuessAuthTypeCode ModAuthority DelAuthority );
34
use C4::AuthoritiesMarc qw (AddAuthority GuessAuthTypeCode ModAuthority DelAuthority );
35
use C4::Log             qw( cronlogaction );
36
use HTTP::OAI;
35
use HTTP::OAI;
37
use HTTP::OAI::Metadata::OAI_DC;
36
use HTTP::OAI::Metadata::OAI_DC;
38
use Koha::DateUtils qw( dt_from_string );
37
use Koha::DateUtils qw( dt_from_string );
Lines 276-289 sub processRecord { Link Here
276
                        "Record " . $oai_record->identifier . " not deleted, biblionumber: $biblionumber ($error)" );
275
                        "Record " . $oai_record->identifier . " not deleted, biblionumber: $biblionumber ($error)" );
277
                    $status = 'in_error';
276
                    $status = 'in_error';
278
                } else {
277
                } else {
279
                    $imported_record->delete;
280
                    $self->printlog( "Record " . $oai_record->identifier . " deleted, biblionumber: $biblionumber" );
278
                    $self->printlog( "Record " . $oai_record->identifier . " deleted, biblionumber: $biblionumber" );
281
                    $status = 'deleted';
279
                    $status = 'deleted';
282
                }
280
                }
283
            } else {
281
            } else {
284
                my $authid = $imported_record->authid;
282
                my $authid = $imported_record->authid;
285
                DelAuthority( { authid => $authid } );
283
                DelAuthority( { authid => $authid } );
286
                $imported_record->delete;
287
                $self->printlog( "Record " . $oai_record->identifier . " deleted, authid: $authid" );
284
                $self->printlog( "Record " . $oai_record->identifier . " deleted, authid: $authid" );
288
                $status = 'deleted';
285
                $status = 'deleted';
289
            }
286
            }
(-)a/admin/oai_servers.pl (-3 / +3 lines)
Lines 83-89 if ( $op eq 'cud-delete_confirmed' && $id ) { Link Here
83
    }
83
    }
84
} elsif ( $op eq 'search' ) {
84
} elsif ( $op eq 'search' ) {
85
85
86
    #use searchfield only in remaining operations
86
    # use searchfield only in remaining operations
87
    $searchfield = $input->param('searchfield') || '';
87
    $searchfield = $input->param('searchfield') || '';
88
}
88
}
89
89
Lines 108-118 output_html_with_http_headers $input, $cookie, $template->output; Link Here
108
108
109
# End of main code
109
# End of main code
110
110
111
sub server_search {    #find server(s) by id or name
111
sub server_search {    # find server(s) by id or name
112
    my ( $schema, $id, $searchstring ) = @_;
112
    my ( $schema, $id, $searchstring ) = @_;
113
113
114
    return Koha::OAIServers->search(
114
    return Koha::OAIServers->search(
115
        $id ? { id => $id } : { servername => { like => $searchstring . '%' } },
115
        $id ? { oai_server_id => $id } : { servername => { like => $searchstring . '%' } },
116
    )->unblessed;
116
    )->unblessed;
117
}
117
}
118
118
(-)a/installer/data/mysql/atomicupdate/Bug-35659.pl (-3 / +3 lines)
Lines 16-22 return { Link Here
16
              `dataformat` enum('oai_dc','marc-xml', 'marcxml') NOT NULL DEFAULT 'oai_dc' COMMENT 'data format',
16
              `dataformat` enum('oai_dc','marc-xml', 'marcxml') NOT NULL DEFAULT 'oai_dc' COMMENT 'data format',
17
              `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'server contains bibliographic or authority records',
17
              `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'server contains bibliographic or authority records',
18
              `add_xslt` longtext DEFAULT NULL COMMENT 'zero or more paths to XSLT files to be processed on the search results',
18
              `add_xslt` longtext DEFAULT NULL COMMENT 'zero or more paths to XSLT files to be processed on the search results',
19
              PRIMARY KEY (`id`)
19
              PRIMARY KEY (`oai_server_id`)
20
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
20
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
21
        }
21
        }
22
        );
22
        );
Lines 32-38 return { Link Here
32
              `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'is the record bibliographic or authority',
32
              `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'is the record bibliographic or authority',
33
              `datestamp` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest',
33
              `datestamp` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest',
34
              `last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
34
              `last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
35
              PRIMARY KEY (id),
35
              PRIMARY KEY (`import_oai_biblio_id`),
36
              KEY biblionumber (biblionumber),
36
              KEY biblionumber (biblionumber),
37
              CONSTRAINT FK_import_oai_biblios_1 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE NO ACTION
37
              CONSTRAINT FK_import_oai_biblios_1 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE NO ACTION
38
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
38
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Lines 49-55 return { Link Here
49
              `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'is the record bibliographic or authority',
49
              `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'is the record bibliographic or authority',
50
              `datestamp` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest',
50
              `datestamp` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest',
51
              `last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
51
              `last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
52
              PRIMARY KEY (id),
52
              PRIMARY KEY (`import_oai_authority_id`),
53
              KEY authid (authid),
53
              KEY authid (authid),
54
              CONSTRAINT FK_import_oai_authorities_1 FOREIGN KEY (authid) REFERENCES auth_header (authid) ON DELETE CASCADE ON UPDATE NO ACTION
54
              CONSTRAINT FK_import_oai_authorities_1 FOREIGN KEY (authid) REFERENCES auth_header (authid) ON DELETE CASCADE ON UPDATE NO ACTION
55
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
55
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
(-)a/installer/data/mysql/kohastructure.sql (-6 / +6 lines)
Lines 4859-4872 DROP TABLE IF EXISTS `oai_servers`; Link Here
4859
/*!40101 SET @saved_cs_client     = @@character_set_client */;
4859
/*!40101 SET @saved_cs_client     = @@character_set_client */;
4860
/*!40101 SET character_set_client = utf8 */;
4860
/*!40101 SET character_set_client = utf8 */;
4861
CREATE TABLE `oai_servers` (
4861
CREATE TABLE `oai_servers` (
4862
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha',
4862
  `oai_server_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha',
4863
  `endpoint` varchar(255) NOT NULL COMMENT 'OAI endpoint (host + port + path)',
4863
  `endpoint` varchar(255) NOT NULL COMMENT 'OAI endpoint (host + port + path)',
4864
  `oai_set` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest',
4864
  `oai_set` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest',
4865
  `servername` longtext NOT NULL COMMENT 'name given to the target by the library',
4865
  `servername` longtext NOT NULL COMMENT 'name given to the target by the library',
4866
  `dataformat` enum('oai_dc','marc-xml', 'marcxml') NOT NULL DEFAULT 'oai_dc' COMMENT 'data format',
4866
  `dataformat` enum('oai_dc','marc-xml', 'marcxml') NOT NULL DEFAULT 'oai_dc' COMMENT 'data format',
4867
  `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'server contains bibliographic or authority records',
4867
  `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'server contains bibliographic or authority records',
4868
  `add_xslt` longtext DEFAULT NULL COMMENT 'zero or more paths to XSLT files to be processed on the search results',
4868
  `add_xslt` longtext DEFAULT NULL COMMENT 'zero or more paths to XSLT files to be processed on the search results',
4869
  PRIMARY KEY (`id`)
4869
  PRIMARY KEY (`oai_server_id`)
4870
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4870
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4871
4871
4872
--
4872
--
Lines 4877-4890 DROP TABLE IF EXISTS `import_oai_biblios`; Link Here
4877
/*!40101 SET @saved_cs_client     = @@character_set_client */;
4877
/*!40101 SET @saved_cs_client     = @@character_set_client */;
4878
/*!40101 SET character_set_client = utf8 */;
4878
/*!40101 SET character_set_client = utf8 */;
4879
CREATE TABLE `import_oai_biblios` (
4879
CREATE TABLE `import_oai_biblios` (
4880
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha',
4880
  `import_oai_biblio_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha',
4881
  `biblionumber` int(11) NOT NULL COMMENT 'unique identifier assigned to each koha record',
4881
  `biblionumber` int(11) NOT NULL COMMENT 'unique identifier assigned to each koha record',
4882
  `identifier` varchar(255) NOT NULL COMMENT 'OAI record identifier',
4882
  `identifier` varchar(255) NOT NULL COMMENT 'OAI record identifier',
4883
  `repository` varchar(255) NOT NULL COMMENT 'OAI repository',
4883
  `repository` varchar(255) NOT NULL COMMENT 'OAI repository',
4884
  `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'is the record bibliographic or authority',
4884
  `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'is the record bibliographic or authority',
4885
  `datestamp` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest',
4885
  `datestamp` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest',
4886
  `last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
4886
  `last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
4887
  PRIMARY KEY (id),
4887
  PRIMARY KEY (import_oai_biblio_id),
4888
  KEY biblionumber (biblionumber),
4888
  KEY biblionumber (biblionumber),
4889
  CONSTRAINT FK_import_oai_biblios_1 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE NO ACTION
4889
  CONSTRAINT FK_import_oai_biblios_1 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE NO ACTION
4890
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4890
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Lines 4897-4910 DROP TABLE IF EXISTS `import_oai_authorities`; Link Here
4897
/*!40101 SET @saved_cs_client     = @@character_set_client */;
4897
/*!40101 SET @saved_cs_client     = @@character_set_client */;
4898
/*!40101 SET character_set_client = utf8 */;
4898
/*!40101 SET character_set_client = utf8 */;
4899
CREATE TABLE `import_oai_authorities` (
4899
CREATE TABLE `import_oai_authorities` (
4900
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha',
4900
  `import_oai_authority_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha',
4901
  `authid` bigint(20) unsigned NOT NULL COMMENT 'unique identifier assigned to each koha record',
4901
  `authid` bigint(20) unsigned NOT NULL COMMENT 'unique identifier assigned to each koha record',
4902
  `identifier` varchar(255) NOT NULL COMMENT 'OAI record identifier',
4902
  `identifier` varchar(255) NOT NULL COMMENT 'OAI record identifier',
4903
  `repository` varchar(255) NOT NULL COMMENT 'OAI repository',
4903
  `repository` varchar(255) NOT NULL COMMENT 'OAI repository',
4904
  `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'is the record bibliographic or authority',
4904
  `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'is the record bibliographic or authority',
4905
  `datestamp` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest',
4905
  `datestamp` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest',
4906
  `last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
4906
  `last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
4907
  PRIMARY KEY (id),
4907
  PRIMARY KEY (import_oai_authority_id),
4908
  KEY authid (authid),
4908
  KEY authid (authid),
4909
  CONSTRAINT FK_import_oai_authorities_1 FOREIGN KEY (authid) REFERENCES auth_header (authid) ON DELETE CASCADE ON UPDATE NO ACTION
4909
  CONSTRAINT FK_import_oai_authorities_1 FOREIGN KEY (authid) REFERENCES auth_header (authid) ON DELETE CASCADE ON UPDATE NO ACTION
4910
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4910
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/oai_servers.tt (-8 / +8 lines)
Lines 70-76 Link Here
70
        [% INCLUDE 'csrf-token.inc' %]
70
        [% INCLUDE 'csrf-token.inc' %]
71
        [% IF op == 'edit' %]
71
        [% IF op == 'edit' %]
72
            <h1>Modify OAI repository</h1>
72
            <h1>Modify OAI repository</h1>
73
            <input type="hidden" name="id" value="[% server.id | html %]" />
73
            <input type="hidden" name="id" value="[% server.oai_server_id | html %]" />
74
        [% ELSE %]
74
        [% ELSE %]
75
            <h1>New OAI repository</h1>
75
            <h1>New OAI repository</h1>
76
        [% END %]
76
        [% END %]
Lines 138-145 Link Here
138
        <tbody>
138
        <tbody>
139
        [% FOREACH loo IN loop %]
139
        [% FOREACH loo IN loop %]
140
            <tr>
140
            <tr>
141
            <td>[% loo.id | html %]</td>
141
            <td>[% loo.oai_server_id | html %]</td>
142
            <td><a href="/cgi-bin/koha/admin/oai_servers.pl?op=edit&amp;id=[% loo.id | uri %]">[% loo.servername | html %]</a></td><td>[% loo.endpoint | html %]</td><td>[% loo.oai_set | html %]</td>
142
            <td><a href="/cgi-bin/koha/admin/oai_servers.pl?op=edit&amp;id=[% loo.oai_server_id | uri %]">[% loo.servername | html %]</a></td><td>[% loo.endpoint | html %]</td><td>[% loo.oai_set | html %]</td>
143
            <td>[% loo.dataformat | html %]</td>
143
            <td>[% loo.dataformat | html %]</td>
144
            <td>[% IF ( loo.recordtype == 'biblio' )  %]
144
            <td>[% IF ( loo.recordtype == 'biblio' )  %]
145
                <span>Bibliographic</span>
145
                <span>Bibliographic</span>
Lines 153-166 Link Here
153
                        Actions <b class="caret"></b>
153
                        Actions <b class="caret"></b>
154
                    </a>
154
                    </a>
155
                    <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="reportactions[% savedreport.id | html %]">
155
                    <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="reportactions[% savedreport.id | html %]">
156
                        <li><a href="/cgi-bin/koha/admin/oai_servers.pl?op=edit&amp;id=[% loo.id | uri %]"><i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit</a></li>
156
                        <li><a href="/cgi-bin/koha/admin/oai_servers.pl?op=edit&amp;id=[% loo.oai_server_id | uri %]"><i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit</a></li>
157
                        <li><a href="/cgi-bin/koha/admin/oai_servers.pl?op=add&amp;id=[% loo.id | uri %]"><i class="fa fa-copy"></i> Copy</a></li>
157
                        <li><a href="/cgi-bin/koha/admin/oai_servers.pl?op=add&amp;id=[% loo.oai_server_id | uri %]"><i class="fa fa-copy"></i> Copy</a></li>
158
                        <li>
158
                        <li>
159
                            <a href="#" class="delete" data-formid="server_row_[% loo.id | uri %]" data-servername="[% loo.servername | html %]"><i class="fa fa-trash-can"></i> Delete</a>
159
                            <a href="#" class="delete" data-formid="server_row_[% loo.oai_server_id | uri %]" data-servername="[% loo.servername | html %]"><i class="fa fa-trash-can"></i> Delete</a>
160
                            <form id="server_row_[% loo.id | uri %]" action="/cgi-bin/koha/admin/oai_servers.pl" method="post">
160
                            <form id="server_row_[% loo.oai_server_id | uri %]" action="/cgi-bin/koha/admin/oai_servers.pl" method="post">
161
                                [% INCLUDE 'csrf-token.inc' %]
161
                                [% INCLUDE 'csrf-token.inc' %]
162
                                <input type="hidden" name="op" value="cud-delete_confirmed">
162
                                <input type="hidden" name="op" value="cud-delete_confirmed">
163
                                <input type="hidden" name="id" value="[% loo.id | uri %]">
163
                                <input type="hidden" name="id" value="[% loo.oai_server_id | uri %]">
164
                            </form>
164
                            </form>
165
                        </li>
165
                        </li>
166
166
(-)a/t/db_dependent/Koha/OAIHarvester.t (-6 / +148 lines)
Lines 18-25 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 9;
21
use Test::More tests => 24;
22
use Test::Exception;
22
use Test::Exception;
23
use File::Temp qw/tempfile/;
23
24
24
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
25
use HTTP::OAI;
26
use HTTP::OAI;
Lines 36-42 my $builder = t::lib::TestBuilder->new; Link Here
36
37
37
$schema->storage->txn_begin;
38
$schema->storage->txn_begin;
38
39
39
my $new_oai_1 = Koha::OAIServer->new(
40
my $new_oai_biblio = Koha::OAIServer->new(
40
    {
41
    {
41
        endpoint   => 'my_host1.org',
42
        endpoint   => 'my_host1.org',
42
        oai_set    => 'set1',
43
        oai_set    => 'set1',
Lines 47-53 my $new_oai_1 = Koha::OAIServer->new( Link Here
47
    }
48
    }
48
)->store;
49
)->store;
49
50
50
my $harvester = Koha::OAI::Client::Harvester->new( { server => $new_oai_1, verbose => 1, days => 1, force => 1 } );
51
my $harvester = Koha::OAI::Client::Harvester->new( { server => $new_oai_biblio, verbose => 1, days => 1, force => 1 } );
51
52
52
my $record =
53
my $record =
53
    '<metadata xmlns="http://www.openarchives.org/OAI/2.0/"><oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"><dc:title>Pièces diverses </dc:title><dc:identifier>ARCH/0320 [cote]</dc:identifier><dc:relation>FR-920509801 [RCR établissement]</dc:relation><dc:relation>Central obrera boliviana [Fonds ou collection]</dc:relation><dc:format>1 carton</dc:format><dc:date>1971/2000</dc:date><dc:type>Archives et manuscrits</dc:type></oai_dc:dc></metadata>';
54
    '<metadata xmlns="http://www.openarchives.org/OAI/2.0/"><oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"><dc:title>Pièces diverses </dc:title><dc:identifier>ARCH/0320 [cote]</dc:identifier><dc:relation>FR-920509801 [RCR établissement]</dc:relation><dc:relation>Central obrera boliviana [Fonds ou collection]</dc:relation><dc:format>1 carton</dc:format><dc:date>1971/2000</dc:date><dc:type>Archives et manuscrits</dc:type></oai_dc:dc></metadata>';
Lines 77-83 is( $status, 'added', 'Record is added' ); Link Here
77
$status = $harvester->processRecord($r);
78
$status = $harvester->processRecord($r);
78
is( $status, 'updated', 'When force is used, record is updated' );
79
is( $status, 'updated', 'When force is used, record is updated' );
79
80
80
$harvester = Koha::OAI::Client::Harvester->new( { server => $new_oai_1, verbose => 1, days => 1, force => 0 } );
81
$harvester = Koha::OAI::Client::Harvester->new( { server => $new_oai_biblio, verbose => 1, days => 1, force => 0 } );
81
$status    = $harvester->processRecord($r);
82
$status    = $harvester->processRecord($r);
82
is( $status, 'skipped', 'When force is not used, record is skipped (already up to date)' );
83
is( $status, 'skipped', 'When force is not used, record is skipped (already up to date)' );
83
84
Lines 86-92 $status = $harvester->processRecord($r); Link Here
86
is( $status, 'updated', 'When force is not used, record is updated if newer' );
87
is( $status, 'updated', 'When force is not used, record is updated if newer' );
87
88
88
my $imported_record = Koha::Import::OAI::Biblios->find( { identifier => 'oai:myarchive.org:oid-234' } );
89
my $imported_record = Koha::Import::OAI::Biblios->find( { identifier => 'oai:myarchive.org:oid-234' } );
89
my $added_datestamp = $imported_record->datestamp;
90
my $added_datestamp = '2017-05-10T09:18:13Z';
91
$imported_record->update(
92
    {
93
        datestamp => $added_datestamp,
94
    }
95
);
96
90
$r->header->datestamp(undef);
97
$r->header->datestamp(undef);
91
$status          = $harvester->processRecord($r);
98
$status          = $harvester->processRecord($r);
92
$imported_record = Koha::Import::OAI::Biblios->find( { identifier => 'oai:myarchive.org:oid-234' } );
99
$imported_record = Koha::Import::OAI::Biblios->find( { identifier => 'oai:myarchive.org:oid-234' } );
Lines 96-99 isnt( Link Here
96
    'local datestamp is updated even if there is no datestamp in incoming record'
103
    'local datestamp is updated even if there is no datestamp in incoming record'
97
);
104
);
98
105
106
$r->header->status('deleted');
107
$status = $harvester->processRecord($r);
108
is( $status, 'deleted', 'When a record is marked to be deleted, status is deleted' );
109
110
$imported_record = Koha::Import::OAI::Biblios->find( { identifier => 'oai:myarchive.org:oid-234' } );
111
is( $imported_record, undef, 'Record has been deleted' );
112
113
$status = $harvester->processRecord($r);
114
is( $status, 'skipped', 'Status is skipped for already deleted record' );
115
116
# Authorities
117
my $file         = xsl_file();
118
my $new_oai_auth = Koha::OAIServer->new(
119
    {
120
        endpoint   => 'my_host1.org',
121
        oai_set    => 'set1',
122
        servername => 'my_test_1',
123
        dataformat => 'oai_dc',
124
        recordtype => 'authority',
125
        add_xslt   => $file,
126
    }
127
)->store;
128
129
$harvester = Koha::OAI::Client::Harvester->new( { server => $new_oai_auth, verbose => 1, days => 1, force => 1 } );
130
131
my $auth =
132
    '<metadata xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dc="http://purl.org/dc/elements/1.1/" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"><dc:FamilyName>Emerson</dc:FamilyName><dc:GivenName>Everett H.</dc:GivenName></oai_dc:dc></metadata>';
133
134
$r = HTTP::OAI::Record->new();
135
$r->metadata( HTTP::OAI::Metadata->new( dom => $auth ) );
136
137
$status = $harvester->processRecord($r);
138
is( $status, 'skipped', 'Authority with no identifier is skipped' );
139
140
$r->header->identifier('oai:myarchive.org:oid-161');
141
$status = $harvester->processRecord($r);
142
is( $status, 'added', 'Authority with no date is added' );
143
144
$status = $harvester->processRecord($r);
145
is( $status, 'updated', 'Authority with no date is updated' );
146
147
$status = $harvester->processRecord($r);
148
is( $status, 'updated', 'Authority with no date is updated even without force' );
149
150
$r->header->identifier('oai:myarchive.org:oid-162');
151
$r->header->datestamp('2017-05-10T09:18:13Z');
152
153
$status = $harvester->processRecord($r);
154
is( $status, 'added', 'Authority is added' );
155
156
$status = $harvester->processRecord($r);
157
is( $status, 'updated', 'When force is used, authority is updated' );
158
159
$harvester = Koha::OAI::Client::Harvester->new( { server => $new_oai_auth, verbose => 1, days => 1, force => 0 } );
160
$status    = $harvester->processRecord($r);
161
is( $status, 'skipped', 'When force is not used, authority is skipped (already up to date)' );
162
163
$r->header->datestamp('2018-05-10T09:18:13Z');
164
$status = $harvester->processRecord($r);
165
is( $status, 'updated', 'When force is not used, authority is updated if newer' );
166
167
my $imported_authority = Koha::Import::OAI::Authorities->find( { identifier => 'oai:myarchive.org:oid-162' } );
168
$imported_authority->update(
169
    {
170
        datestamp => $added_datestamp,
171
    }
172
);
173
174
$r->header->datestamp(undef);
175
176
$status             = $harvester->processRecord($r);
177
$imported_authority = Koha::Import::OAI::Authorities->find( { identifier => 'oai:myarchive.org:oid-162' } );
178
$updated_datestamp  = $imported_authority->datestamp;
179
isnt(
180
    $added_datestamp, $updated_datestamp,
181
    'local datestamp is updated even if there is no datestamp in incoming authority'
182
);
183
184
$r->header->status('deleted');
185
$status = $harvester->processRecord($r);
186
is( $status, 'deleted', 'When an authority is marked to be deleted, status is deleted' );
187
188
$imported_record = Koha::Import::OAI::Biblios->find( { identifier => 'oai:myarchive.org:oid-162' } );
189
is( $imported_record, undef, 'Authority has been deleted' );
190
191
$status = $harvester->processRecord($r);
192
is( $status, 'skipped', 'Status is skipped for already deleted authority' );
193
99
$schema->storage->txn_rollback;
194
$schema->storage->txn_rollback;
100
- 
195
196
sub xsl_file {
197
    return mytempfile(
198
        q{<?xml version="1.0" encoding="UTF-8"?>
199
<xsl:stylesheet version="1.0"
200
    xmlns:dc="http://purl.org/dc/elements/1.1/"
201
    xmlns:dcterms="http://purl.org/dc/terms/1.1"
202
    xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
203
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
204
    xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/
205
        http://www.openarchives.org/OAI/2.0/oai_dc.xsd"
206
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
207
    xmlns="http://www.loc.gov/MARC21/slim"  exclude-result-prefixes="dc dcterms oai_dc">
208
209
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
210
211
    <xsl:template match="/">
212
        <collection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd" >
213
            <xsl:apply-templates />
214
        </collection>
215
    </xsl:template>
216
217
    <xsl:template match="oai_dc:dc">
218
        <record>
219
220
            <xsl:variable name="FamilyName" select="dc:FamilyName"/>
221
            <xsl:variable name="GivenName" select="dc:GivenName"/>
222
223
            <datafield tag="100" ind1="0" ind2=" ">
224
                <subfield code="a">
225
                    <xsl:value-of select="concat($FamilyName,', ',$GivenName)"/>
226
                </subfield>
227
            </datafield>
228
229
        </record>
230
   </xsl:template>
231
232
</xsl:stylesheet>
233
            }
234
    );
235
}
236
237
sub mytempfile {
238
    my ( $fh, $fn ) = tempfile( SUFFIX => '.xsl', UNLINK => 1 );
239
    print $fh $_[0] // '';
240
    close $fh;
241
    return $fn;
242
}

Return to bug 35659