diff --git a/application/modules/admin/controllers/ModoController.php b/application/modules/admin/controllers/ModoController.php index e8b3c634584cf935b0df1b209f15d777bfa2d4bc..8b7a8c8e0fc370ca24d9e3d98f687f46e8e16dd4 100644 --- a/application/modules/admin/controllers/ModoController.php +++ b/application/modules/admin/controllers/ModoController.php @@ -28,17 +28,19 @@ class Admin_ModoController extends ZendAfi_Controller_Action { public function avisnoticeAction() { $this->subviewForStatus(0); + $this->_request->setParam('back', 'avisnotice'); $this->_forward('index'); + } public function invisibleavisnoticeAction() { if (!$review_id=$this->_request->getParam('id',0)) $this->_forward('index'); + $review=Class_AvisNotice::find($review_id); $review->setFlags(Class_AvisNotice::ARCHIVED_FLAG)->save(); - - $this->_forward('index'); + $this->_stayOnPage(); } @@ -47,8 +49,7 @@ class Admin_ModoController extends ZendAfi_Controller_Action { $this->_forward('index'); $review=Class_AvisNotice::find($review_id); $review->setFlags(Class_AvisNotice::NO_FLAG)->save(); - - $this->_forward('index'); + $this->_stayOnPage(); } protected function subviewForStatus($status) { @@ -82,7 +83,7 @@ class Admin_ModoController extends ZendAfi_Controller_Action { } public function allreviewsAction() { - + $this->_request->setParam('back', 'avisnotice'); $this->subviewForStatus(1); $this->_forward('index'); } @@ -91,7 +92,7 @@ class Admin_ModoController extends ZendAfi_Controller_Action { public function delavisnoticeAction() { $id = $this->_request->getParam('id'); Class_AvisNotice::find($id)->delete(); - $this->_redirect('admin/modo/avisnotice'); + $this->_stayOnPage(); } public function editavisnoticeAction() { @@ -124,7 +125,8 @@ class Admin_ModoController extends ZendAfi_Controller_Action { $avis = $this->_setAvisAndEntete($avis, $form); if ($record = $form->url->getRecord()) { - $avis->setClefOeuvre($record->getClefOeuvre())->save(); + + $avis->forceUpdateWithNotice($record)->save(); $this->_helper->notify($this->view->_('Avis rattaché à la notice "%s"', $record->getTitrePrincipal())); } diff --git a/cosmogramme/php/_init.php b/cosmogramme/php/_init.php index fd12ea4641593a002fdb218c22c0c1e3dca605b0..b7e03eaac463a4c30ae4c3a68bee68f1c311b828 100644 --- a/cosmogramme/php/_init.php +++ b/cosmogramme/php/_init.php @@ -1,7 +1,7 @@ <?php error_reporting(E_ERROR | E_PARSE); -define("PATCH_LEVEL","265"); +define("PATCH_LEVEL","266"); define("APPLI","cosmogramme"); define("COSMOPATH", "/var/www/html/vhosts/opac2/www/htdocs"); diff --git a/cosmogramme/sql/patch/patch_266.php b/cosmogramme/sql/patch/patch_266.php new file mode 100644 index 0000000000000000000000000000000000000000..7b3379f439b82900abb90ffe7105f65f21a9ba4a --- /dev/null +++ b/cosmogramme/sql/patch/patch_266.php @@ -0,0 +1,7 @@ +<?php + +// update reviews to attach reviews to notices +$reviews = new Class_Cosmogramme_Integration_PhaseReviews(); +$reviews->initPhaseWithoutContext()->_execute(); + +?> \ No newline at end of file diff --git a/library/Class/AvisNotice.php b/library/Class/AvisNotice.php index 1191d37793cdbaaed03a3170a325dd7f8fc7f7cc..7aa82ce8a0ef2bfa82b82dac8d3f7e81e8ad4566 100644 --- a/library/Class/AvisNotice.php +++ b/library/Class/AvisNotice.php @@ -197,6 +197,7 @@ class Class_AvisNotice extends Storm_Model_Abstract { 'flags' => self::NO_FLAG, 'clef_oeuvre' => '', 'date_avis' => null, + 'id_notice' => 0, 'note' => 0]; protected $_notices; @@ -267,6 +268,7 @@ class Class_AvisNotice extends Storm_Model_Abstract { * oeuvre à été mis à jour dans le SIGB, essaye de retrouver la notice et réaffecte l'avis */ public function findNoticesByClefOeuvre() { + $this->setIdNotice(0); if ($this->_notices = Class_Notice::findAllBy(['clef_oeuvre' => $this->getClefOeuvre()])) return $this->_notices; @@ -280,8 +282,8 @@ class Class_AvisNotice extends Storm_Model_Abstract { return $this->_notices = []; $this - ->setClefOeuvre($clef_oeuvre) - ->save(); + ->setIdNotice($notice->getId()); + } $this->_notices=$notices; return $notices; @@ -299,8 +301,8 @@ class Class_AvisNotice extends Storm_Model_Abstract { public function getFirstNotice() { - if ($this->id_notice>0) - return Class_Notice::find($this->id_notice); + if ($this->getIdNotice()>0) + return Class_Notice::find($this->getIdNotice()); $notices = $this->getNotices(); if (count($notices) == 0) return null; @@ -355,6 +357,24 @@ class Class_AvisNotice extends Storm_Model_Abstract { } + public function updateFlags() { + if ($this->getIdNotice()>0 && $this->getFlags() == Class_AvisNotice::ORPHAN_FLAG) + $this->setFlags(Class_AvisNotice::NO_FLAG); + if ($this->getIdNotice()<1 && $this->getFlags() == Class_AvisNotice::NO_FLAG) + $this->setFlags(Class_AvisNotice::ORPHAN_FLAG); + return $this; + } + + public function forceUpdateWithNotice($notice) { + if (!$notice) + return $this; + $this->setClefOeuvre($notice->getClefOeuvre()); + $this->setIdNotice($notice->getId()); + $this->updateFlags(); + return $this; + } + + public function beforeSave() { if ($this->isImportMode()) return; diff --git a/library/Class/Cosmogramme/Integration/PhaseAbstract.php b/library/Class/Cosmogramme/Integration/PhaseAbstract.php index aea2fb2f2a65b632d4f495d48cd87269936741c2..427964a077832b5e65368c32b49d1c3021084002 100644 --- a/library/Class/Cosmogramme/Integration/PhaseAbstract.php +++ b/library/Class/Cosmogramme/Integration/PhaseAbstract.php @@ -123,6 +123,8 @@ abstract class Class_Cosmogramme_Integration_PhaseAbstract { public function isTimeOut() { + if (!$this->_chrono) + return false; return !$this->_phase->isCron() && $this->_chrono->mainElapsed() > $this->_chrono->timeout(); } diff --git a/library/Class/Cosmogramme/Integration/PhaseReviews.php b/library/Class/Cosmogramme/Integration/PhaseReviews.php index ee566bfaed1bdc9daba61b77b7f85d8bdee94bda..be2dce1f8cc082c662195bea20b945ccd4d9404f 100644 --- a/library/Class/Cosmogramme/Integration/PhaseReviews.php +++ b/library/Class/Cosmogramme/Integration/PhaseReviews.php @@ -30,25 +30,33 @@ class Class_Cosmogramme_Integration_PhaseReviews extends Class_Cosmogramme_Integ } + public function initPhaseWithoutContext() { - protected function _init($new_phase) { + $this->_phase=(new Class_Cosmogramme_Integration_Phase(self::MY_ID)); + $this->_phase->resetDatas() + ->setData('nombre', 0); + $this->_db_reset = true; + return $this; + } + protected function _init($new_phase) { $new_phase ->resetDatas() ->setData('nombre', 0); $this->_chrono - ->startOnFile() - ->startOnRecords(); + ->startOnFile() + ->startOnRecords(); + return $this; } - public function _execute() { + $page = 1; while ($records = Class_AvisNotice::findAllBy(['order' => 'id', - 'limitPage' => [$page, 500]])) { + 'limitPage' => [$page, 500]])) { - if (0 == ($this->_getData('nombre') % 100)) + if ($this->_log && (0 == ($this->_getData('nombre') % 100))) $this->_log->ecrire('<span class="vert"> ' . $this->_getData('nombre') . ' records updated </span>'); $this->runUpdateForRecords($records); @@ -59,16 +67,18 @@ class Class_Cosmogramme_Integration_PhaseReviews extends Class_Cosmogramme_Integ } - $this->_log->ecrire('<span class="vert">'. - 'Tous les avis ont été mis à jour :' . - '<br>' . $this->_getData('nombre') . ' avis traités.</span>'); + if ($this->_log) { + $this->_log->ecrire('<span class="vert">'. + 'Tous les avis ont été mis à jour :' . + '<br>' . $this->_getData('nombre') . ' avis traités.</span>'); - $msg = '<span class="vert">Temps de traitement : ' - . $this->_chrono->endFile() - . ' (' . $this->_chrono->meanOnFile($this->_getData('nombre'), + $msg = '<span class="vert">Temps de traitement : ' + . $this->_chrono->endFile() + . ' (' . $this->_chrono->meanOnFile($this->_getData('nombre'), 'notices') . ')</span>'; - $this->_log->ecrire($msg); + $this->_log->ecrire($msg); + } } protected function runUpdateForRecords($records) { @@ -83,14 +93,13 @@ class Class_Cosmogramme_Integration_PhaseReviews extends Class_Cosmogramme_Integ protected function _runOne($record) { - // types starting with 100 are indexed at another phase - $record->findNoticesByClefOeuvre(); - if ($notice = $record->getFirstNotice()) - $record->setIdNotice($notice->getId())->save(); + if ($notice = $record->getFirstNotice()) { + $record->setIdNotice($notice->getId())->updateFlags()->save(); + } - if (!$notice) - $record->setFlags(Class_AvisNotice::ORPHAN_FLAG)->save(); + if (!$notice && $record->getFlags() == Class_AvisNotice::NO_FLAG) + $record->updateFlags()->save(); $this->_incrementData('nombre'); @@ -101,6 +110,7 @@ class Class_Cosmogramme_Integration_PhaseReviews extends Class_Cosmogramme_Integ $this->_db_reset = false; return $this; } + protected function _resetDbConnection() { if (!$this->_db_reset) return $this; diff --git a/tests/application/modules/admin/controllers/AdminAvisModerationControllerTest.php b/tests/application/modules/admin/controllers/AdminAvisModerationControllerTest.php index 2f9324112698c367aac768888c8e5b30a2f3ca2e..684dc556cf411f4b8da18263a5fb9be9960e207f 100644 --- a/tests/application/modules/admin/controllers/AdminAvisModerationControllerTest.php +++ b/tests/application/modules/admin/controllers/AdminAvisModerationControllerTest.php @@ -189,6 +189,7 @@ class AdminAvisModerationControllerAvisEditPostTest extends AdminAvisModerationC 'clef_alpha' => 'GARCONNIERELA--GREMILLONH--FLAMMARION-2013-1', 'titre_principal' => 'La garçonnière' ]); + Class_AvisNotice::find(38)->setFlags(1)->save(); new ZendAfi_Controller_Action_Helper_FlashMessenger(); $this->postDispatch('/admin/modo/editavisnotice/id/38', ['url' => 'http://localhost/recherche/viewnotice/expressionRecherche/la+garconniere/tri/%2A/facette/T1/clef/GARCONNIERELA--GREMILLONH--FLAMMARION-2013-1/id/1190178', @@ -202,6 +203,19 @@ class AdminAvisModerationControllerAvisEditPostTest extends AdminAvisModerationC Class_AvisNotice::find(38)->getClefOeuvre()); } + + public function testIdNoticeShouldBeUpdated() { + $this->assertEquals(1190178, + Class_AvisNotice::find(38)->getIdNotice()); + } + + + public function testReviewShouldBeNotFlaggedAnymore() { + $this->assertEquals(0, + Class_AvisNotice::find(38)->getFlags()); + } + + public function testRecordShouldBeUpdated() { $this->assertEquals('after', Class_AvisNotice::find(38)->getAvis()); diff --git a/tests/library/Class/Cosmogramme/Integration/PhaseReviewsTest.php b/tests/library/Class/Cosmogramme/Integration/PhaseReviewsTest.php index 4d2c8ff175da6e0114f8572a18ed60cf2f87a1b5..f335f90d6d754bdff529e3f6a5d1c4e74d9247f7 100644 --- a/tests/library/Class/Cosmogramme/Integration/PhaseReviewsTest.php +++ b/tests/library/Class/Cosmogramme/Integration/PhaseReviewsTest.php @@ -83,7 +83,7 @@ class PhaseReviewsExpectedPreviousPhaseTest extends PhaseReviewsTestCase { $this->avis_tout_seul = $this->fixture('Class_AvisNotice', ['id' => 14, 'entete' => "I'm an orphan", 'avis' => '<div><ul><li>Suspense Intense !</li><li>plop !</li></ul></div>', - 'id_notice' => 0, + 'id_notice' => 20, 'note' => 5, 'date_avis' => '2011-03-18 13:00:00',