From db9aa17091d872bbd08d1c3af481a107a489bf2f Mon Sep 17 00:00:00 2001
From: Laurent Laffont <llaffont@afi-sa.fr>
Date: Tue, 19 Nov 2019 12:40:10 +0100
Subject: [PATCH] hotline #96803 add article summary, author et creation year
 in record indexation

---
 VERSIONS_HOTLINE/96803                        |  1 +
 library/Class/Indexation/PseudoNotice.php     |  8 +++
 .../Class/Indexation/PseudoNoticeTest.php     | 52 +++++++++++++++++--
 3 files changed, 58 insertions(+), 3 deletions(-)
 create mode 100644 VERSIONS_HOTLINE/96803

diff --git a/VERSIONS_HOTLINE/96803 b/VERSIONS_HOTLINE/96803
new file mode 100644
index 00000000000..1cec179815d
--- /dev/null
+++ b/VERSIONS_HOTLINE/96803
@@ -0,0 +1 @@
+ - ticket #96803 : Indexation des articles : ajout du résumé en 330$a, de l'auteur en 701 et de l'année de création en 210$d
\ No newline at end of file
diff --git a/library/Class/Indexation/PseudoNotice.php b/library/Class/Indexation/PseudoNotice.php
index 6597d0c830c..ddb1be1653f 100644
--- a/library/Class/Indexation/PseudoNotice.php
+++ b/library/Class/Indexation/PseudoNotice.php
@@ -127,6 +127,7 @@ class Class_Indexation_PseudoNotice {
                                  'date_maj' =>'',
                                  'isbn' => '',
                                  'domaine_ids' => '',
+                                 'resume' => '',
                                  'created_at' => null],
                                 array_change_key_case($this->_datas));
   }
@@ -356,6 +357,7 @@ class Class_Indexation_PseudoNotice {
       ->visitUrl($this->_datas['url'])
       ->visitNotes($this->_datas['notes'])
       ->visitNatures($this->_datas['nature_doc'])
+      ->visitResume($this->_datas['resume'])
       ->visitCustomFieldsValues($this->getCustomFieldsValues());
 
     $this->_modelIdAcceptVisitor($visitor);
@@ -597,7 +599,13 @@ class Class_Indexation_PseudoNotice_Cms extends Class_Indexation_PseudoNotice{
 
   protected function _prepareDatas() {
     parent::_prepareDatas();
+    $this->_datas['resume'] = strip_tags($this->_datas['description']);
     $this->_datas['description'] = strip_tags($this->_datas['contenu']);
+    $this->_datas['auteur'] = $this->_model->hasAuteur()
+      ? $this->_model->getAuteur()->getNomComplet()
+      : '';
+
+    $this->_datas['annee'] = date('Y', strtotime($this->_model->getDateCreation()));
   }
 }
 
diff --git a/tests/library/Class/Indexation/PseudoNoticeTest.php b/tests/library/Class/Indexation/PseudoNoticeTest.php
index 227f65052bc..90112ae9396 100644
--- a/tests/library/Class/Indexation/PseudoNoticeTest.php
+++ b/tests/library/Class/Indexation/PseudoNoticeTest.php
@@ -355,10 +355,17 @@ class Class_Indexation_PseudoNoticeArticleTest
   public function setUp() {
     parent::setUp();
 
+    $author = $this->fixture('Class_Users',
+                             ['id' => 3,
+                              'login' => 'gm',
+                              'nom' => 'Musso',
+                              'prenom' => 'Guillaume',
+                              'password' => 'secret']);
+
     $this->fixture('Class_NoticeDomain',
                    ['id' => 189,
                     'domain_id' => 17,
-                    'record_alpha_key' => 'MYARTCILE-1-----8']);
+                    'record_alpha_key' => 'MYARTICLE-1-GUILLAUMEMUSSO----8']);
 
     $this->fixture('Class_Catalogue',
                    ['id' => 17,
@@ -366,13 +373,17 @@ class Class_Indexation_PseudoNoticeArticleTest
 
     $this->fixture('Class_Article',
                    ['id' => 1,
-                    'titre' => 'My Artcile',
+                    'titre' => 'My Article',
                     'contenu' => 'article is about...',
+                    'description' => 'This is a test',
+                    'date_creation' => '2018-02-17 10:22:34',
+                    'auteur' => $author,
                     'domaine_ids' => '17']);
 
     $this->fixture('Class_Article',
                    ['id' => 5,
-                    'titre' => 'My Artcile bis',
+                    'titre' => 'My Article bis',
+                    'auteur' => $author,
                     'contenu' => 'article is about bis...']);
 
     Class_Article::indexAll();
@@ -383,9 +394,42 @@ class Class_Indexation_PseudoNoticeArticleTest
   public function noticeDomainShouldContainsOnlyOneEnreg() {
     $this->assertCount(1, Class_NoticeDomain::findAll());
   }
+
+
+  /** @test */
+  public function firstRecordTitleShouldBeMyArticle() {
+    $this->assertEquals('My Article', Class_Notice::find(1)->getTitrePrincipal());
+  }
+
+
+  /** @test */
+  public function firstRecordSummaryShouldBeThisIsATest() {
+    $this->assertEquals('This is a test', Class_Notice::find(1)->getResume());
+  }
+
+
+  /** @test */
+  public function secondRecordSummaryShouldBeEmpty() {
+    $this->assertEmpty(Class_Notice::find(2)->getResume());
+  }
+
+
+  /** @test */
+  public function firstRecordMainAuthorShouldBeMusso() {
+    $this->assertEquals('Guillaume Musso', Class_Notice::find(1)->getAuteurPrincipal());
+  }
+
+
+  /** @test */
+  public function firstRecord210DShouldContainsCreationYear2018() {
+    $this->assertEquals(['2018'],
+                        Class_Notice::find(1)->get_subfield('210', 'd'));
+  }
 }
 
 
+
+
 /** @see http://forge.afi-sa.fr/issues/72723 */
 class Class_Indexation_PseudoNoticeArticleWithUnknownDomainTest
   extends Class_Indexation_PseudoNoticeTestCase {
@@ -462,6 +506,8 @@ class Class_Indexation_PseudoNoticeArticleUpdateTest
 }
 
 
+
+
 /** @see http://forge.afi-sa.fr/issues/69916 */
 class Class_Indexation_PseudoNoticeArticleLongContentTest
   extends Class_Indexation_PseudoNoticeTestCase {
-- 
GitLab