From 92dbd2c8ddec2450eac4f9432677227d62a9abd2 Mon Sep 17 00:00:00 2001
From: gloas <gloas@afi-sa.fr>
Date: Wed, 7 Sep 2022 17:27:09 +0200
Subject: [PATCH] hotline #161093 fix MusicMe harvesting

---
 VERSIONS_HOTLINE/161093                       |  1 +
 library/digital_resources/Musicme/Config.php  | 18 +++++----
 library/digital_resources/Musicme/Service.php |  4 +-
 .../Musicme/tests/MusicmeTest.php             | 38 ++++++++++++-------
 4 files changed, 38 insertions(+), 23 deletions(-)
 create mode 100644 VERSIONS_HOTLINE/161093

diff --git a/VERSIONS_HOTLINE/161093 b/VERSIONS_HOTLINE/161093
new file mode 100644
index 00000000000..f0a7b66bfcb
--- /dev/null
+++ b/VERSIONS_HOTLINE/161093
@@ -0,0 +1 @@
+ - correctif #161093 : Ressources numériques : corrections du moissonnage de MusicMe.
\ No newline at end of file
diff --git a/library/digital_resources/Musicme/Config.php b/library/digital_resources/Musicme/Config.php
index e35f9fd6b58..0a5cc5dfb71 100644
--- a/library/digital_resources/Musicme/Config.php
+++ b/library/digital_resources/Musicme/Config.php
@@ -29,18 +29,20 @@ class Musicme_Config extends Class_DigitalResource_Config {
             'Introduction' => $this->_('Plateforme d\'écoute et de téléchargement de musique.'),
             'NotAllowedMessage' => $this->_('Votre abonnement ne permet pas l\'accès à cette ressource.'),
 
-            'HelpLink' => 'http://wiki.bokeh-library-portal.org/index.php/MusicMe',
-            'Url' => 'http://www.musicme.com/',
+            'HelpLink' => 'https://wiki.bokeh-library-portal.org/index.php/MusicMe',
+            'Url' => 'https://www.musicme.com/',
             'Icon' => 'https://static.wixstatic.com/media/679c8e_71d2ebe18f5141769ccb3d7cb6d66cf0.png',
             'Mail' => 'support@musicme.com',
             'MailUrl' => 'https://www.musicme.com/#/support.php?cat=2',
 
-            'AdminVars' => [
-                            'BIB_ID' => Class_AdminVar_Meta::newDefault($this->_('Identifiant fournit par musicMe'))->bePrivate(),
-                            'URL' => Class_AdminVar_Meta::newDefault($this->_('Url fournit par musicMe'))->bePrivate(),
-                            'EXPORT_URL' => Class_AdminVar_Meta::newDefault($this->_('Url du dépot de ressources founit par musicMe'))->bePrivate(),
-                            'COVER_IMG_URL' => Class_AdminVar_Meta::newDefault($this->_('Url du dépot des images de musicMe'), ['value' => 'https://covers.hosting-media.net/jpgr575'] )->bePrivate(),
-            ],
+            'AdminVars' =>
+            ['BIB_ID' => Class_AdminVar_Meta::newDefault($this->_('Identifiant fourni par musicMe'))->bePrivate(),
+             'URL' => Class_AdminVar_Meta::newDefault($this->_('Url fourni par musicMe'))->bePrivate(),
+             'EXPORT_URL' => Class_AdminVar_Meta::newDefault($this->_('Url du dépot de ressources fourni par musicMe'))->bePrivate(),
+             'EXPORT_USERNAME' => Class_AdminVar_Meta::newDefault($this->_('Nom d\'utilisateur fourni par musicMe pour accéder au dépot de ressources '))->bePrivate(),
+             'EXPORT_PASSWORD' => Class_AdminVar_Meta::newDefault($this->_('Mot de passe de d\'utilisateur fourni par musicMe pour accéder au dépot de ressources'))->bePrivate(),
+             'COVER_IMG_URL' => Class_AdminVar_Meta::newDefault($this->_('Url du dépot des images de musicMe'),
+                                                                ['value' => 'https://covers.hosting-media.net/jpgr575'] )->bePrivate()],
 
             'SsoAction' => true,
             'Batch' => 'Musicme_Batch',
diff --git a/library/digital_resources/Musicme/Service.php b/library/digital_resources/Musicme/Service.php
index f6e5aa5bfa1..6a9184a4cbe 100644
--- a/library/digital_resources/Musicme/Service.php
+++ b/library/digital_resources/Musicme/Service.php
@@ -28,7 +28,9 @@ class Musicme_Service extends Class_DigitalResource_Service {
   protected function loadPage($page_number = 1) {
     $client = $this->getHttpClient();
 
-    $xml = gzdecode($this->httpGet($this->_config->getHarvestUrl()));
+    $xml = gzdecode($this->httpGet($this->_config->getHarvestUrl(),
+                                   ['auth' => ['user' => $this->_config->getAdminVar('EXPORT_USERNAME'),
+                                               'password' => $this->_config->getAdminVar('EXPORT_PASSWORD')] ]));
 
     $this->_parser = new Musicme_Service_XMLParser();
     $this->_parser->parseXML($xml);
diff --git a/library/digital_resources/Musicme/tests/MusicmeTest.php b/library/digital_resources/Musicme/tests/MusicmeTest.php
index ad35307a8ac..7865a4bfd83 100644
--- a/library/digital_resources/Musicme/tests/MusicmeTest.php
+++ b/library/digital_resources/Musicme/tests/MusicmeTest.php
@@ -26,6 +26,8 @@ class MusicmeFixtures {
     Class_AdminVar::newInstanceWithId('Musicme_BIB_ID', ['valeur' => 'QUEST']);
     Class_AdminVar::newInstanceWithId('Musicme_URL', ['valeur' => 'http://linkmusicme.com']);
     Class_AdminVar::newInstanceWithId('Musicme_EXPORT_URL', ['valeur' => 'http://easyaxe.musicme.com/partnerstop.xml.gz']);
+    Class_AdminVar::newInstanceWithId('Musicme_EXPORT_USERNAME', ['valeur' => 'LM-UTA']);
+    Class_AdminVar::newInstanceWithId('Musicme_EXPORT_PASSWORD', ['valeur' => 'UIEurstiure789789123T']);
     Class_AdminVar::newInstanceWithId('Musicme_COVER_IMG_URL', ['valeur' => 'http://easyaxecover.com']);
     return $this;
   }
@@ -35,27 +37,36 @@ class MusicmeFixtures {
     Class_AdminVar::newInstanceWithId('Musicme_BIB_ID', ['valeur' => '']);
     Class_AdminVar::newInstanceWithId('Musicme_URL', ['valeur' => '']);
     Class_AdminVar::newInstanceWithId('Musicme_EXPORT_URL', ['valeur' => '']);
+    Class_AdminVar::newInstanceWithId('Musicme_EXPORT_USERNAME', ['valeur' => '']);
+    Class_AdminVar::newInstanceWithId('Musicme_EXPORT_PASSWORD', ['valeur' => '']);
     Class_AdminVar::newInstanceWithId('Musicme_COVER_IMG_URL', ['valeur' => '']);
     return $this;
   }
 
+
   public function prepare() {
     $musicme_xml = file_get_contents(__DIR__ . '/musicme.xml.gz');
-    $http_client = $this->mock()
-                        ->whenCalled('open_url')
-                        ->with('http://easyaxe.musicme.com/partnerstop.xml.gz')
-                        ->answers($musicme_xml)
-                        ->whenCalled('open_url')
-                        ->with('http://easyaxecover.com/u0000000063128.jpg')
-                        ->answers(true)
-                        ->whenCalled('open_url')
-                        ->with('http://easyaxecover.com/u0190295740580.jpg')
-                        ->answers(true)
-                        ->whenCalled('open_url')
-                        ->with('http://easyaxecover.com/u0008811031725.jpg')
-                        ->answers(true);
+    $http_client =
+      $this->mock()
+           ->whenCalled('open_url')
+           ->with('http://easyaxe.musicme.com/partnerstop.xml.gz',
+                  ['auth' => ['user' => 'LM-UTA',
+                              'password' => 'UIEurstiure789789123T']])
+           ->answers($musicme_xml)
+
+           ->whenCalled('open_url')
+           ->with('http://easyaxecover.com/u0000000063128.jpg')
+           ->answers(true)
 
+           ->whenCalled('open_url')
+           ->with('http://easyaxecover.com/u0190295740580.jpg')
+           ->answers(true)
 
+           ->whenCalled('open_url')
+           ->with('http://easyaxecover.com/u0008811031725.jpg')
+           ->answers(true)
+
+           ->beStrict();
 
     Musicme_Service::setDefaultHttpClient($http_client);
 
@@ -357,7 +368,6 @@ class MusicmeViewRecordTest extends AbstractControllerTestCase {
     (new MusicmeFixtures())->logValidUser();
     $this->dispatch('/modules/musicme/album_id/1', true);
     $this->assertXPathContentContains('//script', 'http://linkmusicme.com/Nils-Van-Zandt/albums/Destination-Paradise-0000000063128.html?iduser=tom&ticket=ST-' . md5(Zend_Session::getId() . '1') . '&MediaLibraryID=QUEST&service=');
-
   }
 
 
-- 
GitLab