Giter VIP home page Giter VIP logo

opencultureconsulting / simple-oai-pmh Goto Github PK

View Code? Open in Web Editor NEW
14.0 6.0 8.0 412 KB

This is a stand-alone OAI-PMH data provider. It serves records in any metadata format from directories of XML files using the directory name as metadata prefix, the filename as identifier and the filemtime as datestamp. 0-byte files are considered deleted records and handled accordingly. Resumption tokens are managed using files.

Home Page: https://demo.opencultureconsulting.com/simple-oai-pmh/?verb=Identify

License: GNU General Public License v3.0

PHP 64.55% XSLT 35.45%
oai oai-pmh data-provider code4lib repository php

simple-oai-pmh's Introduction

Simple OAI-PMH 2.0 Data Provider

This is a stand-alone and easy to install data provider implementing the Open Archives Initiative's Protocol for Metadata Harvesting (OAI-PMH). It serves records in any metadata format from directories of XML files using the directory name as metadataPrefix, the filename as identifier and the filemtime as timestamp. 0-byte files are considered deleted records and handled accordingly. Resumption tokens are managed using files. Sets are currently not supported.

Just put the records as XML files in the data directory, adjust a few configuration settings and you are ready to go!

A demo installation can be found here.

Codacy Badge

Installation

  1. Run composer create-project opencultureconsulting/simple-oai-pmh <path>.

  2. Create a data directory in a location not publicly accessible (i. e. outside of <path>). Create a subdirectory inside the specified data directory for every format (i. e. metadataPrefix) you want to provide.

  3. Copy Configuration/Main.template.php to Configuration/Main.php and edit the settings according to your preferences. Don't forget pointing $config['dataDirectory'] to your newly created data directory.

  4. Put the records into the respective directories according to their format. Each record has to be a separate XML file with its identifier as filename (e. g. the file 12345678.xml can be adressed using the identifier 12345678). Optionally you can maintain deletions by keeping 0-byte files for deleted records.

  5. Congratulations! Now you are running your own Simple OAI-PMH 2.0 Data Provider. You can access the entry point by calling index.php?verb=Identify in your browser.

Upgrading

  1. Backup Configuration/Main.php!

  2. Delete <path> and re-install by running composer create-project opencultureconsulting/simple-oai-pmh <path>.

  3. Move your configuration back into Configuration/Main.php.

  4. Congratulations! Now you are running the newest version of the Simple OAI-PMH 2.0 Data Provider. You can access the entry point by calling index.php?verb=Identify in your browser.

Updating

Updating your records is just as easy with the update.php script! The script automatically handles deletions by maintaining 0-byte files for deleted records. Just call php update.php from the command line and follow the instructions. (Of course, you can simply replace the records manually as well.)

History

This project was originally initiated in 2002 by Heinrich Stamerjohanns at University of Oldenburg. His latest implementation can still be found via the Internet Archive's Wayback Machine.

It was then modified in 2011 by Jianfeng Li at University of Adelaide for The Plant Accelerator. The modified version can be found in the Google Code Archive.

In 2013 Daniel Neis Araujo at Federal University of Santa Catarina modified the project again in order to integrate it with Moodle. His implementation can be found on GitHub. In 2014 Kazimierz Pietruszewski provided some further bugfixes.

The current implementation was derived from the latter in 2017 by Sebastian Meyer at Open Culture Consulting for the German Literature Archive. It is a stand-alone version focused on easy deployment and file based record handling.

simple-oai-pmh's People

Contributors

danielneis avatar scottlimmer avatar sebastian-meyer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

simple-oai-pmh's Issues

Possible bug in Server.php

Getting the following error with PHP 8.2 and the following request:
?verb=ListRecords&metadataPrefix=oai_dc&from=2023-01-15T00:00:00Z&until=2023-01-25T23:59:59Z

The error is:

stderr: Stack trace:
stderr: #0 /oai/Classes/Server.php(292): array_sum(false)
stderr: #1 /oai/Classes/Server.php(187): OCC\\OAI2\\Server->checkDateFormat('2023-01-15T00:0...')
stderr: #2 [internal function]: OCC\\OAI2\\Server->ListRecords()
stderr: #3 /oai/Classes/Server.php(56): call_user_func(Array)
stderr: #4 /oai/index.php(73): OCC\\OAI2\\Server->__construct('...', Array, Array, Array, Array)
stderr: #5 {main}
stderr:   thrown in /oai/Classes/Server.php on line 292
stderr: PHP Fatal error:  Uncaught TypeError: array_sum(): Argument #1 ($array) must be of type array, bool given in /oai/Classes/Server.php:292

I looked at the code in Server.php, line 292 here:
https://github.com/opencultureconsulting/oai_pmh/blob/master/Classes/Server.php#L292

 return ($datetime !== false) && !array_sum($datetime->getLastErrors());

The docs for "getLastErrors()" say that in case there are no errors a boolean is returned:
https://www.php.net/manual/en/datetime.getlasterrors.php

Returns array containing info about warnings and errors, or false if there are neither warnings nor errors.

I changed my copy of the code as follows and it is working now:

return ($datetime !== false) && ($datetime->getLastErrors() == false);

I can provide a pull request but I am not that familiar with PHP so I am not sure if this is a real bug.

PHP 8.1 compatibility / createElement Deprecated Warning

Hi,

the current code base throws a PHP warrning if ?verb=ListMetadataFormats is called:
Deprecated: DOMDocument::createElement(): Passing null to parameter #2 ($value) of type string is deprecated in ./Classes/Response.php on line 64.

The is caused by the function public function addChild() which tries to create an element with an empty string as value. In my understanding this triggers a warning since PHP 8.1.

To create an empty element you can simply omit the value. Quick workaround (Response.php from line 63):

public function addChild($mom_node, $name, $value = '') {
        if (!empty($value)) {
                $added_node = $this->doc->createElement($name, $value);
        } else {
                $added_node = $this->doc->createElement($name);
        }
        $added_node = $mom_node->appendChild($added_node);
        return $added_node;
}

There might be a nicer fix to this, though.

POST requests not handled correctly

openarchives.org validation fails on my OAI repository based on opencultureconsulting / oai_pmh : POST requests are not handled correctly.

### Checking that HTTP POST requests are handled correctly
REQUEST https://oai.telemillevaches.net/ POST verb:Identify
FAIL POST test 1 for Identify was unsuccessful, an OAI error response was received
REQUEST https://oai.telemillevaches.net/ POST identifier:oai:oai.telemillevaches.net:2021-12-07:documentaire:exode-urbain-bonne-nouvelle-ou-nouveau-desastre metadataPrefix:oai_dc verb:GetRecord
FAIL POST test 2 for GetRecord was unsuccessful, an OAI error response was received

http://www.openarchives.org/Register/ValidateSite?log=V3Z0MIWI

Suggestion to improve security

Some recommendations to improve security:

  • Add .htaccess files to deny access to all directories except the stylesheet
  • Add .htaccess file to deny access to the "update.php" file

Filw autoload filw

Hello, I downloaded the code, but it does not contain the autoload.php file.

how can I get it?
thank you.

FAIL Error code badArgument not found in response but should be given to the request: verb=ListRecords&metadataPrefix=oai_dc&from=2002-02-05&until=2002-02-06T05:35:00Z The request has different granularities for the from and until parameters.

openarchives.org validation fails on my OAI repository based on opencultureconsulting / oai_pmh : a request that has different granularities should receive a badArgument error.

### Checking for version 2.0 specific exceptions
REQUEST https://oai.telemillevaches.net/?verb=ListRecords&metadataPrefix=oai_dc&from=2002-02-05&until=2002-02-06T05:35:00Z GET
FAIL Error code badArgument not found in response but should be given to the request: verb=ListRecords&metadataPrefix=oai_dc&from=2002-02-05&until=2002-02-06T05:35:00Z The request has different granularities for the from and until parameters.

Full log : http://www.openarchives.org/Register/ValidateSite?log=V3Z0MIWI

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.