diff --git a/library/Class/Cosmogramme/Integration/PhasePseudoRecord.php b/library/Class/Cosmogramme/Integration/PhasePseudoRecord.php new file mode 100644 index 0000000000000000000000000000000000000000..4e2e45b9cab962c4989ee06569139aa371b1185d --- /dev/null +++ b/library/Class/Cosmogramme/Integration/PhasePseudoRecord.php @@ -0,0 +1,81 @@ +<?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 Class_Cosmogramme_Integration_PhasePseudoRecord + extends Class_Cosmogramme_Integration_PhaseAbstract { + + /** @var Trait_Indexable */ + protected $_model_name; + + + protected function _getModelIdField() { + return call_user_func([$this->_model_name, 'getIdField']); + } + + + protected function _loadPage() { + $id_field = $this->_getModelIdField(); + return call_user_func_array([$this->_model_name, 'findAllBy'], + [['where' => $id_field . ' > ' . $this->_getData('pointeur_reprise'), + 'order' => $id_field, + 'limit' => 100 + ]]); + } + + + protected function _execute() { + while ($models = $this->_loadPage()) { + foreach($models as $model) { + if ($this->isTimeOut()) + return $this->_phase; + + $model->index(); + $this->_incrementData('nombre'); + $this->_setData('pointeur_reprise', $model->getId()); + +/* TODO : trace + $record = $article->getNotice(); + $statut = $record + ? ['statut' => 1, + 'id_notice' => $record->getId(), + 'unimarc' => $record->getUnimarc(), + 'code_barres' => '', + 'facettes' => $record->getFacettes()] + : ['statut' => 0, 'id_notice' => 0]; + + tracePseudoNotice($ret, $statut); */ + } + } + } + + + protected function _init($phase) { + $phase + ->resetDatas() + ->setData('pointeur_reprise', 0) + ->setData('nombre', 0); + + $this->_chrono + ->startOnFile() + ->startOnRecords(); + } +} \ No newline at end of file diff --git a/library/Class/Cosmogramme/Integration/PhasePseudoRecordCms.php b/library/Class/Cosmogramme/Integration/PhasePseudoRecordCms.php new file mode 100644 index 0000000000000000000000000000000000000000..377dff16d2906faabdf8ae2af960e82eab6ae59d --- /dev/null +++ b/library/Class/Cosmogramme/Integration/PhasePseudoRecordCms.php @@ -0,0 +1,34 @@ +<?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 + */ + + +class Class_Cosmogramme_Integration_PhasePseudoRecordCms extends Class_Cosmogramme_Integration_PhasePseudoRecord { + const MY_ID = 0.2; + + protected $_label = 'Pseudo-notices : CMS'; + protected $_model_name = 'Class_Article'; + + + /** @return array **/ + protected function _previousPhaseIds() { + return [0.1]; + } +} \ No newline at end of file diff --git a/library/Class/Indexation/PseudoNotice.php b/library/Class/Indexation/PseudoNotice.php index 3b0047fb56c4e579c8a40bef0125f69e60b4f46b..d53710d75793e55dbd04acf39978131dfcb7fdcf 100644 --- a/library/Class/Indexation/PseudoNotice.php +++ b/library/Class/Indexation/PseudoNotice.php @@ -34,7 +34,7 @@ class Class_Indexation_PseudoNotice { public static function index($model) { - $instance = self::newWith($model->getTypeDocId(), $model->toArray()); + $instance = self::newWith($model); return ($instance->isValid()) ? $instance->save() : false; } @@ -47,7 +47,9 @@ class Class_Indexation_PseudoNotice { } - public static function newWith($type_doc, $datas) { + public static function newWith($model) { + $type_doc = $model->getTypeDocId(); + // types simples $mapping = [Class_TypeDoc::ARTICLE => 'Cms', Class_TypeDoc::RSS => 'Rss', @@ -55,22 +57,21 @@ class Class_Indexation_PseudoNotice { if (array_key_exists($type_doc, $mapping)) { $class_name = 'Class_Indexation_PseudoNotice_' . $mapping[$type_doc]; - return new $class_name($type_doc, $datas); + return new $class_name($model); } // bibnum if (99 < $type_doc) - return new Class_Indexation_PseudoNotice_Album($type_doc, $datas); + return new Class_Indexation_PseudoNotice_Album($model); return new Class_Indexation_PseudoNotice_Null(); } - public function __construct($type_doc, $datas) { - $this->_type_doc = (int)$type_doc; - $this->_datas = array_change_key_case($datas, CASE_LOWER); - $this->_model = call_user_func_array([$this->_model_name, 'find'], - [$this->_datas[$this->_id]]); - } + public function __construct($model) { + $this->_model = $model; + $this->_type_doc = $model->getTypeDocId(); + $this->_datas = array_change_key_case($model->toArray(), CASE_LOWER); + } public function getId() { return $this->_notice->getId(); diff --git a/tests/library/Class/Cosmogramme/Integration/PhasePseudoRecordTest.php b/tests/library/Class/Cosmogramme/Integration/PhasePseudoRecordTest.php new file mode 100644 index 0000000000000000000000000000000000000000..4f58cfa83fe71eae3edf7a3229005904df6beb18 --- /dev/null +++ b/tests/library/Class/Cosmogramme/Integration/PhasePseudoRecordTest.php @@ -0,0 +1,79 @@ +<?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 + */ + + +class PhasePseudoRecordTest extends Class_Cosmogramme_Integration_PhaseTestCase { + public function setUp() { + parent::setUp(); + $this->_phase = $this->_buildPhase('PseudoRecordCms')->run(); + } + + + protected function _prepareFixtures() { + $article = $this->fixture('Class_Article', + ['id' => 15, + 'titre' => 'Un article', + 'contenu' => 'Un contenu', + 'indexation' => 1]); + + $this->onLoaderOfModel('Class_Article') + ->whenCalled('findAllBy') + ->with(['where' => 'id_article > 0', + 'order' => 'id_article', + 'limit' => 100]) + ->answers([$article]) + + ->whenCalled('findAllBy')->answers([]); + + } + + + protected function _getPreviousPhase() { + return (new Class_Cosmogramme_Integration_Phase(0.1)) + ->setData('pointeur_reprise', 45) + ->beCron(); + } + + + /** @test */ + public function shouldHaveCreatedPseudoRecord() { + $this->assertNotNull(Class_Article::find(15)->getNotice()); + } + + + /** @test */ + public function traitemenPhaseShouldBePseudoRecord() { + $this->assertEquals('Pseudo-notices : CMS', + Class_CosmoVar::get('traitement_phase')); + } + + + /** @test */ + public function logShouldContainsPhaseLabel() { + $this->assertLogContains('Pseudo-notices : CMS'); + } +} + + +/** TODO + Testcase avec réentrance + Testcase avec pagination +*/ \ No newline at end of file diff --git a/tests/library/Class/Indexation/PseudoNoticeTest.php b/tests/library/Class/Indexation/PseudoNoticeTest.php index 08e0f41a2dc7fd95c174d62bf0dbc9eb6a7d9bdb..b42eeba67e6d64814e926e45aa387480d32c7772 100644 --- a/tests/library/Class/Indexation/PseudoNoticeTest.php +++ b/tests/library/Class/Indexation/PseudoNoticeTest.php @@ -85,19 +85,14 @@ class Class_Indexation_PseudoNoticeSitothequeFromRawSQLTest extends Class_Indexa public function setUp() { parent::setUp(); - $this->fixture('Class_Sitotheque', ['id' => 12, - 'titre' => 'Thot cursus', - 'url' => 'http://cursus.edu/', - 'description' => 'Top notch site', - 'tags' => 'VOD']); + $sito = $this->fixture('Class_Sitotheque', ['id' => 12, + 'titre' => 'Thot cursus', + 'url' => 'http://cursus.edu/', + 'description' => 'Top notch site', + 'tags' => 'VOD']); /** as done in Cosmogramme */ - Class_Indexation_PseudoNotice::newWith(Class_TypeDoc::SITE, - ['ID_SITO' => 12, - 'TITRE' => 'Thot cursus', - 'URL' => 'http://cursus.edu/', - 'DESCRIPTION' => 'Top notch site', - 'TAGS' => 'VOD'])->save(); + Class_Indexation_PseudoNotice::newWith($sito)->save(); $this->_notice = Class_Notice::find(1); } @@ -129,8 +124,7 @@ class Class_Indexation_PseudoNoticeCmsTest extends Class_Indexation_PseudoNotice ['id' => 43, 'titre' => 'Festival Animation', 'contenu' => 'à Annecy']); - Class_Indexation_PseudoNotice::newWith(Class_TypeDoc::ARTICLE, - $article->getRawAttributes())->save(); + Class_Indexation_PseudoNotice::newWith($article)->save(); $this->_notice = Class_Notice::find(1); } @@ -162,9 +156,7 @@ class Class_Indexation_PseudoNoticeSitothequeTest extends Class_Indexation_Pseud 'description' => 'Top notch site', 'tags' => 'VOD']); - Class_Indexation_PseudoNotice::newWith(Class_TypeDoc::SITE, - $this->_sito->toArray() + ['ID_SITO' => $this->_sito->getId()]) - ->save(); + Class_Indexation_PseudoNotice::newWith($this->_sito)->save(); $this->_notice = $this->_sito->getNotice(); }