diff --git a/FEATURES/178946 b/FEATURES/178946 new file mode 100644 index 0000000000000000000000000000000000000000..d19d73c21dbc4089c105a43d67d3c0a1f208ffbc --- /dev/null +++ b/FEATURES/178946 @@ -0,0 +1,10 @@ + '178946' => + ['Label' => $this->_('Cafeyn : résultat de recherche : tri par date de nouveauté possible'), + 'Desc' => $this->_('Il est possible de trier les ressources numériques Cafeyn par date : la date de sortie du magazine corresponds à la date de nouveauté'), + 'Image' => '', + 'Video' => '', + 'Category' => 'Ressources Numériques', + 'Right' => function($feature_description, $user) {return true;}, + 'Wiki' => '', + 'Test' => '', + 'Date' => '2023-05-24'], \ No newline at end of file diff --git a/VERSIONS_WIP/178946 b/VERSIONS_WIP/178946 new file mode 100644 index 0000000000000000000000000000000000000000..095be696770ba3787ab04a253da63372ef8fee52 --- /dev/null +++ b/VERSIONS_WIP/178946 @@ -0,0 +1 @@ + - fonctionnalité #178946 : Ressource Numérique Cafeyn : Résultat de recherche : possibilité de tri par date de nouveauté. \ No newline at end of file diff --git a/library/Class/Album.php b/library/Class/Album.php index 2ae4cd977334c8948145acde278f2b15093fd3f0..68ed5169c91fb2a5b80fb81a3ec3d3eaad2a3413 100644 --- a/library/Class/Album.php +++ b/library/Class/Album.php @@ -69,6 +69,7 @@ class Class_Album extends Storm_Model_Abstract { const VIDEO_URL_TYPE = 'video'; const DURATION_FIELD = '215$a'; const MISC_FIELD = '215$c'; + const RELEASE_DATE_FIELD = '210$d'; const FORMAT_FIELD = '215$d'; const URI_TYPE_POSTER = 'poster'; const URI_TYPE_TRAILER = 'trailer'; @@ -1208,6 +1209,17 @@ class Class_Album extends Storm_Model_Abstract { } + public function setReleaseDate(string $datetime) : self { + $this->addNote(self::RELEASE_DATE_FIELD, $datetime); + return $this; + } + + + public function getReleaseDate() : string { + return $this->getNote(self::RELEASE_DATE_FIELD) ?? ''; + } + + public function getMisc() { return $this->getNote(self::MISC_FIELD); } diff --git a/library/Class/Indexation/PseudoNotice.php b/library/Class/Indexation/PseudoNotice.php index 24282ab17e6be2d807ddc11b5b4f75cdf6c06908..4163e1eae4486a25fcb82fd6fd52263822ea6e0a 100644 --- a/library/Class/Indexation/PseudoNotice.php +++ b/library/Class/Indexation/PseudoNotice.php @@ -492,7 +492,8 @@ class Class_Indexation_PseudoNotice_Album extends Class_Indexation_PseudoNotice{ $url_vignette = $this->_model->getThumbnailUrl(); $this->_notice->setUrlVignette($url_vignette); $this->_notice->setUrlImage($url_vignette); - + if ($release_date = $this->_model->getReleaseDate()) + $this->_notice->setDateCreation($this->tryFormatDate($release_date, 'Y-m-d H:i:s')); parent::_index(); } diff --git a/library/Class/WebService/BibNumerique/Abstract.php b/library/Class/WebService/BibNumerique/Abstract.php index 1d3a90f3a15d9b6fb839444c75c7c4e71c2dcba0..11908887e854b7806f11a0cdf2c6f7f9307835ee 100644 --- a/library/Class/WebService/BibNumerique/Abstract.php +++ b/library/Class/WebService/BibNumerique/Abstract.php @@ -89,16 +89,21 @@ abstract class Class_WebService_BibNumerique_Abstract extends Class_WebService_A $harvestedIds = []; foreach ($ressources as $ressource) { $harvestedIds[] = $ressource->getId(); - if ($ressource->isAlreadyHarvested()) + if ($this->_skipAlreadyHarvested() && $ressource->isAlreadyHarvested()) continue; $this->loadRessource($ressource); - $ressource->import(); + $ressource->import(!$this->_skipAlreadyHarvested()); } return $harvestedIds; } + protected function _skipAlreadyHarvested() : bool{ + return true; + } + + public function loadRessource($film) {} @@ -164,4 +169,4 @@ abstract class Class_WebService_BibNumerique_Abstract extends Class_WebService_A public function getName() { return ''; } -} \ No newline at end of file +} diff --git a/library/Class/WebService/BibNumerique/RessourceNumerique.php b/library/Class/WebService/BibNumerique/RessourceNumerique.php index 8d57ad0a19c7b55f73ba193e3af41ceba50ed87f..c5648987b51c817659b4a8515e37364cea23a6ad 100644 --- a/library/Class/WebService/BibNumerique/RessourceNumerique.php +++ b/library/Class/WebService/BibNumerique/RessourceNumerique.php @@ -50,8 +50,8 @@ class Class_WebService_BibNumerique_RessourceNumerique { $_zones = [], $_bibliotheques='', $_authors = [], - $_is_deleted = false; - + $_is_deleted = false, + $_release_date = ''; static public function getLogger() { if (!static::$_logger) @@ -271,11 +271,24 @@ class Class_WebService_BibNumerique_RessourceNumerique { return $this->_zones[$codif]; } + public function setBibliotheques($bibs) { $this->_bibliotheques=$bibs; return $this; } + + public function getReleaseDate() : string{ + return $this->_release_date; + } + + + public function setReleaseDate(string $datetime) : self { + $this->_release_date = $datetime; + return $this; + } + + public function getBibliotheques() { return $this->_bibliotheques; } @@ -396,6 +409,9 @@ class Class_WebService_BibNumerique_RessourceNumerique { if($duration = $this->getDuration()) $album->setDuration($duration); + if ($release_date = $this->getReleaseDate()) + $album->setReleaseDate($release_date); + if($tags = $this->getTags()) $album->setTags($tags); @@ -519,6 +535,7 @@ class Class_WebService_BibNumerique_RessourceNumerique { return $this->_ressources; } + public function isDeleted() { return $this->_is_deleted; } diff --git a/library/Trait/TimeSource.php b/library/Trait/TimeSource.php index 347c694afadf9288d8772623f81c1ce8238bd4ef..a675547667f706ae377ac7a586f840b57294abea 100644 --- a/library/Trait/TimeSource.php +++ b/library/Trait/TimeSource.php @@ -79,7 +79,8 @@ trait Trait_TimeSource { public static function tryFormatDate( string $date_str, string $return_format= 'Y-m-d'): string { $date_str = str_replace( '.0Z', '', $date_str); - $formats=['Y','Y-m-d', 'Y/m/d', 'Ymd', 'YmdHis', 'd-m-Y', 'd/m/Y']; + + $formats=['Y','Y-m-d', 'Y/m/d', 'Ymd', 'YmdHis','Y-m-d*H:i:s', 'd-m-Y', 'd/m/Y']; foreach ($formats as $format) { if ($date = DateTime::createFromFormat($format, $date_str)) diff --git a/library/digital_resources/ArteVod/Service.php b/library/digital_resources/ArteVod/Service.php index e9f1e8703cd5fd80900748689a56e889847d1095..17800deb13e5f6181dc19bbf43245d9c5441ae0f 100644 --- a/library/digital_resources/ArteVod/Service.php +++ b/library/digital_resources/ArteVod/Service.php @@ -68,22 +68,13 @@ class ArteVod_Service extends Class_DigitalResource_Service { } - protected function _importRessources($ressources) { - if(!$ressources) - return []; - $harvestedIds = []; - - - foreach ($ressources as $ressource) { - $harvestedIds[] = $ressource->getId(); - if ($ressource->isAlreadyHarvested() && !$this->_config->getAdminVar( 'BATCH_UPDATE_NOTICE')) - continue; + protected function _skipAlreadyHarvested() : bool{ + return !$this->_config->getAdminVar( 'BATCH_UPDATE_NOTICE'); + } - $this->loadRessource($ressource); - $update=true; - $ressource->import($update); - } + protected function _importRessources($ressources) { + $harvestedIds=parent::_importRessources($ressources); Class_AdminVar::set('ArteVod_BATCH_UPDATE_NOTICE',0); return $harvestedIds; } diff --git a/library/digital_resources/Cafeyn/Config.php b/library/digital_resources/Cafeyn/Config.php index 1cb7fe0b138aac1ebee444fbeb6bd47f042da51f..b612abc306345c29b5b067e2d5aaef2d5cb8aad3 100644 --- a/library/digital_resources/Cafeyn/Config.php +++ b/library/digital_resources/Cafeyn/Config.php @@ -47,6 +47,7 @@ class Cafeyn_Config extends Class_DigitalResource_Config { 'API_ID' => Class_AdminVar_Meta::newDefault($this->_('Identifiant API fourni par Cafeyn'))->bePrivate(), '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(), '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 b24cd4dcec2373fae026cc89405196cc62a1a7d9..fe8ebac11113319fd659ca56391322fa1d9f0747 100644 --- a/library/digital_resources/Cafeyn/Service.php +++ b/library/digital_resources/Cafeyn/Service.php @@ -73,6 +73,11 @@ class Cafeyn_Service extends Class_DigitalResource_Service { } + protected function _skipAlreadyHarvested() : bool{ + return !$this->_config->getAdminVar( 'BATCH_UPDATE_NOTICE'); + } + + public function getCatalogUrl($page_number) { return $this->_config->getHarvestUrl($page_number); } diff --git a/library/digital_resources/Cafeyn/Service/Album.php b/library/digital_resources/Cafeyn/Service/Album.php index 06297bcd672b1c883631bc5320370a7145166c09..711414efd7f1b89c1a1e5bf328943b2e83e3c800 100644 --- a/library/digital_resources/Cafeyn/Service/Album.php +++ b/library/digital_resources/Cafeyn/Service/Album.php @@ -25,6 +25,8 @@ class Cafeyn_Service_Album extends Class_WebService_BibNumerique_RessourceNumeri public function __construct($json) { $year = explode('-', $json->releaseDate ?? '')[0]; + if (isset($json->releaseDate) && ($date = $json->releaseDate)) + $this->setReleaseDate($date); $this->setId(sprintf( '%s:%s', $json->publicationId ?? '', diff --git a/library/digital_resources/Cafeyn/tests/CafeynTest.php b/library/digital_resources/Cafeyn/tests/CafeynTest.php index 4f2b4943c8995977b46b78c500f5f9f419299b67..b6046fdad21c1734c4c50c19a2a5bf3feb62b80a 100644 --- a/library/digital_resources/Cafeyn/tests/CafeynTest.php +++ b/library/digital_resources/Cafeyn/tests/CafeynTest.php @@ -177,9 +177,16 @@ abstract class CafeynServiceTestCase extends AbstractControllerTestCase { $_album, $_service; + public function addFixtures() { + Class_AdminVar::set('Cafeyn_BATCH_UPDATE_NOTICE', '1'); + return $this; + } + + public function setUp() { parent::setUp(); + $this->addFixtures(); CafeynAdminVars::activate(); $json = file_get_contents(__DIR__. '/cafeyn.json'); @@ -200,6 +207,7 @@ abstract class CafeynServiceTestCase extends AbstractControllerTestCase { $this->_service = new Cafeyn_Service($config); Cafeyn_Service::setDefaultHttpClient($http_client); + $this->_service->harvest(); Class_Album::clearCache(); $this->_album = Class_Album::find(1); @@ -212,7 +220,7 @@ abstract class CafeynServiceTestCase extends AbstractControllerTestCase { class CafeynHarvest extends CafeynServiceTestCase { public function getAlbumAttribs() { return [ - ['getTitre','Le quotidien du sport n°7 : 3 avril 2023'], + ['getTitre', 'Le quotidien du sport n°7 : 3 avril 2023'], ['getIdOrigine', '21896447:7'], ['getCategoryLabel', 'Cafeyn'], ['getUrlOrigine', 'https://cafeyn.co/'], @@ -225,7 +233,8 @@ class CafeynHarvest extends CafeynServiceTestCase { ['getDescription', '« Le quotidien du sport » vous permettra de découvrir ou de retrouver tous les héros et les champions du sport.' ], - ['getDateMaj', '2017-02-06 10:00:00'] + ['getDateMaj', '2017-02-06 10:00:00'], + ['getReleaseDate', '2023-04-03T00:00:00'] ]; } @@ -299,6 +308,88 @@ class CafeynDashboardActivatedTest extends CafeynActivatedTestCase { $this->assertXPathContentContains('//h4', 'URL de moissonnage'); $this->assertXPathContentContains('//pre', 'https://harvest-cafeyn/partner/publication/66/flow', $this->_response->getBody()); } +} + + + + +class CafeynHarvestDisableUpdateTest extends CafeynServiceTestCase { + public function setUp() { + parent::setUp(); + Class_Album::find(20)->index(); + } + + + public function addFixtures() { + Class_AdminVar::set('Cafeyn_BATCH_UPDATE_NOTICE', '0'); + $album = $this->fixture('Class_Album', + ['id' => 20, + 'visible' => 1, + 'status' => 3, + 'titre' => '10 moutons', + 'id_origine' => '21896447:7', + 'url_origine' => 'https://cafeyn.co/', + 'type_doc_id' => 'Cafeyn' + ]); + return $this; + } + + + /** @test */ + public function titleShouldNotBeUpdated() { + $this->assertEquals( '10 moutons', + Class_Album::find(20)->getTitre()); + } + + + /** @test */ + public function noticeShouldNotHavePublicationDate() { + $this->assertEquals( '', + Class_Album::find(20)->getNotice()->getDateCreation()); + } +} + + + + +class CafeynHarvestUpdateTest extends CafeynServiceTestCase { + public function setUp() { + parent::setUp(); + Class_Album::find(20)->index(); + } + public function addFixtures() { + $album = $this->fixture('Class_Album', + ['id' => 20, + 'titre' => '10 moutons', + 'visible' => 1, + 'status' => 3, + 'id_origine' => '21896447:7', + 'url_origine' => 'https://cafeyn.co/', + 'type_doc_id' => 'Cafeyn' + ]); + return $this; + } + + + /** @test */ + public function titleShouldBeUpdated() { + $this->assertEquals( 'Le quotidien du sport n°7 : 3 avril 2023', + Class_Album::find(20)->getTitre()); + } + + + /** @test */ + public function publicationDateShouldBeUpdated() { + $this->assertEquals( '2023-04-03T00:00:00', + Class_Album::find(20)->getReleaseDate()); + } + + + /** @test */ + public function noticeShouldHavePublicationDate() { + $this->assertEquals( '2023-04-03 00:00:00', + Class_Album::find(20)->getNotice()->getDateCreation()); + } }