From 078689b9791cb3122d437c093c5a6464422a76d4 Mon Sep 17 00:00:00 2001
From: Henri-Damien LAURENT <hdlaurent@afi-sa.fr>
Date: Wed, 24 Nov 2021 17:24:35 +0100
Subject: [PATCH] hotline#138089 : Cosmogramme : Problem with some articles or
 albums which rewrite over bibliographic records

---
 VERSIONS_HOTLINE/138089                       |   1 +
 .../admin/controllers/UploadController.php    |   2 +
 library/Class/Album.php                       |  12 -
 .../Integration/PhasePseudoRecord.php         |   5 +
 library/Class/Indexation/PseudoNotice.php     |  95 +++++-
 .../Controller/Plugin/Manager/Album.php       |   6 +
 .../admin/controllers/AlbumControllerTest.php |   4 +-
 .../SystemeControllerWebServicesTest.php      |   2 +-
 .../BibNumeriqueControllerTest.php            |   1 +
 .../RechercheControllerPrintActionTest.php    |  14 +-
 .../Class/Indexation/PseudoNoticeTest.php     | 286 +++++++++++++++++-
 .../PnbDilicom/PnbDilicomDisplayTest.php      |   4 +-
 12 files changed, 392 insertions(+), 40 deletions(-)
 create mode 100644 VERSIONS_HOTLINE/138089

