Skip to content
Snippets Groups Projects
Commit 2f2adccb authored by Henri-Damien LAURENT's avatar Henri-Damien LAURENT
Browse files

hotline#163609 : Cosmogramme : Importing Carts could die

parent a6fd9e11
Branches
Tags
1 merge request!4608hotline#163609 : Cosmogramme : Importing Carts could die
Pipeline #19364 passed with stage
in 44 minutes and 35 seconds
This commit is part of merge request !4608. Comments created here will be created in the context of that merge request.
- ticket#16309 : Cosmogramme : Correction de la phase d'import des paniers
\ No newline at end of file
......@@ -28,7 +28,7 @@ class Class_Batch_PanierNotice extends Class_Batch_Abstract {
}
public function run() {
return (new Class_PanierNotice())->fixLostClesNoticesForAll();
return Class_PanierNotice::fixLostClesNoticesForAll();
}
}
?>
\ No newline at end of file
?>
......@@ -99,11 +99,11 @@ class Class_Cosmogramme_Integration_PhasePanier
return $this->_log->error($this->_('Pas de donnée trouvée avec le profil de données sélectionné'));
if (!$map['libelle'])
return $this->_log->error($this->_('Ligne non traitée car le libellé n\'a pas pu être lu'));
return $this->_log->log($this->_('Ligne non traitée car le libellé n\'a pas pu être lu'));
$id_int_bib = $integration->getIdBib();
$exemplaire = $this->_getItem($map['id_notice_sigb'], $id_int_bib);
$exemplaire = $this->_getItem($map['id_notice_sigb'], (int) $id_int_bib);
$owners = $this->findPossibleOwnersOfBasketRecord($map);
if ($owners->isEmpty()) {
......@@ -134,32 +134,47 @@ class Class_Cosmogramme_Integration_PhasePanier
}
protected function _getItem($id_notice_sigb, $id_int_bib) {
return ($items = Class_Exemplaire::findAllBy(['id_origine' => $id_notice_sigb,
'id_int_bib' => $id_int_bib]))
protected function _getItem(string $id_notice_sigb, int $id_int_bib) : Class_Exemplaire {
return ($items = Class_Exemplaire::findAllBy(['id_origine' => $id_notice_sigb]))
? $this->_findItem($items, $id_notice_sigb, $id_int_bib)
: $this->_noItem($id_notice_sigb, $id_int_bib);
}
protected function _findItem($items, $id_notice_sigb, $id_int_bib) {
protected function _findItem(array $items, int $id_notice_sigb, int $id_int_bib) : Class_Exemplaire {
$count_items = count($items);
$count = 1;
foreach ($items as $item) {
if (!$record = $item->getNotice())
continue;
if ($record->isSigb())
if ($record->isSigb()
&& ($id_int_bib == ($item_id_int_bib = $item->getIdIntBib()) ))
return $item;
if (($count == $count_items)
&& $record->isSigb() ){
$this->_log->log($this->_('Un exemplaire id_origine : %s / id_int_bib : %s a été trouvé. alors que nous cherchions id_int_bib %s\n',
$id_notice_sigb,
$item_id_int_bib,
$id_int_bib));
return $item;
}
$count++;
}
return $this->_noItem($id_notice_sigb, $id_int_bib);
}
protected function _noItem($id_notice_sigb, $id_int_bib) {
protected function _noItem($id_notice_sigb, $id_int_bib) : Class_Exemplaire {
$this->_log->error($this->_('L\'exemplaire id_origine : %s / id_int_bib : %s n\'a pas été trouvé.',
$id_notice_sigb,
$id_int_bib));
return new Class_Entity();
return (new Class_Exemplaire_Null)
->setIdOrigine($id_notice_sigb)
->setIdIntBib($id_int_bib);
}
......
<?php
/**
* Copyright (c) 2012-2022, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_Exemplaire_Null extends Class_Exemplaire {
public function getNotice() {
return null;
}
}
......@@ -459,8 +459,7 @@ class PhasePanierPartialImportTest extends PhasePanierKohaTestCase {
/** @see http://forge.afi-sa.fr/issues/33712 */
class PhasePanierNanookTest extends PhasePanierTestCase {
abstract class PhasePanierNanookTestCase extends PhasePanierTestCase {
protected $_basket;
protected function _prepareFixtures() {
......@@ -488,6 +487,18 @@ class PhasePanierNanookTest extends PhasePanierTestCase {
'role_level' => ZendAfi_Acl_AdminControllerRoles::SUPER_ADMIN,
'idabon' => '',
'mail' => '']);
}
}
/** @see http://forge.afi-sa.fr/issues/33712 */
class PhasePanierNanookTest extends PhasePanierNanookTestCase {
protected $_basket;
protected function _prepareFixtures() {
parent::_prepareFixtures();
$this->fixture(Class_Notice::class,
['id' => 23,
......@@ -535,3 +546,55 @@ class PhasePanierNanookTest extends PhasePanierTestCase {
$this->assertEquals(['CASTAFIORE'], $this->_basket->getClesNotices());
}
}
/** @see http://forge.afi-sa.fr/issues/163609 */
class PhasePanierNanookWithGhostItemsTest extends PhasePanierNanookTestCase {
protected $_basket;
protected function _prepareFixtures() {
parent::_prepareFixtures();
$this->fixture(Class_IntBib::class,
['id' => 3,
'nom_court' => 'Annexe 3',
'sigb' => 13]);
$this->fixture(Class_Notice::class,
['id' => 230,
'type_doc' => Class_TypeDoc::LIVRE,
'clef_alpha' => 'CASTAFIORE',
'exemplaires' => [$this->fixture(Class_Exemplaire::class,
['id' => 231,
'id_int_bib' => 3,
'id_origine' => 45633])]]);
$this->fixture(Class_Notice::class,
['id' => 234,
'type_doc' => Class_TypeDoc::LIVRE,
'clef_alpha' => 'BOB MORANE AVENTURIER',
'exemplaires' => [$this->fixture(Class_Exemplaire::class,
['id' => 235,
'id_int_bib' => 2,
'id_origine' => 189699])]]);
}
/** @test */
public function panierNoticesLogShouldContainsCastafiore() {
$this->assertLogContains('Un exemplaire id_origine : 45633 / id_int_bib : 3 a été trouvé. alors que nous cherchions id_int_bib 2');
}
/** @test */
public function panierNoticesShouldContainsCastafiore() {
$this->assertContains('CASTAFIORE',Class_PanierNotice::findFirstBy(['id_sigb' => 509])->getNotices());
}
/** @test */
public function panierNoticesShouldBeCastafioreAndBobMorane() {
$this->assertContains('BOB MORANE AVENTURIER',Class_PanierNotice::findFirstBy(['id_sigb' => 509])->getNotices());
}
}
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