diff --git a/library/Class/Cosmogramme/Integration/PhaseReviews.php b/library/Class/Cosmogramme/Integration/PhaseReviews.php new file mode 100644 index 0000000000000000000000000000000000000000..ff9e7c2409f07c82d04f052e6035cca019817286 --- /dev/null +++ b/library/Class/Cosmogramme/Integration/PhaseReviews.php @@ -0,0 +1,106 @@ +<?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 + */ +require_once('cosmogramme/php/classes/classe_notice_integration.php'); + +class Class_Cosmogramme_Integration_PhaseReviews extends Class_Cosmogramme_Integration_PhaseAbstract { + const MY_ID=7.5; + + protected $_label = 'Reviews attachments'; + + public function __construct($phase, $log, $chrono) { + parent::__construct($phase, $log, $chrono); + $this->_previous_records = []; + xdebug_break(); + } + protected function _init($new_phase) {} + + + public function _execute() { + xdebug_break(); + while ($records = Class_AvisNotice::findAllAfter($this->_getData('pointeur_notice'), + + $this->_getData('pointeur'))) { + + if (0 == ($this->_getData('nombre') % 100)) + $this->_log->ecrire('<span class="vert"> ' . $this->_getData('nombre') . ' records updated </span>'); + if ($this->_previous_records && (0 == count(array_filter(array_diff($this->_previous_records, $records))))) + break; + + $this->_previous_records = $records; + + $this->runUpdateForRecords($records); + + $this->_resetDbConnection(); + + } + + $this->_log->ecrire('<span class="vert">'. + 'Tous les avis ont été mis à jour :' . + ' pointeur avis : ' . $this->_getData('pointeur_avis') . + ' pointeur : ' . $this->_getData('pointeur') . + '<br>' . $this->_getData('nombre') . ' avis traités.</span>'); + + $msg = '<span class="vert">Temps de traitement : ' + . $this->_chrono->endFile() + . ' (' . $this->_chrono->meanOnFile($this->_getData('nombre'), + 'notices') . ')</span>'; + + $this->_log->ecrire($msg); + + } + protected function runUpdateForRecords($records) { + foreach ($records as $record) { + if ($this->isTimeOut()) + return $this->_resetDbConnection() + ->_phase; + $this->_runOne($record); + + } + } + + + protected function _runOne($record) { + // types starting with 100 are indexed at another phase + + $record->findNoticesByClefOeuvre(); + $this->_setData('pointeur_notice', $record->getId()); + $this->_incrementData('nombre'); + + } + + /** @category testing */ + public function noDbReset() { + $this->_db_reset = false; + return $this; + } + protected function _resetDbConnection() { + if (!$this->_db_reset) + return $this; + + Storm_Model_Abstract::unsetLoaders(); + Zend_Db_Table::getDefaultAdapter()->closeConnection(); + setupDatabase(loadConfig()); + gc_collect_cycles(); + return $this; + } + + +} \ No newline at end of file