Skip to content
Snippets Groups Projects
Commit 76a8ed9d authored by Sebastien ANDRE's avatar Sebastien ANDRE
Browse files

Merge branch 'hotline#198520_nanook_unique_casses' into 'master'

[RTKO] hotline : #198520 : single nannok with similar urls

See merge request !4968
parents 3883ff71 fd9b35db
Branches
Tags
1 merge request!4968[RTKO] hotline : #198520 : single nannok with similar urls
Pipeline #32188 passed with stage
in 20 minutes and 54 seconds
- correctif #198520 : SIGB Nanook : Correction du mode Nanook unique.
\ No newline at end of file
......@@ -20,10 +20,13 @@
*/
class Cosmo_IndexTest extends CosmoControllerTestCase {
class Cosmo_IndexTest extends CosmoControllerTestCase
{
public function setUp() {
public function setUp()
{
parent::setUp();
Class_IntBib::setTimeSource(new TimeSourceForTest('2021-10-16'));
$this->fixture(Class_IntBib::class,
......@@ -119,61 +122,71 @@ class Cosmo_IndexTest extends CosmoControllerTestCase {
/** @test */
public function indexShouldContainsH1Administration() {
public function indexShouldContainsH1Administration()
{
$this->assertXPathContentContains('//h1', 'Administration');
}
/** @test */
public function shouldContainsCurrentBokehVersion() {
public function shouldContainsCurrentBokehVersion()
{
$this->assertXPathContentContains('//p', 'Version : ' . BOKEH_RELEASE_NUMBER);
}
/** @test */
public function uniqueNanookShouldBeDisplay() {
public function uniqueNanookShouldBeDisplay()
{
$this->assertXPathContentContains('//p', 'Mode Nanook unique : Non');
}
/** @test */
public function shouldContainsAccesAdminSys() {
public function shouldContainsAccesAdminSys()
{
$this->assertXPathContentContains('//p', 'Accès : Administrateur système');
}
/** @test */
public function shouldContainsLastIntegration() {
public function shouldContainsLastIntegration()
{
$this->assertXPathContentContains('//p', 'Dernier traitement d\'intégration effectué le : 14 October 2021');
}
/** @test */
public function shouldContainsNoWaitingIntegrations() {
public function shouldContainsNoWaitingIntegrations()
{
$this->assertXPathContentContains('//p', 'Tous les fichiers en attente ont été intégrés.');
}
/** @test */
public function shouldContains2NoticesSuccinctesAndOneWaiting() {
public function shouldContains2NoticesSuccinctesAndOneWaiting()
{
$this->assertXPathContentContains('//p', 'Il reste 2 notices succinctes dont 1 en attente de traitement ( Class_CosmoVar Z3950_retry_level = 3 ) .');
}
/** @test */
public function shouldContainsNoLateSendFile() {
public function shouldContainsNoLateSendFile()
{
$this->assertXPathContentContains('//p', 'Toutes les bibliothèques à alerter sont à jour de leurs envois de fichiers');
}
/** @test */
public function shouldContainsTwdHistoricalIntegrationsDataForTenKiloBytes() {
public function shouldContainsTwdHistoricalIntegrationsDataForTenKiloBytes()
{
$this->assertXPathContentContains('//p', 'Il y a 2 paniers conservés dans /cosmo/integration/ pour une taille de : 10 ko');
}
/** @test */
public function shouldContainsTwoHistoricalIntegrationsLogsFilesForOneHundredKiloBytes() {
public function shouldContainsTwoHistoricalIntegrationsLogsFilesForOneHundredKiloBytes()
{
$this->assertXPathContentContains('//p', 'Il y a 2 fichiers de logs conservés dans /cosmo/log/ pour une taille de : 100 ko');
}
}
......@@ -181,9 +194,11 @@ class Cosmo_IndexTest extends CosmoControllerTestCase {
class CosmoIndexWithDangerTest extends CosmoControllerTestCase {
class CosmoIndexWithDangerTest extends CosmoControllerTestCase
{
public function setUp() {
public function setUp()
{
parent::setUp();
Class_CosmoVar::setValueOf('integration_frequence', 2);
......@@ -224,31 +239,36 @@ class CosmoIndexWithDangerTest extends CosmoControllerTestCase {
/** @test */
public function shouldContainsWaitingIntegrations() {
public function shouldContainsWaitingIntegrations()
{
$this->assertXPathContentContains('//p', 'Il reste 1 fichier(s) en attente d\'intégration.');
}
/** @test */
public function shouldContainsIntegrationProcessDidntRunSince() {
public function shouldContainsIntegrationProcessDidntRunSince()
{
$this->assertXPathContentContains('//p[@class="error"]', 'Les traitements d\'intégration n\'ont pas été effectués depuis 13 jour(s)');
}
/** @test */
public function lateLibraryLastInDay() {
public function lateLibraryLastInDay()
{
$this->assertXPathContentContains('//p', 'Retard 13 jour(s)');
}
/** @test */
public function shouldContainsNoLogPathErrorMessage() {
public function shouldContainsNoLogPathErrorMessage()
{
$this->assertXPathContentContains('//p[@class="error"]', 'Vous devez définir un chemin de dossier pour les fichiers de log');
}
/** @test */
public function shouldContainsNoIntegrationPathErrorMessage() {
public function shouldContainsNoIntegrationPathErrorMessage()
{
$this->assertXPathContentContains('//p[@class="error"]', 'La variable integration_path n\'est pas définie.');
}
}
......@@ -256,9 +276,11 @@ class CosmoIndexWithDangerTest extends CosmoControllerTestCase {
class CosmoIndexWithLockedDatabaseTest extends CosmoControllerTestCase {
class CosmoIndexWithLockedDatabaseTest extends CosmoControllerTestCase
{
public function setUp() {
public function setUp()
{
parent::setUp();
Class_CosmoVar::setValueOf('clef_traitements', 1);
......@@ -268,7 +290,8 @@ class CosmoIndexWithLockedDatabaseTest extends CosmoControllerTestCase {
/** @test */
public function shouldContainsLockedDatabase() {
public function shouldContainsLockedDatabase()
{
$this->assertXPathContentContains('//p[@class="error"]', 'La base est bloquée à la phase de traitement : notice');
}
}
......@@ -276,30 +299,54 @@ class CosmoIndexWithLockedDatabaseTest extends CosmoControllerTestCase {
class CosmoIndexWithSingleNanookYesTest extends CosmoControllerTestCase {
protected $_storm_default_to_volatile = true;
class CosmoIndexWithSingleNanookYesTest extends CosmoControllerTestCase
{
public function setUp() {
public function setUp()
{
parent::setUp();
$this->fixture(Class_IntBib::class,
['id' => 32,
'nom_court' => 'BEZU',
'sigb' => 13,
'url_server' => 'https://monsuper-server-nanook.fr']);
'comm_sigb' => Class_IntBib::COM_NANOOK,
'comm_params' => ['url_serveur' => 'http://monsuper-server-nanook.fr']]);
$this->fixture(Class_IntBib::class,
['id' => 33,
'nom_court' => 'CHATEAU',
'sigb' => 13,
'comm_sigb' => Class_IntBib::COM_NANOOK,
'comm_params' => ['url_serveur' => 'monsuper-server-nanook.fr']]);
$this->fixture(Class_IntBib::class,
['id' => 34,
'nom_court' => 'ETREPAGNY',
'sigb' => 13,
'comm_sigb' => Class_IntBib::COM_NANOOK,
'comm_params' => ['url_serveur' => 'http://monsuper-server-nanook.fr/']]);
$this->fixture(Class_IntBib::class,
['id' => 36,
'nom_court' => 'ELOI',
'sigb' => 13,
'url_server' => 'https://monsuper-server-nanook.fr']);
'comm_sigb' => Class_IntBib::COM_NANOOK,
'comm_params' => ['url_serveur' => ' http://monsuper-server-nanook.fr/ ']]);
$this->fixture(Class_IntBib::class,
['id' => 37,
'nom_court' => 'OAI',
'sigb' => 0,
'comm_sigb' => Class_IntBib::COM_NONE]);
$this->dispatch('/cosmo/index');
}
/** @test */
public function uniqueNanookShouldBeYes() {
public function uniqueNanookShouldBeYes()
{
$this->assertXPathContentContains('//p', 'Mode Nanook unique : Oui');
}
}
......@@ -307,12 +354,11 @@ class CosmoIndexWithSingleNanookYesTest extends CosmoControllerTestCase {
class CosmoIndexWithSingleNanookNoTest extends CosmoControllerTestCase {
protected $_storm_default_to_volatile = true;
class CosmoIndexWithSingleNanookNoTest extends CosmoControllerTestCase
{
public function setUp() {
public function setUp()
{
parent::setUp();
$this->fixture(Class_IntBib::class,
......@@ -332,7 +378,7 @@ class CosmoIndexWithSingleNanookNoTest extends CosmoControllerTestCase {
$this->fixture(Class_IntBib::class,
['id' => 34,
'nom_court' => 'ETREPAGNY',
'sigb' => 12,
'sigb' => Class_IntBib::SIGB_KOHA,
'comm_sigb' => Class_IntBib::COM_KOHA,
'comm_params' => ['url_serveur' => 'http://monsuper-server-nanook.fr']]);
......@@ -341,55 +387,68 @@ class CosmoIndexWithSingleNanookNoTest extends CosmoControllerTestCase {
'nom_court' => 'ELOI',
'sigb' => 13,
'comm_sigb' => Class_IntBib::COM_NANOOK,
'comm_params' => ['url_serveur' => 'https://monsuper-server-nanook.fr']]);
'comm_params' => ['url_serveur' => 'https://monsuper-server-nanook.fr/']]);
$this->fixture(Class_IntBib::class,
['id' => 37,
'nom_court' => 'MICHA',
'sigb' => 13,
'comm_sigb' => Class_IntBib::COM_NANOOK,
'comm_params' => ['url_serveur' => 'https://monsuper-server-nanook.fr']]);
'comm_params' => ['url_serveur' => ' https://monsuper-server-nanook.fr ']]);
$this->fixture(Class_IntBib::class,
['id' => 38,
'nom_court' => 'OAI',
'sigb' => 0,
'comm_sigb' => Class_IntBib::COM_NONE]);
$this->dispatch('/cosmo/index');
}
/** @test */
public function uniqueNanookShouldBeNo() {
public function uniqueNanookShouldBeNo()
{
$this->assertXPathContentContains('//p', 'Mode Nanook unique : Non');
}
/** @test */
public function messageEtrepagnyIsUsingKohaShouldBeDisplay() {
public function messageEtrepagnyIsUsingKohaShouldBeDisplay()
{
$this->assertXPathContentContains('//p', 'L\'integration ETREPAGNY a pour SIGB : Koha .');
}
/** @test */
public function linkToETREPAGNYDashboardShouldBeDisplay() {
public function linkToETREPAGNYDashboardShouldBeDisplay()
{
$this->assertXPath('//p/a[@href="/cosmo/integration/dashboard/id/34"]/i[@class="fa fa-bug"]');
}
/** @test */
public function messageBezuIsUsingUrlServerInHttpsShouldBeDisplay() {
$this->assertXPathContentContains('//p', 'L\'integration BEZU a pour url_server : https://monsuper-server-nanook.fr/ . Cette url_serveur est utilisée dans 2 autres intégrations');
public function messageBezuIsUsingUrlServerInHttpsShouldBeDisplay()
{
$this->assertXPathContentContains('//p', 'L\'integration BEZU a pour url_server : https://monsuper-server-nanook.fr . Cette url_serveur est utilisée dans 2 autres intégrations');
}
/** @test */
public function messageChateauIsUsingUrlServerInHttpShouldBeDisplay() {
$this->assertXPathContentContains('//p', 'L\'integration CHATEAU a pour url_server : http://monsuper-server-nanook.fr/ .');
public function messageChateauIsUsingUrlServerInHttpShouldBeDisplay()
{
$this->assertXPathContentContains('//p', 'L\'integration CHATEAU a pour url_server : http://monsuper-server-nanook.fr .');
}
}
class CosmoIndexWithLatePatchLevelTest extends CosmoControllerTestCase {
class CosmoIndexWithLatePatchLevelTest extends CosmoControllerTestCase
{
public function setUp() {
public function setUp()
{
parent::setUp();
Class_CosmoVar::setValueOf('log_path', '/cosmo/log/');
......@@ -401,7 +460,8 @@ class CosmoIndexWithLatePatchLevelTest extends CosmoControllerTestCase {
/** @test */
public function shouldContainsAnchorToRunPatchLevel() {
public function shouldContainsAnchorToRunPatchLevel()
{
$this->assertXPathContentContains('//p[@class="error"]//a[@href="/cosmo/database-migration/migrate"]', 'mise à niveau de la base de données');
}
}
......@@ -409,9 +469,11 @@ class CosmoIndexWithLatePatchLevelTest extends CosmoControllerTestCase {
class CosmoIndexWithAdminLoggedTest extends CosmoControllerTestCase {
class CosmoIndexWithAdminLoggedTest extends CosmoControllerTestCase
{
public function setUp() {
public function setUp()
{
parent::setUp();
$_SESSION['passe'] = 'admin_portail';
......@@ -420,7 +482,8 @@ class CosmoIndexWithAdminLoggedTest extends CosmoControllerTestCase {
/** @test */
public function adminPortailShouldBeLogged() {
public function adminPortailShouldBeLogged()
{
$this->assertXPathContentContains('//p', 'Accès : Administrateur du portail');
}
}
......@@ -428,9 +491,11 @@ class CosmoIndexWithAdminLoggedTest extends CosmoControllerTestCase {
class CosmoIndexWithCatalogueurLoggedTest extends CosmoControllerTestCase {
class CosmoIndexWithCatalogueurLoggedTest extends CosmoControllerTestCase
{
public function setUp() {
public function setUp()
{
parent::setUp();
$_SESSION['passe'] = 'catalogueur';
......@@ -439,7 +504,8 @@ class CosmoIndexWithCatalogueurLoggedTest extends CosmoControllerTestCase {
/** @test */
public function adminPortailShouldBeLogged() {
public function adminPortailShouldBeLogged()
{
$this->assertXPathContentContains('//p', 'Accès : Catalogueur');
}
}
......@@ -447,27 +513,32 @@ class CosmoIndexWithCatalogueurLoggedTest extends CosmoControllerTestCase {
class CosmoIndexIntBibSQLTest extends CosmoControllerTestCase {
class CosmoIndexIntBibSQLTest extends CosmoControllerTestCase
{
protected array $_storm_scopes = ['IntBibLoader',
'NoticeSuccincteLoader'];
protected bool $_storm_mock_zend_adapter = true;
public function setUp() {
public function setUp()
{
parent::setUp();
Class_CosmoVar::set('Z3950_retry_level', 0);
Class_CosmoVar::setValueOf('Z3950_retry_level', 0);
$this->dispatch('/cosmo/index');
}
/** @test */
public function intBibLoaderShouldGenerateEcartAjoutGreaterThanZero() {
public function intBibLoaderShouldGenerateEcartAjoutGreaterThanZero()
{
$this->assertSql('SELECT `int_bib`.* FROM `int_bib` WHERE (`int_bib`.`mail` != \'\' AND `int_bib`.`dernier_ajout` != \'0000-00-00\' AND `int_bib`.`ecart_ajouts` > \'0\') ORDER BY `int_bib`.`nom_court` ASC');
}
/** @test */
public function noticeSuccincteLoaderShouldGenerateZ3950LeserThanZero() {
$this->assertSql('SELECT `notices_succintes`.* FROM `notices_succintes` WHERE (`notices_succintes`.`z3950_retry` < 0)');
public function noticeSuccincteLoaderShouldGenerateZ3950LeserThanZero()
{
$this->assertSql('SELECT COUNT(*) AS `numberof` FROM `notices_succintes` WHERE (`notices_succintes`.`z3950_retry` < 0)');
}
}
......@@ -20,12 +20,14 @@
*/
class Class_IntBib_SingleSigb {
class Class_IntBib_SingleSigb
{
protected array $_sigbs = [];
protected ?string $_unique_url = null;
public function isSingle() : bool {
public function isSingle(): bool
{
$this->_unique_url = null;
$int_bibs = $this->_intBibs();
......@@ -40,7 +42,29 @@ class Class_IntBib_SingleSigb {
}
public function isSinglePatrons() : bool {
public function urlCountByNanook(): array
{
$rows = Class_IntBib::query()
->select(['nom_court', 'comm_params', Storm_Query_Key::count()])
->eq('sigb', Class_IntBib::SIGB_NANOOK)
->group('comm_params')
->fetchAll();
$models = [];
foreach ($rows as $row) {
if ( ! ($url = $this->_url($this->_unserializeParams($row->getCommParams()))))
continue;
$url_count = ($models [$url] ??= new Class_IntBib_UrlCount($row->getNomCourt()));
$url_count->addCount($row->getCountBy() ?? 1);
}
return $models;
}
public function isSinglePatrons(): bool
{
$aCollection = (new Storm_Model_Collection(Class_IntBib::findAll()))
->select(fn($model) => $model->hasPatronImport());
......@@ -48,7 +72,8 @@ class Class_IntBib_SingleSigb {
}
protected function _isSizeValid(array $int_bibs) : bool {
protected function _isSizeValid(array $int_bibs): bool
{
if ( ! ($count_sigbs = count($this->_sigbs)))
$count_sigbs = 1;
......@@ -56,7 +81,8 @@ class Class_IntBib_SingleSigb {
}
protected function _isSigb(int $sigb) : bool {
protected function _isSigb(int $sigb): bool
{
if ( ! $this->_sigbs)
$this->_sigbs = [$sigb];
......@@ -64,11 +90,12 @@ class Class_IntBib_SingleSigb {
}
protected function _isSameUrl(array $comm_params) : bool {
protected function _isSameUrl(array $comm_params): bool
{
foreach (array_filter(array_unique($comm_params)) as $params) {
$params = $this->_unserializeParams($params);
if ( ! ($url = $params['url_serveur'] ?? ''))
if ( ! ($url = $this->_url($params)))
continue;
$this->_unique_url ??= $url;
......@@ -80,7 +107,8 @@ class Class_IntBib_SingleSigb {
}
protected function _unserializeParams(string $params) : array {
protected function _unserializeParams(string $params): array
{
try {
return $params && ($results = unserialize($params))
? $results
......@@ -91,7 +119,17 @@ class Class_IntBib_SingleSigb {
}
protected function _intBibs() : array {
protected function _url(array $params): string
{
if ( ! ($url = trim(($params['url_serveur'] ?? ''), " \n\r\t\v\x00\/")))
return '';
return Class_WebService_SIGB_AbstractRESTService::withProtocol($url);
}
protected function _intBibs(): array
{
$rows = Class_IntBib::query()
->select(['sigb', 'comm_params'])
->not_eq('sigb', Class_IntBib::SIGB_NONE)
......
<?php
/**
* Copyright (c) 2012-2024, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_IntBib_UrlCount
{
protected string $_name = '';
protected int $_count = 0;
public function __construct(string $name)
{
$this->_name = $name;
}
public function addCount(int $count): self
{
$this->_count += $count;
return $this;
}
public function getName(): string
{
return $this->_name;
}
public function getCount(): int
{
return $this->_count - 1;
}
}
......@@ -36,23 +36,26 @@ abstract class Class_WebService_SIGB_AbstractRESTService extends Class_WebServic
}
public static function withProtocol(string $url): string
{
$protocol = ('http://' === substr($url, 0, 7) || 'https://' === substr($url, 0, 8))
? ''
: 'http://';
return $protocol . $url;
}
/**
* @param string $server_root
* @return Class_WebService_SIGB_AbstractRESTService
*/
public function setServerRoot($server_root) {
$this->_server_root = $this->_withProtocol($server_root);
$this->_server_root = static::withProtocol($server_root);
return $this;
}
protected function _withProtocol($url) {
return ('http://' == substr($url, 0, 7) || 'https://' == substr($url, 0, 8)
? '' : 'http://')
. $url;
}
/**
* @return string
*/
......
......@@ -140,7 +140,7 @@ class ZendAfi_View_Helper_Cosmo_Index extends ZendAfi_View_Helper_BaseHelper {
protected function _addNonNanookIntegrations(array $html) : array {
foreach (Class_IntBib::query()
->not_eq('sigb', Class_IntBib::SIGB_NANOOK)
->not_in('sigb', [Class_IntBib::SIGB_NANOOK, Class_IntBib::SIGB_NONE])
->fetchAll() as $int_bib)
$html [] = $this->view->tagError($this->_('L\'integration %s a pour SIGB : %s . %s',
$int_bib->getNomCourt(),
......@@ -152,33 +152,17 @@ class ZendAfi_View_Helper_Cosmo_Index extends ZendAfi_View_Helper_BaseHelper {
null, true),
$this->view->renderIcon('class fa fa-bug'))));
$urls_server = [];
foreach (Class_IntBib::findAllBy(['sigb' => Class_IntBib::SIGB_NANOOK]) as $int_bib) {
$url_server = $int_bib->getUrlServer();
if (array_key_exists($url_server, $urls_server)) {
$urls_server [$url_server] += 1;
continue;
}
$urls_server [$url_server] = 0;
$html [$url_server] = $this->_('L\'integration %s a pour url_server : %s .',
$int_bib->getNomCourt(),
$url_server);
}
foreach ($html as $url_server => $notice) {
if ( ! $url_server)
continue;
$count = $urls_server[$url_server] ?? 0;
$message = $html [$url_server];
foreach ((new Class_IntBib_SingleNanook)->urlCountByNanook() as $url => $url_count) {
$message = $this->_('L\'integration %s a pour url_server : %s .',
$url_count->getName(),
$url);
$count = $url_count->getCount();
$others = $this->_plural($count,
'Cette url_serveur n\'est pas utilisée dans une autre intégration.',
'Cette url_serveur est utilisée dans %s seule autre intégration.',
'Cette url_serveur est utilisée dans %s autres intégrations.',
$count);
$html [$url_server] = $this->view->tagWarning(implode(' ', [$message, $others]));
$html [$url] = $this->view->tagWarning(implode(' ', [$message, $others]));
}
return $html;
......
......@@ -375,12 +375,12 @@ class IntBibSingleSigbTest extends ModelTestCase {
['id' => 78,
'sigb' => Class_IntBib::SIGB_ORPHEE,
'comm_sigb' => Class_IntBib::COM_ORPHEE,
'comm_params' => 'a:1:{s:11:"url_serveur";s:53:"http://nanookws.afi-sa.net/afi_NanookWs/ilsdi/meylan/";}']);
'comm_params' => 'a:1:{s:11:"url_serveur";s:52:"http://nanookws.afi-sa.net/afi_NanookWs/ilsdi/meylan";}']);
$this->fixture(Class_IntBib::class,
['id' => 79,
'sigb' => Class_IntBib::SIGB_ORPHEE,
'comm_sigb' => Class_IntBib::COM_ORPHEE,
'comm_params' => 'a:2:{s:11:"url_serveur";s:53:"http://nanookws.afi-sa.net/afi_NanookWs/ilsdi/meylan/";s:15:"provide_suggest";s:1:"1";}']);
'comm_params' => 'a:2:{s:11:"url_serveur";s:48:" nanookws.afi-sa.net/afi_NanookWs/ilsdi/meylan/ ";s:15:"provide_suggest";s:1:"1";}']);
$this->assertTrue(Class_IntBib::isSingleSigb());
}
......
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