From b96fdc9fce15bc60ab69f5485b0018cf1da11bac Mon Sep 17 00:00:00 2001 From: efalcy <efalcy@afi-sa.fr> Date: Fri, 25 Sep 2015 17:16:05 +0200 Subject: [PATCH] hotline #23808 : casqy reviews, add cosmogramme review phase --- cosmogramme/php/integre_traite_main.php | 14 ++- library/Class/AvisNotice.php | 12 +- tests/library/Class/AvisNoticeTest.php | 3 + .../Integration/PhaseReviewsTest.php | 112 ++++++++++++++++++ 4 files changed, 138 insertions(+), 3 deletions(-) create mode 100644 tests/library/Class/Cosmogramme/Integration/PhaseReviewsTest.php diff --git a/cosmogramme/php/integre_traite_main.php b/cosmogramme/php/integre_traite_main.php index cf167dda418..789b6af69f9 100644 --- a/cosmogramme/php/integre_traite_main.php +++ b/cosmogramme/php/integre_traite_main.php @@ -496,7 +496,19 @@ if (!$mode_cron and $chrono->tempsPasse() > 5) sauveContexte(); startIntegrationPhase('ItemFacets'); -$phase = 8; +$phase = 7.5 + +// ---------------------------------------------------------------- +// Reattach Reviews +// ---------------------------------------------------------------- + +if ($phase == 7.5) { + startIntegrationPhase('Reviews'); + $phase = 8; +} +; + + // ---------------------------------------------------------------- // Integration des abonnés diff --git a/library/Class/AvisNotice.php b/library/Class/AvisNotice.php index 6de4e750d5a..af516d044ec 100644 --- a/library/Class/AvisNotice.php +++ b/library/Class/AvisNotice.php @@ -67,6 +67,14 @@ class AvisNoticeLoader extends Storm_Model_Loader { } + public function findAllAfter($record_id, $update_date) { + $where = "id > " . $record_id . " and date_maj >='" . $update_date . "'"; + return Class_AvisNotice::findAllBy(['where' => $where, + 'order' => 'id', + 'limit' => '100']); + } + + /* Renvoie les avis correspondants aux préférences de recherches données - id_catalogue: le catalogue de notices dont on veut récupérer les avis @@ -189,8 +197,8 @@ class Class_AvisNotice extends Storm_Model_Abstract { * Recherche les notices liées à cet avis. Si non trouvé (par exemple l'auteur de la clé * oeuvre à été mis à jour dans le SIGB, essaye de retrouver la notice et réaffecte l'avis */ - protected function _findNoticesByClefOeuvre() { - xdebug_break(); + public function findNoticesByClefOeuvre() { + if ($notices = Class_Notice::findAllBy(['clef_oeuvre' => $this->getClefOeuvre()])) return $notices; diff --git a/tests/library/Class/AvisNoticeTest.php b/tests/library/Class/AvisNoticeTest.php index 3a39385cacf..07fe72d3418 100644 --- a/tests/library/Class/AvisNoticeTest.php +++ b/tests/library/Class/AvisNoticeTest.php @@ -811,6 +811,9 @@ class AvisVisibilityTest extends ModelTestCase { } +class AvisNoticeReattachReviewsTest extends NoticeTestHasManyAvisTest { + +} class AvisNoticeAvisFromPreferencesTest extends Storm_Test_ModelTestCase { public function setUp() { diff --git a/tests/library/Class/Cosmogramme/Integration/PhaseReviewsTest.php b/tests/library/Class/Cosmogramme/Integration/PhaseReviewsTest.php new file mode 100644 index 00000000000..5883feec583 --- /dev/null +++ b/tests/library/Class/Cosmogramme/Integration/PhaseReviewsTest.php @@ -0,0 +1,112 @@ +<?php +/** + * Copyright (c) 2012-2014, 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 + */ + + +abstract class PhaseReviewsTestCase extends Class_Cosmogramme_Integration_PhaseTestCase { + public function setUp() { + parent::setUp(); + + $this->_phase = $this->_buildPhase('Reviews') + ->noDbReset() + ->run(); + } +} + + + +class PhaseReviewsBadPreviousPhaseTest extends PhaseReviewsTestCase { + protected function _getPreviousPhase() { + return new Class_Cosmogramme_Integration_Phase(6); + } + + + /** @test */ + public function shouldNotChangePhase() { + $this->assertTrue($this->_phase->isId(6)); + } +} + + + +class PhaseReviewsExpectedPreviousPhaseTest extends PhaseReviewsTestCase { + protected function _getPreviousPhase() { + return (new Class_Cosmogramme_Integration_Phase(7.5)) + ->beCron(); + } + + + protected function _prepareFixtures() { + $this->fixture('Class_AdminVar', + ['id' => 'AVIS_MIN_SAISIE', + 'valeur' => 0]); + $this->fixture('Class_AdminVar', + ['id' => 'AVIS_MAX_SAISIE', + 'valeur' => 1000]); + + $this->millenium = $this->fixture('Class_Notice', ['id' => 816, + 'titre_principal' => 'Millenium', + 'clef_alpha' => 'MILLENIUM', + 'auteur_principal' => 'Stieg Larsson', + 'url_vignette' => '', + 'url_image' => '' + ] + ); + + + $this->avis_millenium = $this->fixture('Class_AvisNotice', ['id' => 13, + 'entete' => "J'adore", + 'avis' => '<div><ul><li>Suspense Intense !</li><li>Suspense Intense !</li></ul></div>', + 'note' => 5, + 'date_avis' => '2011-03-18 13:00:00', + + 'statut' => 0, + 'abon_ou_bib'=>1 , + 'notices' => [] ]); + + + $this + ->onLoaderOfModel('Class_AvisNotice') + ->whenCalled('findAllAfter') + ->answers([$this->avis_millenium]); + } + + + /** @test */ + public function shouldChangePhase() { + $this->assertTrue($this->_phase->isId(7.5)); + } + + + /** @test */ + public function logShouldContainsPhaseLabel() { + $this->assertLogContains('Tous les avis ont été mis à jour'); + } + + + /** @test */ + public function logShouldContainsProcessedRecordCount() { + $this->assertLogContains('1 avis traités'); + } + +} + + +} \ No newline at end of file -- GitLab