diff --git a/VERSIONS_HOTLINE/138089 b/VERSIONS_HOTLINE/138089
new file mode 100644
index 00000000000..5e640ccbd93
--- /dev/null
+++ b/VERSIONS_HOTLINE/138089
@@ -0,0 +1 @@
+ - ticket #138089 : les articles peuvent prendre ds ids de notices déjà existantes.
\ No newline at end of file
diff --git a/application/modules/admin/controllers/UploadController.php b/application/modules/admin/controllers/UploadController.php
index 8aaf562b3e0..11d369491ae 100644
--- a/application/modules/admin/controllers/UploadController.php
+++ b/application/modules/admin/controllers/UploadController.php
@@ -71,6 +71,8 @@ $(document).ready(function () {
 
 
       $result = $model->addFile($this->_request);
+      if ($modelClass == 'Class_Album')
+        $model->updateDateMaj();
       $model->save();
       $model->index();
       $this->_helper->json($result);
diff --git a/library/Class/Album.php b/library/Class/Album.php
index dcf0a0e5563..a80d18ae9e8 100644
--- a/library/Class/Album.php
+++ b/library/Class/Album.php
@@ -180,7 +180,6 @@ class Class_Album extends Storm_Model_Abstract {
   protected
     $_marc,
     $path_flash,
-    $_date_maj_enabled = true,
     $_authors;
 
 
@@ -992,7 +991,6 @@ class Class_Album extends Storm_Model_Abstract {
   public function beforeSave() {
     $this
       ->updateThumbnailFromMedia()
-      ->updateDateMaj()
       ->collectAuthors()
       ->collectEditors()
       ->collectCollections()
@@ -1000,13 +998,6 @@ class Class_Album extends Storm_Model_Abstract {
   }
 
 
-  public function saveWithoutDateMaj() {
-    $this->_date_maj_enabled = false;
-    $this->save();
-    $this->_date_maj_enabled = true;
-  }
-
-
   public function collectAuthors() {
     $authors = $this->_collect('authors', self::AUTHOR_FIELD);
     $this->_authors = null;
@@ -1051,9 +1042,6 @@ class Class_Album extends Storm_Model_Abstract {
 
 
   public function updateDateMaj() {
-    if (!$this->_date_maj_enabled)
-      return $this;
-
     return $this->setDateMaj(date('Y-m-d H:i:s', self::getTimeSource()->time()));
   }
 
diff --git a/library/Class/Cosmogramme/Integration/PhasePseudoRecord.php b/library/Class/Cosmogramme/Integration/PhasePseudoRecord.php
index e5040754c2f..0eccce87b05 100644
--- a/library/Class/Cosmogramme/Integration/PhasePseudoRecord.php
+++ b/library/Class/Cosmogramme/Integration/PhasePseudoRecord.php
@@ -108,6 +108,11 @@ abstract class Class_Cosmogramme_Integration_PhasePseudoRecord
       return;
     }
 
+    if ($model->getTypeDocId() != $old_record->getTypeDoc()) {
+      $this->_incrementCount(Class_Cosmogramme_Integration_Phase::RECORD_INSERT);
+      return;
+    }
+
     $this->_incrementCount(Class_Cosmogramme_Integration_Phase::RECORD_FULLUPDATE);
   }
 
diff --git a/library/Class/Indexation/PseudoNotice.php b/library/Class/Indexation/PseudoNotice.php
index fa21644fba8..5156769caa5 100644
--- a/library/Class/Indexation/PseudoNotice.php
+++ b/library/Class/Indexation/PseudoNotice.php
@@ -28,7 +28,6 @@ class Class_Indexation_PseudoNotice {
     $_table,
     $_id,
     $_label,
-    $_id_notice = 'ID_NOTICE',
     $_notice,
     $_exemplaire,
     $_type_doc;
@@ -88,9 +87,30 @@ class Class_Indexation_PseudoNotice {
 
 
   protected function _updateLinkToRecord() {
-    $this->_model
-      ->updateAttributes([$this->_id_notice => $this->_notice->getId()])
-      ->save();
+    if ($this->getModelRecordId() == $this->_notice->getId())
+      return true;
+
+    $this->setModelRecordId($this->_notice->getId())
+         ->setModelRecordAssocation($this->_notice);
+
+    return $this->_model->save();
+  }
+
+
+  public function getModelRecordId(){
+    return $this->_model->getIdNotice();
+  }
+
+
+  public function setModelRecordId($id){
+    $this->_model->setIdNotice($id);
+    return $this;
+  }
+
+
+  public function setModelRecordAssocation($record){
+    $this->_model->setNotice($record);
+    return $this;
   }
 
 
@@ -159,14 +179,33 @@ class Class_Indexation_PseudoNotice {
 
 
   protected function _ensureRecord() {
-    if ($this->_notice = $this->_model->getNotice())
-      return $this->_notice->setTypeDoc($this->_type_doc)->save();
+    if ( ! $this->_notice = $this->_model->getNotice()) {
+      $this->_notice = Class_Notice::newInstance(['type_doc' => $this->_type_doc]);
+      return $this->_notice->save();
+    }
+
+    if ((string) $this->_type_doc == (string) $this->_notice->getTypeDoc())
+      return true;
+
+    if ($this->_couldUpdateRecord()) {
+      $this->_notice->setTypeDoc($this->_type_doc);
+      return $this->_notice->save();
+    }
+
+    if ( ! $this->_notice->getFirstExemplaire())
+      $this->_notice->delete();
 
     $this->_notice = Class_Notice::newInstance(['type_doc' => $this->_type_doc]);
+
     return $this->_notice->save();
   }
 
 
+  protected function _couldUpdateRecord(){
+    return ! $this->_notice->isSigb();
+  }
+
+
   public function getAuthorsNames() {
     $names = [];
     foreach($authors = $this->extractAuthors() as $author)
@@ -400,8 +439,24 @@ class Class_Indexation_PseudoNotice_Album extends Class_Indexation_PseudoNotice{
   protected
     $_model_name = Class_Album::class,
     $_id = 'id',
-    $_label = 'm4',
-    $_id_notice = 'notice_id';
+    $_label = 'm4';
+
+
+  public function getModelRecordId(){
+    return $this->_model->getNoticeId();
+  }
+
+
+  public function setModelRecordId($id){
+    $this->_model->setNoticeId($id);
+    return $this;
+  }
+
+
+  public function setModelRecordAssocation($record){
+    $this->_model->setNotice($record);
+    return $this;
+  }
 
 
   public function __construct($model) {
@@ -430,13 +485,6 @@ class Class_Indexation_PseudoNotice_Album extends Class_Indexation_PseudoNotice{
   }
 
 
-  protected function _updateLinkToRecord() {
-    $this->_model
-      ->setNoticeId($this->_notice->getId())
-      ->saveWithoutDateMaj();
-  }
-
-
   protected function _modelIdAcceptVisitor($visitor) {}
 
 
@@ -603,6 +651,23 @@ class Class_Indexation_PseudoNotice_Cms extends Class_Indexation_PseudoNotice{
   }
 
 
+  public function getModelRecordId(){
+    return $this->_model->getIdNotice();
+  }
+
+
+  public function setModelRecordId($id){
+    $this->_model->setIdNotice($id);
+    return $this;
+  }
+
+
+  public function setModelRecordAssocation($record){
+    $this->_model->setNotice($record);
+    return $this;
+  }
+
+
   public function delete() {
     (new Class_Indexation_Model_WithManyDomains($this->_model))->unindex();
     parent::delete();
diff --git a/library/ZendAfi/Controller/Plugin/Manager/Album.php b/library/ZendAfi/Controller/Plugin/Manager/Album.php
index fba9ace9542..8fb2be3d8a6 100644
--- a/library/ZendAfi/Controller/Plugin/Manager/Album.php
+++ b/library/ZendAfi/Controller/Plugin/Manager/Album.php
@@ -245,6 +245,12 @@ class ZendAfi_Controller_Plugin_Manager_Album extends ZendAfi_Controller_Plugin_
   }
 
 
+  protected function _doBeforeSave($album) {
+    $album->updateDateMaj();
+    return parent::_doBeforeSave($album);
+  }
+
+
   public function sortressourcesAction() {
     $album = Class_Album::find((int)$this->_getParam('id'));
     $album->sortRessourceByFileName()->save();
diff --git a/tests/application/modules/admin/controllers/AlbumControllerTest.php b/tests/application/modules/admin/controllers/AlbumControllerTest.php
index b30bea0cec8..27aa5869989 100644
--- a/tests/application/modules/admin/controllers/AlbumControllerTest.php
+++ b/tests/application/modules/admin/controllers/AlbumControllerTest.php
@@ -1231,6 +1231,7 @@ abstract class Admin_AlbumControllerEditAlbumMesBDTestCase extends Admin_AlbumCo
       ->setDuration('00:05:00')
       ->addAuthor('Pba')
       ->addEditor('Glo')
+      ->updateDateMaj()
       ->addCollection('Ratm')
       ->setDistributor('Geffen Records')
       ->setDroits(Class_Album::getPublicDomain())
@@ -1401,7 +1402,7 @@ class Admin_AlbumControllerEditAlbumMesBDTest extends Admin_AlbumControllerEditA
 
   /** @test */
   public function divShouldDisplayMajDate() {
-    $this->assertXPathContentContains("//div", '14 décembre 2013 09:00:00',$this->_response->getBody());
+    $this->assertXPathContentContains("//div", '14 décembre 2013 09:00:00');
   }
 
 
@@ -1753,6 +1754,7 @@ class Admin_AlbumControllerPostEditAlbumMesBDTest extends Admin_AlbumControllerT
                          $this->fixture('Class_Notice',
                                         ['id' => 72,
                                          'titre_principal' => 'Mes Romans',
+                                         'type_doc' => 201,
                                          'exemplaires' => [
                                                            $this->fixture('Class_Exemplaire',
                                                                           ['id' => 2])]
diff --git a/tests/application/modules/admin/controllers/SystemeControllerWebServicesTest.php b/tests/application/modules/admin/controllers/SystemeControllerWebServicesTest.php
index 5c564c8b301..d2a76b184a2 100644
--- a/tests/application/modules/admin/controllers/SystemeControllerWebServicesTest.php
+++ b/tests/application/modules/admin/controllers/SystemeControllerWebServicesTest.php
@@ -67,6 +67,6 @@ class SystemeControllerWebServicesActionTest extends Admin_AbstractControllerTes
     $this->dispatch('/admin/systeme/webservices/id_service/Premiere/id_fonction/1', true);
 
     $this->assertXPathContentContains('//pre[@class="resultat"]',
-                                      'Jake Sully est un ancien marine');
+                                      'Jake Sully est un ancien marine', $this->_response->getBody());
   }
 }
\ No newline at end of file
diff --git a/tests/application/modules/opac/controllers/BibNumeriqueControllerTest.php b/tests/application/modules/opac/controllers/BibNumeriqueControllerTest.php
index 6f832fe9c3c..10f41d60861 100644
--- a/tests/application/modules/opac/controllers/BibNumeriqueControllerTest.php
+++ b/tests/application/modules/opac/controllers/BibNumeriqueControllerTest.php
@@ -572,6 +572,7 @@ abstract class BibNumeriqueControllerAlbumMultiMediasTestCase extends AbstractCo
       ->setDescription('<p>pour passer la soirée</p>')
 
       ->addEditor('Gallimard')
+      ->updateDateMaj()
       ->setIdLang('lat')
       ->setDroits('CC-BY-SA')
 
diff --git a/tests/application/modules/opac/controllers/RechercheControllerPrintActionTest.php b/tests/application/modules/opac/controllers/RechercheControllerPrintActionTest.php
index bb0a914c9bb..e4d5d4e9893 100644
--- a/tests/application/modules/opac/controllers/RechercheControllerPrintActionTest.php
+++ b/tests/application/modules/opac/controllers/RechercheControllerPrintActionTest.php
@@ -156,11 +156,14 @@ class RechercheControllerPrintActionViewNoticeWithRecordsTest extends AbstractCo
                                           'type' => Class_ModeleFusion::RECORD_TEMPLATE]);
 
 
-    Class_Indexation_PseudoNotice::index( $this->fixture('Class_Article' , ['id' => 12,
-                                                                            'titre' => 'transmetropolitan',
-                                                                            'contenu' => '<p>bd</p>',
-                                                                            'notice' => new Class_Notice(),
-                                                                            'type_doc_id' => Class_TypeDoc::ARTICLE]));
+    Class_Indexation_PseudoNotice::index( $this->fixture('Class_Article' ,
+                                                         ['id' => 12,
+                                                          'titre' => 'transmetropolitan',
+                                                          'contenu' => '<p>bd</p>',
+                                                          'notice' => ($this->fixture(Class_Notice::class,
+                                                                                      ['id' => 1,
+                                                                                       'type_doc' => Class_TypeDoc::ARTICLE])),
+                                                          'type_doc_id' => Class_TypeDoc::ARTICLE]));
     $avis = [
              $this->fixture('Class_AvisNotice', [
                                                  'id' => 1,
@@ -202,6 +205,7 @@ class RechercheControllerPrintActionViewNoticeWithRecordsTest extends AbstractCo
     $this->assertXPathContentContains("//div//h1[1]", "transmetropolitan", $this->_response->getBody());
   }
 
+
   /** @test */
   public function avisShouldBeDisplayed() {
     $this->assertXPathContentContains('//div//p', "Lies are news and truth is obsolete.",$this->_response->getBody());
diff --git a/tests/library/Class/Indexation/PseudoNoticeTest.php b/tests/library/Class/Indexation/PseudoNoticeTest.php
index c3ca63d6813..ac04c9a4569 100644
--- a/tests/library/Class/Indexation/PseudoNoticeTest.php
+++ b/tests/library/Class/Indexation/PseudoNoticeTest.php
@@ -94,7 +94,7 @@ class Class_Indexation_PseudoNoticeAlbumWorkKeyCompositionTest extends ModelTest
     Class_CosmoVar::setValueOf('unimarc_zone_titre','200$a;200$e');
     Class_CosmoVar::setValueOf('other_index_fields','701$a');
     Class_CosmoVar::setValueOf('unimarc_zone_matiere','600$a');
-    Class_CosmoVar::set('work_key_composition', 'TITLE;AUTHOR');
+    Class_CosmoVar::setValueOf('work_key_composition', 'TITLE;AUTHOR');
 
     $this->fixture('Class_Album',
                    ['id' => 896,
@@ -488,6 +488,8 @@ class Class_Indexation_PseudoNoticeArticleTest
 }
 
 
+
+
 /**
  * @see http://forge.afi-sa.fr/issues/98102
  */
@@ -614,8 +616,13 @@ class Class_Indexation_PseudoNoticeArticleUpdateTest
 
     $record = $this->fixture('Class_Notice',
                              ['id' => 15,
+                              'type_doc' => Class_TypeDoc::LIVRE,
                               'titres' => 'Should not be deleted']);
 
+    $item = $this->fixture(Class_Exemplaire::class,
+                           ['id' => 231,
+                            'id_notice' => 15]);
+
     $article = $this->fixture('Class_Article',
                               ['id' => 1,
                                'titre' => 'Should update record with id 15',
@@ -634,22 +641,29 @@ class Class_Indexation_PseudoNoticeArticleUpdateTest
 
 
   /** @test */
-  public function onlyOneRecordShouldBePresent() {
-    $this->assertCount(1, Class_Notice::findAll());
+  public function twoRecordsShouldBePresent() {
+    $this->assertCount(2, Class_Notice::findAll());
   }
 
 
   /** @test */
   public function recordShouldHaveBeenUpdated() {
     $this->assertEquals('SHOULD CHOUL UPDATE UPDAT RECORD REKOR WITH OUI 15',
-                        Class_Notice::find(15)->getTitres());
+                        Class_Notice::find(16)->getTitres());
   }
 
 
   /** @test */
   public function deleteArticleShouldDeleteRecord() {
     Class_Article::find(1)->delete();
-    $this->assertNull(Class_Notice::find(15));
+    $this->assertNull(Class_Notice::find(16));
+  }
+
+
+  /** @test */
+  public function recordBookShouldBePresent() {
+    Class_Article::find(1)->delete();
+    $this->assertNotNull(Class_Notice::find(15));
   }
 }
 
@@ -695,6 +709,7 @@ class Class_Indexation_PseudoNoticeRssUpdateTest extends ModelTestCase {
     parent::setUp();
     $record = $this->fixture('Class_Notice',
                              ['id' => 15,
+                              'type_doc' => Class_TypeDoc::RSS,
                               'titres' => 'Should not be deleted']);
 
     $rss = $this->fixture('Class_Rss',
@@ -1001,3 +1016,264 @@ class Class_Indexation_PseudoNoticeSacramentariumTest extends ModelTestCase {
     $this->assertEquals(7, $item->getGenre());
   }
 }
+
+
+
+
+
+/**
+ *
+ * @see #138089
+ *
+ **/
+
+class Class_Indexation_PseudoNoticeArticleCmsTest
+  extends AbstractControllerTestCase {
+
+  protected $_storm_default_to_volatile = true;
+
+  public function setUp() {
+    parent::setUp();
+
+    $this->fixture(Class_Notice::class,
+                   ['id' => 5,
+                    'type_doc' => Class_TypeDoc::LIVRE,
+                   ]);
+
+    $author = $this->fixture(Class_Users::class,
+                             ['id' => 3,
+                              'login' => 'gm',
+                              'nom' => 'Musso',
+                              'prenom' => 'Guillaume',
+                              'password' => 'secret']);
+
+    $this->fixture(Class_Notice::class,
+                   ['id' => 1,
+                    'titre' => 'L\'Apothéose des Héros',
+                    'type_doc' => Class_TypeDoc::LIVRE,
+                    'auteur' => 'AUBRY LECOMTE HYACINTE',
+                    'unimarc' => '01795nkm0 2200373   450 00100070000000500170000703500170002403600140004109000110005509100160006609900350008210000410011710100080015810600060016611600230017213500060019520000770020121000390027821000330031721500550035023000830040530400390048830700330052733600790056033700590063937102170069845502600091561000200117566900150119570000340121080100620124485601070130697000080141328755220210306131624.0  aALEPH_156617  a000156617  a287552  a2b20201213  tNUMx0c2020-11-13d2020-11-18  a--------h----1821km-y0FREy5003----ba0 afre  as  ahi|b||||||bi||||||  ac1 aL\' Apothéose des héros français  (- Estampe)fHyacinthe Aubry-Lecomte  e[S.l]glith. de G. Engelmannh1821  eWasselonnegFlash Copyh2017  cSuite de 16 lithographies d\'après Girodet-Trioson  aDonnées iconographiques (14 fichiers JPEG : 216 Mo; 1 fichier PDF : 191 Mo )   aTitre provenant de l\'écran-titre   aManquent les planches 2 et 7  a Type de ressource électronique : données textuelles et iconographiques   aUn logiciel capable de lire un fichier au format JPEG   a Pour toute utilisation du document numérisé, indiquer la provenance comme suit : « Collection Société industrielle de Mulhouse, en dépôt à la Bibliothèque municipale de Mulhouse © Ville de Mulhouse »   943350bEstampec[S.l.] d1821fHyacinthe Aubry-Lecomtenlith. de G. EngelmannpSuite de 16 lithographies d\'après Girodet-TriosontL\' Apothéose des héros françaisuhttp://pro.bibliotheques.mulhouse.fr/cgi-bin/koha/catalogue/detail.pl?biblionumber=433500 aGirodet-Trioson  bPatrimoine 1aAubry-LecomtebHyacinthe4040  bBibliothèque municipale de MulhouseaFRcYYYYMMDDgAFNOR  abibliotheques.mulhouse.fruhttps://bibliotheques.mulhouse.fr/bib-numerique/download_album/id/12388.pdf  dArt',
+                    'clef_alpha' => "LAPOTHEOSEDESHEROSFRANCAISESTAMPE--AUBRYLECOMTEH----23"
+                   ]);
+
+    $this->fixture(Class_Exemplaire::class,
+                   ['id' => 123,
+                    'id_notice' => 1,
+                   ]);
+
+    $this->fixture(Class_Article::class,
+                   ['id' => 1,
+                    'id_notice' => 1,
+                    'titre' => 'My Article',
+                    'contenu' => 'article is about...',
+                    'description' => 'C&#39;est un m&eacute;gatest.',
+                    'date_creation' => '2018-02-17 10:22:34',
+                    'auteur' => $author]);
+
+    Class_Article::indexAll();
+  }
+
+
+  /** @test */
+  public function firstRecordTitleShouldBeLApotheoseDesHeros() {
+    $this->assertEquals('L\' Apothéose des héros français (- Estampe)',
+                        Class_Notice::find(1)->getTitrePrincipal());
+  }
+
+
+  /** @test */
+  public function articleRecordMainTitleShouldBeMyArticle() {
+    $this->assertEquals('My Article',
+                        Class_Article::find(1)->getNotice()->getTitrePrincipal());
+  }
+
+
+  /** @test */
+  public function articleRecordIdShouldBeSix() {
+    $this->assertEquals('6',
+                        Class_Article::find(1)->getIdNotice());
+  }
+}
+
+
+
+/**
+ *
+ * @see #138089
+ *
+ **/
+
+class Class_Indexation_IndexAlbumWithNewDocTypeTest
+  extends ModelTestCase {
+
+  protected $_storm_default_to_volatile = true;
+
+
+  public function setUp() {
+    parent::setUp();
+
+    $this->fixture(Class_Notice::class,
+                   ['id' => 1,
+                    'type_doc' => Class_TypeDoc::DIAPORAMA,
+                   ]);
+
+    $this->fixture(Class_Album::class,
+                   ['id' => 1,
+                    'notice_id' => 1,
+                    'visible' => true,
+                    'status' => Class_Article::STATUS_VALIDATED,
+                    'titre' => 'Tintin'
+                   ])
+         ->index();
+  }
+
+
+  /** @test */
+  public function recordOneShouldNotBeRemoved() {
+    $this->assertNotNull(Class_Notice::find(1));
+  }
+
+
+  /** @test */
+  public function newRecordTitleShouldBeTintin() {
+    $album = Class_Album::find(1)
+      ->setTypeDocId(Class_TypeDoc::EPUB);
+    $album->save();
+    $album->index();
+
+    $this->assertEquals('Tintin',
+                        Class_Album::find(1)
+                        ->getNotice()->getTitrePrincipal());
+  }
+
+
+  /** @test */
+  public function albumRecordIdShouldBeOne() {
+    $album = Class_Album::find(1)
+      ->setTypeDocId(Class_TypeDoc::EPUB);
+    $album->save();
+    $album->index();
+
+    $this->assertEquals('1',
+                        Class_Album::find(1)->getNoticeId());
+  }
+}
+
+
+
+
+/**
+ *
+ * @see #138089
+ *
+ **/
+
+class Class_Indexation_PseudoNoticeWithAlbumLinkedToWrongRecordTest
+  extends ModelTestCase {
+
+  protected $_storm_default_to_volatile = true;
+
+
+  public function setUp() {
+    parent::setUp();
+
+    $this->fixture(Class_Notice::class,
+                   ['id' => 1,
+                    'type_doc' => Class_TypeDoc::LIVRE,
+                   ]);
+
+    $this->fixture(Class_Notice::class,
+                   ['id' => 5,
+                    'type_doc' => Class_TypeDoc::LIVRE,
+                   ]);
+
+    $this->fixture(Class_Album::class,
+                   ['id' => 1,
+                    'notice_id' => 1,
+                    'visible' => true,
+                    'type_doc_id' => Class_TypeDoc::DIAPORAMA,
+                    'status' => Class_Album::STATUS_VALIDATED,
+                    'titre' => 'Tintin'
+                   ]);
+  }
+
+
+  /** @test */
+  public function recordOneShouldHaveBeenRemoved() {
+    Class_Album::find(1)->index();
+    $this->assertNull(Class_Notice::find(1));
+  }
+
+
+  /** @test */
+  public function recordOneLinkedInItemShouldNotBeenRemoved() {
+    $this->fixture(Class_Exemplaire::class,
+                   ['id' => 1,
+                    'id_notice' => 1
+                   ]);
+    Class_Album::find(1)->index();
+    $this->assertNotNull(Class_Notice::find(1));
+  }
+}
+
+
+
+
+/**
+ *
+ * @see #138089
+ *
+ **/
+
+class Class_Indexation_PseudoNoticeWithAlbumNotLinkedTest
+  extends ModelTestCase {
+
+  protected $_storm_default_to_volatile = true;
+
+
+  public function setUp() {
+    parent::setUp();
+
+    $this->fixture(Class_Notice::class,
+                   ['id' => 5,
+                    'titres' => 'manuel du guerrier de la lumière',
+                    'type_doc' => Class_TypeDoc::LIVRE,
+                   ]);
+
+    $this->fixture(Class_Article::class,
+                   ['id' => 1,
+                    'visible' => true,
+                    'contenu' => 'rétrospective de tintin',
+                    'status' => Class_Article::STATUS_VALIDATED,
+                    'titre' => 'Tintin'
+                   ]);
+    Class_Article::find(1)->index();
+  }
+
+
+  /** @test */
+  public function recordsCountShouldBeTwo() {
+    $this->assertEquals(2, Class_Notice::count());
+  }
+
+
+  /** @test */
+  public function recordTitleLinkedInArticleShouldBeTintin() {
+    $this->assertEquals('Tintin',
+                        Class_Article::find(1)->getNotice()->getTitrePrincipal());
+  }
+
+
+  /** @test */
+  public function recordIdLinkedInArticleShouldBeSix() {
+    $this->assertEquals(6,
+                        Class_Article::find(1)->getNotice()->getId());
+  }
+
+
+  /** @test */
+  public function recordTypeDocLinkedInAlbumShouldBeArticle() {
+    $this->assertEquals(Class_TypeDoc::ARTICLE,
+                        Class_Article::find(1)->getNotice()->getTypeDoc());
+  }
+}
diff --git a/tests/scenarios/PnbDilicom/PnbDilicomDisplayTest.php b/tests/scenarios/PnbDilicom/PnbDilicomDisplayTest.php
index dc6139f9f15..3cb95196cb0 100644
--- a/tests/scenarios/PnbDilicom/PnbDilicomDisplayTest.php
+++ b/tests/scenarios/PnbDilicom/PnbDilicomDisplayTest.php
@@ -197,7 +197,9 @@ abstract class PnbDilicomDisplayBibNumeriqueControllerTestCase extends AbstractC
                                   'external_uri' => 'http://www.edenlivres.fr/p/23416',
                                   'type_doc_id' => Class_TypeDoc::DILICOM,
                                   'isbn' => '435465',
-                                  'notice' => $this->fixture('Class_Notice', ['id' => 38]),
+                                  'notice' => $this->fixture('Class_Notice',
+                                                             ['id' => 38,
+                                                              'type_doc' => Class_TypeDoc::DILICOM]),
                                   'items' => [$this->fixture('Class_Album_Item',
                                                              ['id' => 1,
                                                               'album_id' => 3,
-- 
GitLab