diff --git a/VERSIONS_HOTLINE/160884 b/VERSIONS_HOTLINE/160884 new file mode 100644 index 0000000000000000000000000000000000000000..e4c3b5981064968111bfa7bae09cb393c8148c59 --- /dev/null +++ b/VERSIONS_HOTLINE/160884 @@ -0,0 +1 @@ + - correctif #160884 : Modération : Il est maintenant possible d'utiliser le nouveau format de permalien (/id_sigb/id_origine) des notices pour gérer les avis orphelins. \ No newline at end of file diff --git a/library/Class/FRBR/Link.php b/library/Class/FRBR/Link.php index 5e47ad136b45b5f1753077aaa36911c51989d60e..06a18660dcbacabc7af7f8d39bc7a4ba11a4f3f0 100644 --- a/library/Class/FRBR/Link.php +++ b/library/Class/FRBR/Link.php @@ -336,14 +336,7 @@ class Class_FRBR_Link extends Storm_Model_Abstract { protected function _route($url) { - try { - $request = new Zend_Controller_Request_Http($url); - $router = new ZendAfi_Controller_Router_RewriteWithoutBaseUrl(); - $router->route($request); - return $request; - } catch(Zend_Uri_Exception $e) { - return null; - } + return (new Class_Url)->getRequestFrom($url); } diff --git a/library/Class/Notice/Loader.php b/library/Class/Notice/Loader.php index 84831c8a39e69457c8e7e67717e5907bfc7ba18f..06b017ac556f7d215c9139a2fd71ea6e322ff340 100644 --- a/library/Class/Notice/Loader.php +++ b/library/Class/Notice/Loader.php @@ -126,12 +126,8 @@ class Class_Notice_Loader extends Storm_Model_Loader { return Class_Catalogue::getLoader()->loadNoticesFor($catalogue); } - public function findByUrl($url) { - $frbr_link = new Class_FRBR_Link(); - if (!$clef_alpha = $frbr_link->extractKeyFromUrl($url)) - return; - - return Class_Notice::getNoticeByClefAlpha($clef_alpha); + public function findByUrl(string $url) : ?Class_Notice { + return (new Class_Notice_Permalink)->findBy($url); } diff --git a/library/Class/Notice/Permalink.php b/library/Class/Notice/Permalink.php index 02378b5e66fb8f716f1fefd26417a8125e0b30c1..f1e2e246a108e4ceab29590d91704cebc89b9571 100644 --- a/library/Class/Notice/Permalink.php +++ b/library/Class/Notice/Permalink.php @@ -101,6 +101,7 @@ class Class_Notice_Permalink { $type = (Class_Notice::TYPE_BIBLIOGRAPHIC === $record->getType()) ? [] : ['type' => $record->getType()]; + return Class_Url::relative(array_merge(['module' => 'opac', 'controller' => 'recherche', 'action' => 'viewnotice', @@ -115,4 +116,14 @@ class Class_Notice_Permalink { 'controller'=>'recherche', 'action' => 'simple']; } + + + public function findBy(string $url) : ?Class_Notice { + if ( ! $request = (new Class_Url)->getRequestFrom($url)) + return null; + + return ($clef_alpha = $request->getParam('clef')) + ? Class_Notice::getNoticeByClefAlpha($clef_alpha) + : Class_Notice::find(Class_MoteurRecherche_RecordRequest::answer($request)->recordId()); + } } diff --git a/library/Class/Url.php b/library/Class/Url.php index 0efe7f43a45bf260460d4d6235b1359b34d05d56..4db6528cf47477b5336a1056ff9e44c6ec2bf1b0 100644 --- a/library/Class/Url.php +++ b/library/Class/Url.php @@ -284,4 +284,16 @@ Bokeh Error : adminVar "NOM_DOMAINE" is empty. Bokeh in php cli mode is unable t return static::assemble($url_array_or_string, $name, $reset, $encode); } + + + public function getRequestFrom(string $url) : ?Zend_Controller_Request_Abstract { + try { + $request = new Zend_Controller_Request_Http($url); + $router = new ZendAfi_Controller_Router_RewriteWithoutBaseUrl; + $router->route($request); + return $request; + } catch(Zend_Uri_Exception $e) { + return null; + } + } } diff --git a/tests/application/modules/admin/controllers/ModoControllerTest.php b/tests/application/modules/admin/controllers/ModoControllerTest.php index cca35578ea910c6c4ef84a475a8bb79f1d14096b..a64fb74a49d32818786ca8362559789c2b78c6cd 100644 --- a/tests/application/modules/admin/controllers/ModoControllerTest.php +++ b/tests/application/modules/admin/controllers/ModoControllerTest.php @@ -1290,3 +1290,47 @@ class ModoControllerWithoutUserTest extends Admin_AbstractControllerTestCase { $this->assertXPathContentContains('//table//td', 'Anonyme'); } } + + + + +class ModoControllerRelinkOrphanReviewsPostWithNoDoubleSearchModeTest extends ModoControllerOrphanReviewsTestCase { + + + public function setUp() { + parent::setUp(); + + $this->fixture(Class_Notice::class, + ['id' => 6120, + 'titre_principal' => 'Gilbert & les pommes de terre', + 'clef_alpha' => 'GILBERTLESPOMMESDETERRE--TURRIERF--DIDIER-1997-1', + 'clef_oeuvre' => 'GILBERTLESPOMMESDETERRE-TURRIERF-DIDIER-1997']) + ->setExemplaires([$this->fixture(Class_Exemplaire::class, + ['id' => 999, + 'id_bib' => 1, + 'id_int_bib' => 1, + 'id_origine' => 7890])]); + + $this->postDispatch('/admin/modo/relink-orphan-reviews/id/LESVAMPIRESDEMANHATTANTOME1--DELACRUZM-', + ['clef_oeuvre' => 'LESVAMPIRESDEMANHATTANTOME1--DELACRUZM-', + 'url' => Class_Url::absolute('/recherche/viewnotice/id_sigb/7890/id_int_bib/1')]); + } + + + /** @test */ + public function shouldRedirectToAdminModoManageOrphan() { + $this->assertRedirectTo('/admin/modo/manage-orphan-reviews'); + } + + + /** @test */ + public function shouldNotifyTwoReviewsHaveBeenLinkedToGilbertAndPotatoes() { + $this->assertFlashMessengerContentContains('2 avis contenant la clé oeuvre "LESVAMPIRESDEMANHATTANTOME1--DELACRUZM-" rattaché(s) à la notice "Gilbert & les pommes de terre"'); + } + + + /** @test */ + public function reviewRecordKeyShouldBeGilbertAndPotatoes() { + $this->assertEquals('GILBERTLESPOMMESDETERRE-TURRIERF-DIDIER-1997', Class_AvisNotice::find(2)->getClefOeuvre()); + } +} diff --git a/tests/library/Class/NoticeTest.php b/tests/library/Class/NoticeTest.php index bfa548b31a2e71d28e27c8dbb490e3728466af1e..238dcb3ceb721e5176679ee9f3e68a4eb05269b3 100644 --- a/tests/library/Class/NoticeTest.php +++ b/tests/library/Class/NoticeTest.php @@ -1157,3 +1157,42 @@ class NoticeTitleWithSeveral461Test extends ModelTestCase { $record->getTitrePrincipal(' : ')); } } + + + + +class NoticeFindByUrlTest extends ModelTestCase { + + + public function setUp() { + parent::setUp(); + + $this->fixture(Class_Notice::class, + ['id' => 6120, + 'clef_alpha' => 'GILBERTLESPOMMESDETERRE--TURRIERF--DIDIER-1997-1']) + ->setExemplaires([$this->fixture(Class_Exemplaire::class, + ['id' => 999, + 'id_bib' => 1, + 'id_int_bib' => 1, + 'id_origine' => 7890])]); + } + + + public function urls() : array { + return [['/recherche/viewnotice/id_sigb/7890/id_int_bib/1', true], + ['/recherche/viewnotice/clef/GILBERTLESPOMMESDETERRE--TURRIERF--DIDIER-1997-1', true], + ['/recherche/viewnotice/id/6120', false], + ['/recherche/viewnotice/clef/unknown', false], + ['/recherche/viewnotice/id_sigb/unknown/id_int_bib/1', false], + ['/recherche/viewnotice/id_sigb/7890/id_int_bib/unknown', false]]; + } + + + /** + * @test + * @dataProvider urls + */ + public function withExpectedUrlsRecordsSearchShouldBe(string $url, bool $found) { + $this->assertEquals($found, (bool) Class_Notice::findByUrl(Class_Url::absolute($url))); + } +} \ No newline at end of file