From f2c810f7ef05008ed9efe87fc0178eecb6ea0256 Mon Sep 17 00:00:00 2001
From: pierre oudot <poudot@afi-sa.fr>
Date: Thu, 29 Jun 2023 13:40:23 +0000
Subject: [PATCH] dev#180967 Add Cafeyn total import option

---
 VERSIONS_WIP/180967                           |  1 +
 library/digital_resources/Cafeyn/Config.php   |  1 +
 library/digital_resources/Cafeyn/Service.php  |  4 ++-
 .../Cafeyn/tests/CafeynTest.php               | 33 ++++++++++++++++++-
 4 files changed, 37 insertions(+), 2 deletions(-)
 create mode 100644 VERSIONS_WIP/180967

diff --git a/VERSIONS_WIP/180967 b/VERSIONS_WIP/180967
new file mode 100644
index 00000000000..230e9e9d3f8
--- /dev/null
+++ b/VERSIONS_WIP/180967
@@ -0,0 +1 @@
+ - fonctionnalité #180967 : Ressource Numérique : Cafeyn : Ajout d'une variable pour activerl'import total
\ No newline at end of file
diff --git a/library/digital_resources/Cafeyn/Config.php b/library/digital_resources/Cafeyn/Config.php
index b612abc3063..0b51941ab24 100644
--- a/library/digital_resources/Cafeyn/Config.php
+++ b/library/digital_resources/Cafeyn/Config.php
@@ -48,6 +48,7 @@ class Cafeyn_Config extends Class_DigitalResource_Config {
                             'API_PASSWORD' => Class_AdminVar_Meta::newDefault($this->_('Mot de passe API fourni par Cafeyn'))->bePrivate(),
                             'HARVEST_URL' => Class_AdminVar_Meta::newDefault($this->_('URL de moissonage de la ressource Cafeyn'))->bePrivate(),
                             'BATCH_UPDATE_NOTICE' => Class_AdminVar_Meta::newOnOff($this->_('Activer la mise à jour systématique des notices lors du moissonnage'),['value' => 1])->bePrivate(),
+                            'TOTAL_IMPORT'=> Class_AdminVar_Meta::newOnOff($this->_('Activer l\'import total: suppression de toutes les archives'),['value' => 0 ])->bePrivate(),
                             'SSO_URL' => Class_AdminVar_Meta::newDefault($this->_('URL SSO de la plateforme Cafeyn'),
                                                                          ['value' => 'https://www.cafeyn.co/fr/externallogin'])->bePrivate(),
             ]
diff --git a/library/digital_resources/Cafeyn/Service.php b/library/digital_resources/Cafeyn/Service.php
index d0140bfc7e6..5de001eb51e 100644
--- a/library/digital_resources/Cafeyn/Service.php
+++ b/library/digital_resources/Cafeyn/Service.php
@@ -47,7 +47,9 @@ class Cafeyn_Service extends Class_DigitalResource_Service {
 
 
   protected function _deleteNonHarvested() {
-    return $this->_deleteNonHarvestedAlbums();
+    return $this->_config->getAdminVar('TOTAL_IMPORT')
+      ? $this->_deleteNonHarvestedAlbums()
+      : $this;
   }
 
 
diff --git a/library/digital_resources/Cafeyn/tests/CafeynTest.php b/library/digital_resources/Cafeyn/tests/CafeynTest.php
index 9b2a07ff2c2..99d000b32fc 100644
--- a/library/digital_resources/Cafeyn/tests/CafeynTest.php
+++ b/library/digital_resources/Cafeyn/tests/CafeynTest.php
@@ -355,12 +355,12 @@ class CafeynHarvestDisableUpdateTest extends CafeynServiceTestCase {
 class CafeynHarvestUpdateTest extends CafeynServiceTestCase {
   public function setUp() {
     parent::setUp();
-
     Class_Album::find(20)->index();
   }
 
 
   public function addFixtures() {
+    Class_AdminVar::set('Cafeyn_TOTAL_IMPORT', true);
     $album = $this->fixture(Class_Album::class,
                             ['id' => 20,
                              'titre' => '10 moutons',
@@ -410,3 +410,34 @@ class CafeynHarvestUpdateTest extends CafeynServiceTestCase {
     $this->assertNull(Class_Album::find(25));
   }
 }
+
+
+
+
+class CafeynHarvestUpdateIncrementialTest extends CafeynServiceTestCase {
+  public function setUp() {
+    parent::setUp();
+  }
+
+
+  public function addFixtures() {
+    Class_AdminVar::set('Cafeyn_TOTAL_IMPORT', false);
+    $this->fixture(Class_Album::class,
+                   ['id' => 25,
+                    'titre' => 'Toto',
+                    'visible' => 1,
+                    'status' => 3,
+                    'id_origine'  => '666:7',
+                    'url_origine' => 'https://cafeyn.co/',
+                    'type_doc_id' => 'Cafeyn'
+                   ]);
+
+    return $this;
+  }
+
+
+  /** @test */
+  public function AlbumTotoShouldStillExist() {
+    $this->assertEquals('Toto', Class_Album::find(25)->getTitre());
+  }
+}
-- 
GitLab