Skip to content
Snippets Groups Projects
Commit c51af7a1 authored by Laurent's avatar Laurent
Browse files

dev #17871 oai

Fetch right number of records

Don't fetch oai data for each record
parent 5204645a
Branches
Tags
2 merge requests!917Dev#17871 oaista la vista,!904Dev#17871 oaista la vista
......@@ -87,7 +87,8 @@ class Class_Cosmogramme_Integration_DataSourceOAI extends Class_Cosmogramme_Inte
protected
$_uri_params,
$_oai_client,
$_position;
$_position,
$_records;
public function __construct($integration) {
......@@ -105,11 +106,20 @@ class Class_Cosmogramme_Integration_DataSourceOAI extends Class_Cosmogramme_Inte
}
protected function _getNextRecords() {
if (!isset($this->_records))
$this->_records = $this->_oai_client->getRecords($this->_uri_params);
return $this->_records;
}
public function next() {
$records = $this->_oai_client->getRecords($this->_uri_params);
$records = $this->_getNextRecords();
$unimarc_record = $records[$this->_position];
if ($this->_position >= count($records))
return (new Class_Cosmogramme_FileParser_Record())->beEnd();
$unimarc_record = $records[$this->_position];
if ($id = $unimarc_record->get_subfield('001')) {
$unimarc_record->add_field('995', ' ', [ ['f', $id[0]] ]);
$unimarc_record->update();
......@@ -119,12 +129,10 @@ class Class_Cosmogramme_Integration_DataSourceOAI extends Class_Cosmogramme_Inte
$record
->setPosition($this->_position)
->setNextPosition($this->_position + 1)
->setCompletion(intval(100 * $this->_position / count($records)));
->setCompletion(intval(100 * $this->_position / count($records)))
->beOk();
$this->_position = $this->_position + 1;
$this->_position >= count($records) ? $record->beEnd() : $record->beOk();
return $record;
}
......
......@@ -51,7 +51,21 @@ class PhaseNoticeOAITest extends PhaseNoticeTestCase {
/** @test */
public function totalNumberOfRecordsFromOAIShouldBeFive() {
$this->assertEquals(5, Class_Notice::countBy([]));
public function totalNumberOfRecordsFromOAIShouldBeSix() {
$this->assertEquals(6, Class_Notice::countBy([]));
}
/** @test */
public function firstRecordTitleShouldBeSavoirsSecrets() {
$this->assertEquals('Savoirs secrets',
Class_Notice::find(1)->getTitrePrincipal());
}
/** @test */
public function sixthRecordTitleShouldContainsTrumanAndThe80th() {
$this->assertContains('Truman and the 80th',
Class_Notice::find(6)->getTitrePrincipal());
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment