diff --git a/VERSIONS_HOTLINE/SANDBOX b/VERSIONS_HOTLINE/SANDBOX new file mode 100644 index 0000000000000000000000000000000000000000..46a32bb428ee30fa8b2392ed2f3e703f6032e394 --- /dev/null +++ b/VERSIONS_HOTLINE/SANDBOX @@ -0,0 +1 @@ +- sandbox : Ajout d'une variable cosmogramme pour déclencher le vidage de la base Bokeh préalablement au prochain import total (pour les modes Nanook ou Koha uniques). \ No newline at end of file diff --git a/cosmogramme/sql/patch/patch_408.php b/cosmogramme/sql/patch/patch_408.php new file mode 100644 index 0000000000000000000000000000000000000000..c63da49b7b96ceaf53129488e37bdbcefc0328fc --- /dev/null +++ b/cosmogramme/sql/patch/patch_408.php @@ -0,0 +1,7 @@ +<?php +$adapter = Zend_Db_Table::getDefaultAdapter(); + +try { + $adapter->query("insert into variables (clef, valeur, commentaire, type_champ, liste, groupe, ordre, verrou, hidden) VALUES ('flush_before_full',0,'Vider la base Bokeh préalablement au prochain import total',2,'0:non\r\n1:oui',4,1,0,0)"); +} catch(Exception $e) { +} diff --git a/library/Class/Cosmogramme/Integration/PhasePrepareIntegrations.php b/library/Class/Cosmogramme/Integration/PhasePrepareIntegrations.php index 8e2aca10addc9572f7d22274d0973bf70673513f..9d47a747bb83ea54762161991d1fb9eb219fb5a9 100644 --- a/library/Class/Cosmogramme/Integration/PhasePrepareIntegrations.php +++ b/library/Class/Cosmogramme/Integration/PhasePrepareIntegrations.php @@ -93,6 +93,10 @@ class Class_Cosmogramme_Integration_PhasePrepareIntegrations extends Class_Cosmo return; } + if (Class_CosmoVar::get('flush_before_full') + && $majauto->isTotal()) + $this->_flushBokeh(); + $this->_log ->log('<tr><td class="blank"><span class="bib">' . $bib->getNomCourt($id_bib) .'</span></td>' .'<td class="blank">'.$majauto->getNomFichier().'</td><td class="blank">'); @@ -118,17 +122,14 @@ class Class_Cosmogramme_Integration_PhasePrepareIntegrations extends Class_Cosmo $filesystem = $this->getFilesystem(); if (true !== $filesystem->rename($ftpfile, $this->_integration_path.$newfile)) { - $this->_log - ->log(sprintf('<span class="rouge">%s</span></td>', - $this->_('erreur au transfert du fichier'))); + $this->_log->error($this->_('erreur au transfert du fichier')); $this->_incrementData('traitement_erreurs'); return $this; } $this->_log - ->log(sprintf('<span class="vert">%s</span></td>', - $this->_('transfert vers %s', $newfile))); + ->success($this->_('transfert vers %s', $newfile)); $this->_newIntegration($newfile, $majauto); @@ -143,10 +144,9 @@ class Class_Cosmogramme_Integration_PhasePrepareIntegrations extends Class_Cosmo if (!$majauto->isFileSizeValid($file)) { $this->_log - ->log(sprintf('<span class="rouge">%s</span></td>', - $this->_('Le fichier est trop petit : %s o -> taille minimum attendue : %s o', + ->error($this->_('Le fichier est trop petit : %s o -> taille minimum attendue : %s o', $file->getFileSize(), - $majauto->getFileSizeLimit()))); + $majauto->getFileSizeLimit())); return false; } @@ -175,16 +175,14 @@ class Class_Cosmogramme_Integration_PhasePrepareIntegrations extends Class_Cosmo if (true !== $filesystem->rename($file->getId(), $this->_integration_path . $newfile)) { $this->_log - ->log(sprintf('<span class="rouge">%s</span></td>', - $this->_('impossible de transférer %s vers %s', $file->getId(), $newfile))); + ->error($this->_('impossible de transférer %s vers %s', $file->getId(), $newfile)); $this->_incrementData('traitement_erreurs'); return; } $this->_log - ->log(sprintf('<span class="vert">%s</span></td>', - $this->_('transfert de %s vers %s', $file->getId(), $newfile))); + ->success($this->_('transfert de %s vers %s', $file->getId(), $newfile)); $this->_newIntegration($newfile, $majauto); @@ -199,8 +197,7 @@ class Class_Cosmogramme_Integration_PhasePrepareIntegrations extends Class_Cosmo 'fichier' => $uri])) return $this; - $this->_log->log(sprintf('<span class="vert">%s</span></td>', - $this->_('Création de l\'intégration pour %s', $uri))); + $this->_log->success($this->_('Création de l\'intégration pour %s', $uri)); $this->_newIntegration($uri, $majauto); return $this; @@ -229,8 +226,7 @@ class Class_Cosmogramme_Integration_PhasePrepareIntegrations extends Class_Cosmo if (!$dir = $this->getFileSystem()->opendir($ftp_path)) { $this->_log - ->log(sprintf('<span class="rouge">%s</span>', - $this->_('répertoire inaccessible: %s', $ftp_path))); + ->error($this->_('répertoire inaccessible: %s', $ftp_path)); $this->_incrementData('traitement_erreurs'); return null; @@ -261,10 +257,9 @@ class Class_Cosmogramme_Integration_PhasePrepareIntegrations extends Class_Cosmo $file_size = $this->getFileSystem()->filesize($file); if ($file_size < $minsize) { $this->_log - ->log(sprintf('<span class="rouge">%s</span></td>', - $this->_('Le fichier est trop petit : %s o -> taille minimum attendue : %s o', + ->error($this->_('Le fichier est trop petit : %s o -> taille minimum attendue : %s o', $file_size, - $minsize))); + $minsize)); return false; } } @@ -289,4 +284,24 @@ class Class_Cosmogramme_Integration_PhasePrepareIntegrations extends Class_Cosmo protected function _getNextIntegrationFileName() { return 'integre' . (Class_CosmoVar::get('ID_upload') + 1) . '.pan'; } + + + protected function _flushBokeh() { + Class_CosmoVar::setValueOf('flush_before_full', 0); + + if (!Class_IntBib::isSingleSigb()) { + $this->_log->error($this->_('<h3>Pas de vidage de la base (mode unique désactivé)</h3>')); + return $this; + } + + Class_Notice::basicDeleteAllFromSigb(); + Class_Exemplaire::basicDeleteAllWithoutRecord(); + + Class_CodifTags::basicDeleteBy([]); + Class_Notice_SerialArticles::basicDeleteBy([]); + Class_NoticeSuccincte::basicDeleteBy([]); + + $this->_log->success($this->_('<h3>Vidage de la base effectué</h3>')); + return $this; + } } diff --git a/library/Class/Exemplaire.php b/library/Class/Exemplaire.php index 8fc0a97f611102d16bf3161dedf3d1f66c9069ea..3412f57eedea851719b1cd1eca15f3cfe985c1ca 100644 --- a/library/Class/Exemplaire.php +++ b/library/Class/Exemplaire.php @@ -74,6 +74,11 @@ class Class_ExemplaireLoader extends Storm_Model_Loader { return $items; } + + + public function basicDeleteAllWithoutRecord() { + return Class_Exemplaire::basicDeleteBy('id_notice not in (select id_notice from notices)'); + } } diff --git a/library/Class/IntBib.php b/library/Class/IntBib.php index a09fe44ddb69a5273010373f02e1fbc75f5086ca..a3f52d8b83fd7b0b36566cab7f1596f1897bf969 100644 --- a/library/Class/IntBib.php +++ b/library/Class/IntBib.php @@ -111,6 +111,11 @@ class IntBibLoader extends Storm_Model_Loader { } + public function isSingleSigb() { + return (new Class_IntBib_SingleSigb())->isSingle(Class_IntBib::findAll()); + } + + public function findAllNanookWithPreRegistration() { $collection = new Storm_Model_Collection(Class_IntBib::findAll()); $combo = $collection diff --git a/library/Class/IntBib/SingleSigb.php b/library/Class/IntBib/SingleSigb.php index 2bffee507c9c350c33d355decebbeb9066cf89cd..bd48043577a1c1eaf32c865dca1eb28f98781f93 100644 --- a/library/Class/IntBib/SingleSigb.php +++ b/library/Class/IntBib/SingleSigb.php @@ -20,14 +20,14 @@ */ -abstract class Class_IntBib_SingleSigb { - protected $_server = null; +class Class_IntBib_SingleSigb { + protected $_server, $_sigb; public function isSingle($models) { if(!$models) return false; - $this->_server = null; + $this->_server = $this->_sigb = null; foreach($models as $library) { if (!$this->_isSigbAndSameServer($library)) return false; @@ -47,7 +47,6 @@ abstract class Class_IntBib_SingleSigb { } - protected function _isSigbAndSameServer($library) { if (!$this->_isSigb($library)) return false; @@ -61,5 +60,12 @@ abstract class Class_IntBib_SingleSigb { } - abstract protected function _isSigb($library); + protected function _isSigb($library) { + if (null == $this->_sigb) { + $this->_sigb = $library->getSigb(); + return true; + } + + return $this->_sigb == $library->getSigb(); + } } \ No newline at end of file diff --git a/library/Class/Notice.php b/library/Class/Notice.php index d8d27dbad731309dfd73a8343480ec28c52c05bb..8571a3fcb332cd1d2321fa26ce45f79ff81566d1 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -187,6 +187,18 @@ class NoticeLoader extends Storm_Model_Loader { return $record_id; } + + + public function basicDeleteAllFromSigb() { + // @see Class_TypeDoc::isSigb() + $params = ['cast(type_doc as UNSIGNED) > 0', + 'type_doc < '.Class_TypeDoc::LIVRE_NUM, + 'type_doc not in (' . implode(',', [Class_TypeDoc::ARTICLE, + Class_TypeDoc::RSS, + Class_TypeDoc::SITE]) . ')']; + + return Class_Notice::basicDeleteBy(implode(' and ', $params)); + } } diff --git a/library/storm b/library/storm index de6da8ef5032cf1c9dc2876a955c7ec91c894328..f079a07b1240a87906582fb1e328df1b3eb38074 160000 --- a/library/storm +++ b/library/storm @@ -1 +1 @@ -Subproject commit de6da8ef5032cf1c9dc2876a955c7ec91c894328 +Subproject commit f079a07b1240a87906582fb1e328df1b3eb38074 diff --git a/tests/db/UpgradeDBTest.php b/tests/db/UpgradeDBTest.php index 51f9f5305804169384aa86fbf5fb64043065d528..8963360defc24d54f8d174ef0f79bf1a1746a30d 100644 --- a/tests/db/UpgradeDBTest.php +++ b/tests/db/UpgradeDBTest.php @@ -3786,4 +3786,20 @@ class UpgradeDB_407_Test extends UpgradeDBTestCase { $this->assertEquals(0, $this->query("select count(*) from session_activity_inscriptions where (adults=0 and children=0) ")->fetch()['count(*)']); } -} \ No newline at end of file +} + + + + +class UpgradeDB_408_Test extends UpgradeDBTestCase { + public function prepare() { + $this->silentQuery("delete from variables where clef='flush_before_full'"); + } + + + /** @test */ + public function tableVariablesShouldHaveFlushBeforeFullVariableInGroupe4() { + $this->assertEquals(4, + $this->query("select * from variables where clef='flush_before_full'")->fetch()['groupe']); + } +} diff --git a/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php b/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php index e379c8e80650628fd49279c4614eea9778928042..d15d2746c3c1ec2ef661daf4c420293e36710cd3 100644 --- a/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php +++ b/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php @@ -308,7 +308,7 @@ class PhasePrepareIntegrationsWithOAITest extends PhasePrepareIntegrationsWithOA /** @test */ public function logShouldContainsFileTooSmall() { - $this->assertLogContains('<td class="blank">foo/toosmall.txt</td><td class="blank"> <span class="rouge">Le fichier est trop petit : 1000000 o -> taille minimum attendue : 10485760 o'); + $this->assertLogContains('<td class="blank">foo/toosmall.txt</td><td class="blank"> Le fichier est trop petit : 1000000 o -> taille minimum attendue : 10485760 o'); } @@ -374,7 +374,7 @@ class PhasePrepareIntegrationsWithOAIIntegrationAlreadyRegisteredTest -class PhasePrepareIntegrationsNanookStandardTest +abstract class PhasePrepareIntegrationsNanookStandardTestCase extends Class_Cosmogramme_Integration_PhaseTestCase { protected $_http_client; @@ -493,6 +493,7 @@ class PhasePrepareIntegrationsNanookStandardTest $this->fixture('Class_Notice', ['id' => 445, + 'type_doc' => 1, 'facettes' => 'G34', 'date_maj' => '2012-03-06 00:00:00']); @@ -504,6 +505,7 @@ class PhasePrepareIntegrationsNanookStandardTest $this->fixture('Class_Notice', ['id' => 446, + 'type_doc' => 1, 'facettes' => 'E34', 'date_maj' => '2012-03-06 00:00:00']); @@ -514,6 +516,7 @@ class PhasePrepareIntegrationsNanookStandardTest $this->fixture('Class_Notice', ['id' => 448, + 'type_doc' => 1, 'facettes' => 'Y34', 'date_maj' => '2012-03-06 00:00:00']); @@ -646,7 +649,23 @@ class PhasePrepareIntegrationsNanookStandardTest 'id_bib' => 2, 'type_operation' => Class_Cosmogramme_Integration::TYPE_OPERATION_TOTAL, 'profil' => 102]); + } + + protected function _getPreviousPhase() { + return (new Class_Cosmogramme_Integration_Phase(0)) + ->beCron(); + } +} + + + + +class PhasePrepareIntegrationsNanookWithRemovedLibraryTest + extends PhasePrepareIntegrationsNanookStandardTestCase { + + protected function _prepareFixtures() { + parent::_prepareFixtures(); $this->fixture('Class_IntBib', ['id' => 3, 'nom_court' => 'Old library', 'sigb' => Class_IntBib::SIGB_NANOOK]); @@ -662,12 +681,24 @@ class PhasePrepareIntegrationsNanookStandardTest } - protected function _getPreviousPhase() { - return (new Class_Cosmogramme_Integration_Phase(0)) - ->beCron(); + /** @test */ + public function removedLibraryShouldBeDisabled() { + $this->assertTrue(Class_IntBib::find(3)->isDisconnected()); + } + + + /** @test */ + public function runQueuOfRemovedLibraryShouldNotBeLost() { + $this->assertNotEmpty(Class_Cosmogramme_Integration::findAllBy(['id_bib' => 3])); } +} + + +class PhasePrepareIntegrationsNanookStandardTest + extends PhasePrepareIntegrationsNanookStandardTestCase { + /** @test */ public function logShouldContainsStandardUpdateOk() { $this->assertContains('<h4>Mise à jour de l\'étalon</h4> OK', $this->_log_content); @@ -723,12 +754,6 @@ class PhasePrepareIntegrationsNanookStandardTest } - /** @test */ - public function removedLibraryShouldBeDisabled() { - $this->assertTrue(Class_IntBib::find(3)->isDisconnected()); - } - - /** @test */ public function libraryIdSixLabelShouldBeMaBibliothèque() { $this->assertEquals('Ma bibliothèque', Class_Cosmogramme_Generator_FixedIdBib::find(6)->getLibelle()); @@ -767,12 +792,6 @@ class PhasePrepareIntegrationsNanookStandardTest } - /** @test */ - public function runQueuOfRemovedLibraryShouldNotBeLost() { - $this->assertNotEmpty(Class_Cosmogramme_Integration::findAllBy(['id_bib' => 3])); - } - - /** @test */ public function updatedLibraryShouldKeepPreviousCity() { $this->assertEquals('My city', @@ -806,6 +825,119 @@ class PhasePrepareIntegrationsNanookStandardTest + + +class PhasePrepareIntegrationsWithDeleteNoticesNanookUniqueTest + extends PhasePrepareIntegrationsNanookStandardTestCase { + + + protected function _prepareFixtures() { + parent::_prepareFixtures(); + $this->fixture('Class_CosmoVar', + ['id' => 'flush_before_full', 'valeur' => 1]); + + $this->fixture('Class_CodifTags', + ['id' => 1]); + + $this->fixture('Class_Notice_SerialArticles', + ['id' => 1, + 'clef_chapeau' => 'XXX-YYY-XXX', + 'clef_numero' => 'Track 3 - Fields']); + + $this->fixture('Class_NoticeSuccincte', + ['id' => 1, + 'id_bib' => 2]); + + $this->onLoaderOfModel(Class_Notice::class); + $this->onLoaderOfModel(Class_Exemplaire::class); + } + + + /** @test */ + public function afterExecuteCosmoVarFlushBokehShouldBeBackToZero() { + $this->assertEquals(0, Class_CosmoVar::get('flush_before_full')); + } + + + /** @test */ + public function prepareNoticeShouldDeleteNoticesWithTypeDocSigb() { + $this->assertEquals('cast(type_doc as UNSIGNED) > 0 and type_doc < 100 and type_doc not in (8,9,10)', + Class_Notice::getFirstAttributeForLastCallOn('basicDeleteBy')); + } + + + /** @test */ + public function prepareNoticeShouldDeleteExemplairesWithoutNotice() { + $this->assertEquals('id_notice not in (select id_notice from notices)', + Class_Exemplaire::getFirstAttributeForLastCallOn('basicDeleteBy')); + } + + + /** @test */ + public function afterPrepareCodifTagsShouldBeEmpty() { + $this->assertEmpty(Class_CodifTags::findAll()); + } + + + /** @test */ + public function afterPrepareNoticeSerialArticlesShouldBeEmpty() { + $this->assertEmpty(Class_Notice_SerialArticles::findAll()); + } + + + /** @test */ + public function afterPrepareNoticeSuccincteShouldBeEmpty() { + $this->assertEmpty(Class_NoticeSuccincte::findAll()); + } +} + + + + +class PhasePrepareIntegrationsWithDeleteNoticesMultiSIGBTest + extends PhasePrepareIntegrationsNanookStandardTestCase { + + protected function _prepareFixtures() { + parent::_prepareFixtures(); + + $this->fixture('Class_CosmoVar', + ['id' => 'flush_before_full', 'valeur' => 1]); + + $this->fixture('Class_IntBib', + ['id' => 6, + 'nom_court' => 'foo', + 'nom' => 'Ma bibliothèque', + 'sigb' => Class_IntBib::SIGB_NANOOK]); + + $this->fixture('Class_IntBib', + ['id' => 8, + 'nom_court' => 'foo', + 'nom' => 'Ma médiathèque', + 'sigb' => Class_IntBib::SIGB_KOHA]); + } + + + /** @test */ + public function afterExecuteCosmoVarFlushBokehShouldBeBackToZero() { + $this->assertEquals(0,Class_CosmoVar::get('flush_before_full')); + } + + + /** @test */ + public function logShouldContainsPasDeVidageDeBase() { + $this->assertLogContains('<h3>Pas de vidage de la base (mode unique désactivé)</h3>'); + } + + + /** @test */ + public function afterPrepareClassNoticeFindAllShouldNotBeEmpty() { + $this->assertNotEmpty(Class_Notice::findAll()); + } +} + + + + class PhasePrepareIntegrationsKindTest extends Class_Cosmogramme_Integration_PhaseTestCase { protected $_http_client; @@ -955,4 +1087,4 @@ class PhasePrepareIntegrationsKindTest extends Class_Cosmogramme_Integration_Pha $this->assertNotNull($kind = Class_CodifGenre::findFirstBy(['libelle' => $label])); $this->assertEquals($attribs, $kind->toArray()); } -} \ No newline at end of file +}