Skip to content
Snippets Groups Projects
Commit 3df1b65a authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

rel #21286 : prepare to migrate one cosmogramme integration phase in object mode

parent 19e305fd
Branches
Tags
3 merge requests!780Master,!755Stable,!750Hotline#21286 holds not deleted with full import
......@@ -93,11 +93,11 @@ abstract class Class_Cosmogramme_FileParser {
$ret = $this->_next();
$ret['adresse'] = $adresse;
$ret['pointeur_reprise'] = $this->_position;
$ret['pct'] = intval(($this->_position / $this->_file_size) * 100);
$ret->setPosition($adresse)
->setNextPosition($this->_position)
->setCompletion(intval(($this->_position / $this->_file_size) * 100));
if ($ret['statut'] == 'eof')
if ($ret->isEnd())
$this->close();
return $ret;
......@@ -142,8 +142,8 @@ class Class_Cosmogramme_FileParser_Marc extends Class_Cosmogramme_FileParser {
$data .= $record;
}
$ret['statut'] = $at_end ? 'eof' : 'ok';
$ret['data'] = $data;
$ret = new Class_Cosmogramme_FileParserRecord($data);
$at_end ? $ret->beEnd() : $ret->beOk();
$this->_position += strlen($data);
return $ret;
......@@ -162,8 +162,10 @@ abstract class Class_Cosmogramme_FileParser_Ascii extends Class_Cosmogramme_File
$data = str_replace($this->_separator, chr(9), $data);
$this->_position = $fileSystem->ftell($this->_file_handle);
return ['data' => $data,
'statut' => $fileSystem->feof($this->_file_handle) ? 'eof' : 'ok'];
$ret = new Class_Cosmogramme_FileParserRecord($data);
$fileSystem->feof($this->_file_handle) ? $ret->beEnd() : $ret->beOk();
return $ret;
}
}
......@@ -228,17 +230,13 @@ class Class_Cosmogramme_FileParser_Xml extends Class_Cosmogramme_FileParser {
$record = $fileSystem->fread($this->_file_handle, self::READ_SIZE);
if ($fileSystem->feof($this->_file_handle)
&& !$record) {
$ret['statut'] = 'eof';
return $ret;
}
&& !$record)
return (new Class_Cosmogramme_FileParserRecord(''))->beEnd();
$data .= $record;
}
$ret['statut'] = 'ok';
$ret['data'] = $data;
$ret = (new Class_Cosmogramme_FileParserRecord($data))->beOk();
$this->_position += strlen($data);
return $ret;
......@@ -255,10 +253,96 @@ class Class_Cosmogramme_FileParser_Csv extends Class_Cosmogramme_FileParser {
$data = str_replace('"', '', $data);
$this->_position = $fileSystem->ftell($this->_file_handle);
return ['data' => $data,
'statut' => $fileSystem->feof($this->_file_handle) ? 'eof' : 'ok'];
$ret = new Class_Cosmogramme_FileParserRecord($data);
$fileSystem->feof($this->_file_handle) ? $ret->beEnd() : $ret->beOk();
return $ret;
}
}
class Class_Cosmogramme_FileParserRecord {
const STATUS_OK = 'ok';
const STATUS_ERROR = 'error';
const STATUS_END = 'eof';
protected $_status, $_data, $_completion, $_position, $_next_position, $_error;
public function __construct($data='') {
$this->_data = $data;
}
public function withErrorDo($closure) {
return $closure($this->_error);
}
public function withDataDo($closure) {
return $closure($this->_data);
}
public function withNextPositionDo($closure) {
return $closure($this->_next_position);
}
public function setCompletion($completion) {
$this->_completion = $completion;
return $this;
}
public function setPosition($position) {
$this->_position = $position;
return $this;
}
public function setNextPosition($position) {
$this->_next_position = $position;
return $this;
}
public function setError($error) {
$this->_error = $error;
return $this;
}
public function beOk() {
$this->_status = self::STATUS_OK;
return $this;
}
public function isOk() {
return $this->_status == self::STATUS_OK;
}
public function beError() {
$this->_status = self::STATUS_ERROR;
return $this;
}
public function isError() {
return $this->_status == self::STATUS_ERROR;
}
public function beEnd() {
$this->_status = self::STATUS_END;
return $this;
}
public function isEnd() {
return $this->_status == self::STATUS_END;
}
}
?>
\ No newline at end of file
......@@ -121,67 +121,89 @@ class Class_Cosmogramme_Integration_PhaseReservation {
if ($this->_isTimeOut())
return;
$processed = $this->_phase->getData('nombre');
$line = $parser->next();
if ($this->_lineError($line)) {
$this->_log->ecrire('<span class="rouge">' . $ret['erreur'] . '</span><br>');
$msg = ($processed > 0) ?
$processed . ' fiches ont pu être traitées.' :
'aucune fiche n\'a pu être traitée.';
$this->_log->ecrire('<span class="vert">' . $msg . '</span>');
if ($this->_lineError($line) || $this->_lineAtEnd($line))
return;
}
if ($this->_lineAtEnd($line)) {
if ($processed == 0) {
$this->_log->ecrire('<br><span class="vert">Le fichier ne contenait aucune fiche</span><br>');
return;
}
$this->_log->ecrire('<br><span class="vert">' . $processed . ' fiches ont été traitées.</span>');
$msg = "temps de traitement " . $this->_chrono->endFile()
. ' (' . $this->_chrono->meanFile($processed, 'fiches') . ')';
$this->_log->ecrire('<br><span class="vert">'.$msg.'</span><br>');
return;
}
if ($this->_lineOk($line)) {
if (substr($line['data'], 0, 13) == 'BIB_T_RESERVE')
continue; // Entete pergame
$transaction = new Class_Cosmogramme_Integration_Transaction($integration);
$transaction->importHold($line['data']);
$this->_phase->incrementData('nombre');
if ($processed % 1000) {
$this->_log->ecrire('fiche ' . $processed
. ' (' . $this->_chrono->elapsedOn100Records()
. ' secondes)<br>');
$this->_chrono->startOn100Records();
}
$this->_phase->setData('pointeur', $line['pointeur_reprise']);
$integration->setPointeurReprise($line['pointeur_reprise'])
->save();
}
$this->_lineOk($line, $integration);
}
}
protected function _lineError($line) {
return $line['statut'] == 'erreur';
if (!$line->isError())
return false;
$line->withErrorDo(
function($error) {
$this->_log->ecrire('<span class="rouge">' . $error . '</span><br>');
});
$processed = $this->_phase->getData('nombre');
$msg = ($processed > 0) ?
$processed . ' fiches ont pu être traitées.' :
'aucune fiche n\'a pu être traitée.';
$this->_log->ecrire('<span class="vert">' . $msg . '</span>');
return true;
}
protected function _lineAtEnd($line) {
return $line['statut'] == 'eof';
if (!$line->isEnd())
return false;
$processed = $this->_phase->getData('nombre');
if ($processed == 0) {
$this->_log->ecrire('<br><span class="vert">Le fichier ne contenait aucune fiche</span><br>');
return true;
}
$this->_log->ecrire('<br><span class="vert">' . $processed . ' fiches ont été traitées.</span>');
$msg = "temps de traitement " . $this->_chrono->endFile()
. ' (' . $this->_chrono->meanFile($processed, 'fiches') . ')';
$this->_log->ecrire('<br><span class="vert">' . $msg . '</span><br>');
return true;
}
protected function _lineOk($line) {
return $line['statut'] == 'ok';
protected function _lineOk($line, $integration) {
if (!$line->isOk())
return;
$is_pergame_header = function($data) {
return substr($data, 0, 13) == 'BIB_T_RESERVE';
};
if ($line->withDataDo($is_pergame_header))
return; // Entete pergame
$transaction = new Class_Cosmogramme_Integration_Transaction($integration);
$line->withDataDo(
function($data) use ($transaction) {
$transaction->importHold($data);
});
$this->_phase->incrementData('nombre');
$processed = $this->_phase->getData('nombre');
if (0 == $processed % 1000) {
$this->_log->ecrire('fiche ' . $processed
. ' (' . $this->_chrono->elapsedOn100Records()
. ' secondes)<br>');
$this->_chrono->startOn100Records();
}
$line->withNextPositionDo(
function($next) use ($integration) {
$this->_phase
->setData('pointeur', $next);
$integration
->setPointeurReprise($next)
->save();
});
}
......
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