Commit 6129a8ad authored by Patrick Barroca's avatar Patrick Barroca 🎮

Merge branch...

Merge branch 'dev#88526_nanookbokeh_pouvoir_afficher_une_notice_a_partir_de_l_identifiant_sigb_dans_l_url' into 'master'

dev #88526 add url recherche/viewnotice/id_sigb/xxx/id_site/xxx to open a record from Nanook

See merge request afi/opacce!3114
parents fc2048c1 4f02132b
- ticket #88526 : intégration Nanook/Bokeh: possibilité d'accéder directement à une notice Bokeh depuis Nanook
\ No newline at end of file
......@@ -28,7 +28,9 @@ class ErrorController extends ZendAfi_Controller_Action {
if (isset($errors->exception) && (404 == $errors->exception->getCode()))
return $this->_renderPageNotFound($errors->exception);
$this->_response->setHttpResponseCode(500);
$this->_response->setHttpResponseCode($this->_isHTTPErrorCode($errors->exception->getCode())
? $errors->exception->getCode()
: 500);
$this->_response->clearBody();
if (($this->_request->getServer('HTTP_HOST') == 'localhost')
......@@ -51,4 +53,88 @@ class ErrorController extends ZendAfi_Controller_Action {
$this->view->exception = $exception;
$this->renderScript('error/404.phtml');
}
protected function _isHTTPErrorCode($code) {
$http_codes = [
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing', // WebDAV; RFC 2518
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information', // since HTTP/1.1
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',
207 => 'Multi-Status', // WebDAV; RFC 4918
208 => 'Already Reported', // WebDAV; RFC 5842
226 => 'IM Used', // RFC 3229
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
303 => 'See Other', // since HTTP/1.1
304 => 'Not Modified',
305 => 'Use Proxy', // since HTTP/1.1
306 => 'Switch Proxy',
307 => 'Temporary Redirect', // since HTTP/1.1
308 => 'Permanent Redirect', // approved as experimental RFC
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Timeout',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request-URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Requested Range Not Satisfiable',
417 => 'Expectation Failed',
418 => 'I\'m a teapot', // RFC 2324
419 => 'Authentication Timeout', // not in RFC 2616
420 => 'Enhance Your Calm', // Twitter
420 => 'Method Failure', // Spring Framework
422 => 'Unprocessable Entity', // WebDAV; RFC 4918
423 => 'Locked', // WebDAV; RFC 4918
424 => 'Failed Dependency', // WebDAV; RFC 4918
424 => 'Method Failure', // WebDAV)
425 => 'Unordered Collection', // Internet draft
426 => 'Upgrade Required', // RFC 2817
428 => 'Precondition Required', // RFC 6585
429 => 'Too Many Requests', // RFC 6585
431 => 'Request Header Fields Too Large', // RFC 6585
444 => 'No Response', // Nginx
449 => 'Retry With', // Microsoft
450 => 'Blocked by Windows Parental Controls', // Microsoft
451 => 'Redirect', // Microsoft
451 => 'Unavailable For Legal Reasons', // Internet draft
494 => 'Request Header Too Large', // Nginx
495 => 'Cert Error', // Nginx
496 => 'No Cert', // Nginx
497 => 'HTTP to HTTPS', // Nginx
499 => 'Client Closed Request', // Nginx
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported',
506 => 'Variant Also Negotiates', // RFC 2295
507 => 'Insufficient Storage', // WebDAV; RFC 4918
508 => 'Loop Detected', // WebDAV; RFC 5842
509 => 'Bandwidth Limit Exceeded', // Apache bw/limited extension
510 => 'Not Extended', // RFC 2774
511 => 'Network Authentication Required', // RFC 6585
598 => 'Network read timeout error', // Unknown
599 => 'Network connect timeout error'];
return isset($http_codes[$code]);
}
}
\ No newline at end of file
......@@ -300,10 +300,47 @@ class RechercheController extends ZendAfi_Controller_Action {
}
protected function _isViewNoticeRequestFromSIGB() {
return $this->_getParam('id_sigb') || $this->_getParam('id_site');
}
protected function _handleViewNoticeRequestFromSIGB() {
if (!$id_sigb = $this->_getParam('id_sigb'))
return $this->_badRequestError($this->_('Paramètre id_sigb obligatoire'));
if (!$id_site = $this->_getParam('id_site'))
return $this->_badRequestError($this->_('Paramètre id_site obligatoire'));
if (!$annex = Class_CodifAnnexe::findFirstBy(['id_origine' => $id_site]))
return $this->_recordDoesNotExistsError();
if (!$item = Class_Exemplaire::findFirstBy(['id_origine' => $id_sigb,
'id_bib' => $annex->getIdBib()]))
return $this->_recordDoesNotExistsError();
return $this->_redirect('/recherche/viewnotice/id/' . $item->getIdNotice());
}
protected function _badRequestError($message) {
throw new Zend_Controller_Action_Exception($message, 400);
}
protected function _recordDoesNotExistsError() {
throw new Zend_Controller_Action_Exception($this->view->_('Désolé, aucun document ne correspond aux critères transmis'),
404);
}
public function viewnoticeAction() {
if ($authority_record = $this->_authorityFromParams())
return $this->_redirect('/opac/recherche/viewnotice/id/' . $authority_record->getId());
if ($this->_isViewNoticeRequestFromSIGB())
return $this->_handleViewNoticeRequestFromSIGB();
$id_notice = (int)$this->_getParam('id');
$clef_alpha = (string)$this->_getParam('clef');
......
<h1>Une erreur est survenue</h1>
<?php echo $this->error($this->errors);?>
\ No newline at end of file
<h1><?php echo $this->_('Une erreur est survenue') ?></h1>
<?php echo $this->error($this->errors);?>
......@@ -37,4 +37,10 @@ class ErrorControllerTest extends AbstractControllerTestCase {
public function actionShouldBeError() {
$this->assertAction('error');
}
/** @test */
public function httpStatusCodeShouldBe404() {
$this->assertResponseCode(404);
}
}
......@@ -82,13 +82,15 @@ abstract class RechercheControllerNoticeTestCase extends AbstractControllerTestC
'facettes' => 'A123 F2 G1 P4 Y2 B1 Lfre M1 Z3 D1',
'date_creation' => '2013-12-31',
'unimarc' => file_get_contents(ROOT_PATH . 'tests/fixtures/bernard_genin.uni')])
->setExemplaires([Class_Exemplaire::getLoader()->newInstanceWithId(34)
->setIdBib('456')
->setIdOrigine('12')
->setCodeBarres('12256663233656')
->setSigbExemplaire($this->mock()
->whenCalled('isReservable')
->answers(true))]);
->setExemplaires([$this->fixture('Class_Exemplaire',
['id' => 34,
'id_bib' => 456,
'id_origine' => 12,
'code_barres' => '12256663233656',
'sigb_exemplaire' => ($this->mock()
->whenCalled('isReservable')
->answers(true))
])]);
}
}
......@@ -604,6 +606,54 @@ class RechercheControllerViewNoticeTest extends RechercheControllerNoticeTestCas
class RechercheControllerViewNoticeByIdSigbTest extends RechercheControllerNoticeTestCase {
public function setUp() {
parent::setUp();
$this->fixture('Class_CodifAnnexe',
['id' => 1,
'id_bib' => 456,
'id_origine' => 2]);
}
/** @test */
public function withRightIdsResponseShouldRedirectToViewNoticeId345() {
$this->dispatch('/recherche/viewnotice/id_sigb/12/id_site/2');
$this->assertRedirectTo('/recherche/viewnotice/id/345');
}
/** @test */
public function withUnknownIdSiteShouldThrow404() {
$this->dispatch('/recherche/viewnotice/id_sigb/12/id_site/3', false);
$this->assertResponseCode(404);
}
/** @test */
public function withUnknownIdSigbShouldThrow404() {
$this->dispatch('/recherche/viewnotice/id_sigb/66/id_site/2', false);
$this->assertResponseCode(404);
}
/** @test */
public function withNoIdSigbShouldThrow400() {
$this->dispatch('/recherche/viewnotice/id_site/2', false);
$this->assertResponseCode(400);
}
/** @test */
public function withNoIdSiteShouldThrow400() {
$this->dispatch('/recherche/viewnotice/id_sigb/12', false);
$this->assertResponseCode(400);
}
}
class RechercheControllerViewNoticeMetasTest extends RechercheControllerNoticeTestCase {
public function setUp() {
parent::setUp();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment