From 70ad0d48d02843b17608af9daf469f06bdcd8ac5 Mon Sep 17 00:00:00 2001
From: Matthias Meusburger <matthias.meusburger@biblibre.com>
Date: Wed, 29 Jul 2015 11:17:18 +0200
Subject: [PATCH] rel #24864 : Add last processed file filter.

---
 cosmogramme/php/_init.php                     |  2 +-
 cosmogramme/sql/patch/patch_264.php           |  6 ++
 library/Class/Batch.php                       | 40 +++++++-------
 library/Class/Batch/Abstract.php              | 10 +++-
 library/Class/Batch/ArteVOD.php               |  4 +-
 .../Class/Batch/AutocompleteRecordAuthor.php  |  4 +-
 .../Class/Batch/AutocompleteRecordTitle.php   |  4 +-
 library/Class/Batch/AvisNotice.php            |  4 +-
 library/Class/Batch/BuildSiteMap.php          |  6 +-
 library/Class/Batch/Cyberlibris.php           |  4 +-
 library/Class/Batch/Dilicom.php               | 34 +++++++++++-
 .../Class/Batch/IndexRessourcesNumeriques.php |  2 +
 library/Class/Batch/Jamendo.php               |  2 +
 library/Class/Batch/NumeriquePremium.php      |  4 +-
 library/Class/Batch/Numilog.php               |  4 +-
 library/Class/Batch/OneDTouch.php             |  4 +-
 library/Class/Batch/Orphea.php                |  2 +
 library/Class/Batch/PanierNotice.php          |  4 +-
 library/Class/Batch/PanierUser.php            |  4 +-
 library/Class/Batch/ToutApprendre.php         |  4 +-
 library/Class/Batch/Typo3.php                 |  2 +
 library/Class/Batch/Vodeclic.php              |  4 +-
 tests/library/Class/Batch/DilicomTest.php     | 55 ++++++++++++++++++-
 23 files changed, 169 insertions(+), 40 deletions(-)
 create mode 100644 cosmogramme/sql/patch/patch_264.php

diff --git a/cosmogramme/php/_init.php b/cosmogramme/php/_init.php
index 15b3b4cec76..dcd5895a549 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","263");
+define("PATCH_LEVEL","264");
 
 define("APPLI","cosmogramme");
 define("COSMOPATH", "/var/www/html/vhosts/opac2/www/htdocs");
diff --git a/cosmogramme/sql/patch/patch_264.php b/cosmogramme/sql/patch/patch_264.php
new file mode 100644
index 00000000000..b60399d6ad3
--- /dev/null
+++ b/cosmogramme/sql/patch/patch_264.php
@@ -0,0 +1,6 @@
+<?php
+
+$adapter = Zend_Db_Table::getDefaultAdapter();
+$adapter->query("ALTER TABLE batchs ADD COLUMN data TEXT NULL");
+
+?>
\ No newline at end of file
diff --git a/library/Class/Batch.php b/library/Class/Batch.php
index d7ed4bcea12..87ab569e1df 100644
--- a/library/Class/Batch.php
+++ b/library/Class/Batch.php
@@ -19,31 +19,33 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
-class Class_BatchLoader extends Storm_Model_Loader{
+class Class_BatchLoader extends Storm_Model_Loader {
 
   public function getKnownTypes() {
-    return array_merge($this->getRessourcesNumeriqueTypes(), [
-            'IMPORT_TYPO3' => new Class_Batch_Typo3(),
-            'CORRECTION_PANIERS' => new Class_Batch_PanierNotice(),
-            'CART_REALLOCATION' => new Class_Batch_PanierUser(),
-            'COMMENT_REALLOCATION'=> new Class_Batch_AvisNotice(),
-            'INDEX_RESSOURCES_NUMERIQUES' => new Class_Batch_IndexRessourcesNumeriques(),
-            'AUTOCOMPLETE_RECORD_TITLE' => new Class_Batch_AutocompleteRecordTitle(),
-            'AUTOCOMPLETE_RECORD_AUTHOR' => new Class_Batch_AutocompleteRecordAuthor(),
-            'BUILD_SITE_MAP' => new Class_Batch_BuildSiteMap(),
+    return array_merge($this->getRessourcesNumeriqueTypes(),
+                       [
+                        Class_Batch_Typo3::TYPE => new Class_Batch_Typo3(),
+                        Class_Batch_PanierNotice::TYPE => new Class_Batch_PanierNotice(),
+                        Class_Batch_PanierUser::TYPE => new Class_Batch_PanierUser(),
+                        Class_Batch_AvisNotice::TYPE => new Class_Batch_AvisNotice(),
+                        Class_Batch_IndexRessourcesNumeriques::TYPE => new Class_Batch_IndexRessourcesNumeriques(),
+                        Class_Batch_AutocompleteRecordTitle::TYPE => new Class_Batch_AutocompleteRecordTitle(),
+                        Class_Batch_AutocompleteRecordAuthor::TYPE => new Class_Batch_AutocompleteRecordAuthor(),
+                        Class_Batch_BuildSiteMap::TYPE => new Class_Batch_BuildSiteMap(),
       ]);
   }
 
   public function getRessourcesNumeriqueTypes() {
-    return ['MOISSONNAGE_VODECLIC' => new Class_Batch_Vodeclic(),
-            'MOISSONNAGE_ARTEVOD' => new Class_Batch_ArteVOD(),
-            'MOISSONNAGE_NUMERIQUEPREMIUM' => new Class_Batch_NumeriquePremium(),
-            'MOISSONNAGE_NUMILOG' => new Class_Batch_Numilog(),
-            'MOISSONNAGE_CYBERLIBRIS' => new Class_Batch_Cyberlibris(),
-            'MOISSONNAGE_TOUTAPPRENDRE' => new Class_Batch_ToutApprendre(),
-            'MOISSONNAGE_1DTOUCH' => new Class_Batch_OneDTouch(),
-            'MOISSONNAGE_ORPHEA' => new Class_Batch_Orphea(),
-            'MOISSONNAGE_JAMENDO' => new Class_Batch_Jamendo(),
+    return [Class_Batch_Vodeclic::TYPE => new Class_Batch_Vodeclic(),
+            Class_Batch_ArteVOD::TYPE => new Class_Batch_ArteVOD(),
+            Class_Batch_NumeriquePremium::TYPE => new Class_Batch_NumeriquePremium(),
+            Class_Batch_Numilog::TYPE => new Class_Batch_Numilog(),
+            Class_Batch_Cyberlibris::TYPE => new Class_Batch_Cyberlibris(),
+            Class_Batch_ToutApprendre::TYPE => new Class_Batch_ToutApprendre(),
+            Class_Batch_OneDTouch::TYPE => new Class_Batch_OneDTouch(),
+            Class_Batch_Orphea::TYPE => new Class_Batch_Orphea(),
+            Class_Batch_Jamendo::TYPE => new Class_Batch_Jamendo(),
+            Class_Batch_Dilicom::TYPE => new Class_Batch_Dilicom(),
     ];
   }
 
diff --git a/library/Class/Batch/Abstract.php b/library/Class/Batch/Abstract.php
index 2466efaa839..a0516bce58a 100644
--- a/library/Class/Batch/Abstract.php
+++ b/library/Class/Batch/Abstract.php
@@ -16,7 +16,7 @@
  *
  * 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 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 
@@ -27,16 +27,24 @@ class Class_Batch_Abstract {
     return '';
   }
 
+
   public function run() {
     return;
   }
 
+
   public function runStep($params) {
     return;
   }
 
+
   public function isEnabled() {
     return true;
   }
+
+
+  public function getModel() {
+    return Class_Batch::findFirstBy(['type' => static::TYPE]);
+  }
 }
 ?>
\ No newline at end of file
diff --git a/library/Class/Batch/ArteVOD.php b/library/Class/Batch/ArteVOD.php
index ff3d370d871..a452f1b7e83 100644
--- a/library/Class/Batch/ArteVOD.php
+++ b/library/Class/Batch/ArteVOD.php
@@ -16,11 +16,13 @@
  *
  * 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 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 
 class Class_Batch_ArteVOD extends Class_Batch_RessourceNumerique{
+  const TYPE = 'MOISSONNAGE_ARTEVOD';
+
   protected function _getService() {
     return new Class_WebService_BibNumerique_ArteVOD();
   }
diff --git a/library/Class/Batch/AutocompleteRecordAuthor.php b/library/Class/Batch/AutocompleteRecordAuthor.php
index 501215eba12..1e5ec064762 100644
--- a/library/Class/Batch/AutocompleteRecordAuthor.php
+++ b/library/Class/Batch/AutocompleteRecordAuthor.php
@@ -16,11 +16,13 @@
  *
  * 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 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 
 class Class_Batch_AutocompleteRecordAuthor extends Class_Batch_Abstract {
+  const TYPE = 'AUTOCOMPLETE_RECORD_AUTHOR';
+
   public function getLabel() {
     return $this->_("Indexer les auteurs de notice pour l'autocompletion");
   }
diff --git a/library/Class/Batch/AutocompleteRecordTitle.php b/library/Class/Batch/AutocompleteRecordTitle.php
index f2b5ec53ba1..d98906d5ec8 100644
--- a/library/Class/Batch/AutocompleteRecordTitle.php
+++ b/library/Class/Batch/AutocompleteRecordTitle.php
@@ -16,11 +16,13 @@
  *
  * 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 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 
 class Class_Batch_AutocompleteRecordTitle extends Class_Batch_Abstract {
+  const TYPE = 'AUTOCOMPLETE_RECORD_TITLE';
+
   public function getLabel() {
     return $this->_("Indexer les titres de notice pour l'autocompletion");
   }
diff --git a/library/Class/Batch/AvisNotice.php b/library/Class/Batch/AvisNotice.php
index 65edb8d220e..58fb96bbc2b 100644
--- a/library/Class/Batch/AvisNotice.php
+++ b/library/Class/Batch/AvisNotice.php
@@ -16,11 +16,13 @@
  *
  * 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 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 
 class Class_Batch_AvisNotice extends Class_Batch_Abstract {
+  const TYPE = 'COMMENT_REALLOCATION';
+
   public function getLabel() {
     return $this->_('Réaffecte les avis perdus des abonnés');
   }
diff --git a/library/Class/Batch/BuildSiteMap.php b/library/Class/Batch/BuildSiteMap.php
index 6427781f46f..ea08c964e84 100644
--- a/library/Class/Batch/BuildSiteMap.php
+++ b/library/Class/Batch/BuildSiteMap.php
@@ -16,11 +16,13 @@
  *
  * 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 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 
 class Class_Batch_BuildSiteMap extends Class_Batch_Abstract {
+  const TYPE = 'BUILD_SITE_MAP';
+
   public function getLabel() {
     return $this->_('Régénère le sitemap XML');
   }
@@ -49,7 +51,7 @@ class Class_Batch_BuildSiteMap extends Class_Batch_Abstract {
     foreach ($profiles as $profile) {
       if (!$profile->isPublic())
         continue;
-      
+
       if (0 == (int) $profile->getCfgAccueilParam('sitemap'))
         continue;
 
diff --git a/library/Class/Batch/Cyberlibris.php b/library/Class/Batch/Cyberlibris.php
index 8fd41415725..886d4ac8ff4 100644
--- a/library/Class/Batch/Cyberlibris.php
+++ b/library/Class/Batch/Cyberlibris.php
@@ -16,11 +16,13 @@
  *
  * 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 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 
 class Class_Batch_Cyberlibris extends Class_Batch_RessourceNumerique{
+  const TYPE = 'MOISSONNAGE_CYBERLIBRIS';
+
   protected function _getService() {
     return new Class_WebService_BibNumerique_Cyberlibris();
   }
diff --git a/library/Class/Batch/Dilicom.php b/library/Class/Batch/Dilicom.php
index 0f780a6d29b..0dcba5196d5 100644
--- a/library/Class/Batch/Dilicom.php
+++ b/library/Class/Batch/Dilicom.php
@@ -22,6 +22,8 @@
 
 class Class_Batch_Dilicom extends Class_Batch_Abstract {
   use Trait_StaticFileSystem;
+  const TYPE = 'MOISSONAGE_DILICOM';
+
   protected static $_client;
   protected $_logger;
   protected $_ftp_path = 'HUB/O/';
@@ -73,13 +75,19 @@ class Class_Batch_Dilicom extends Class_Batch_Abstract {
       return false;
     }
 
-    if (!$list = $client->ls($this->_ftp_path)) {
+    if (false === $list = $client->ls($this->_ftp_path)) {
       $this->_log($this->_('Impossible de lister le contenu de %s',
                            $this->_ftp_path));
       return false;
 
     }
 
+    if (!$list) {
+      $this->_log($this->_('Aucun fichier présent dans %s',
+                           $this->_ftp_path));
+      return false;
+    }
+
     $list = $this->_detectFiles($list);
 
     if (!$this->downloadAll($list))
@@ -126,14 +134,36 @@ class Class_Batch_Dilicom extends Class_Batch_Abstract {
 
     (new Class_WebService_BibNumerique_Dilicom())
       ->importOffersFile($xml, $report);
+
+    $this->setModelData($local_file);
+  }
+
+
+  protected function setModelData($data) {
+    if ($this->getModel())
+      $this->getModel()->setData($data);
+  }
+
+
+  protected function getModelData() {
+    return $this->getModel() ? $this->getModel()->getData() : null;
   }
 
 
   protected function _detectFiles($list) {
+    if ($data = $this->getModelData())
+      $list = $this->filesAfter($data, $list);
+
+    if (!$list) {
+      $this->_log($this->_('Aucun fichier plus récent que le dernier fichier déjà traité (%s)',
+                           $data));
+      return [];
+    }
+
     $fulls = $this->filterFiles($list, function($name) { return $this->isFull($name); });
     $incs = $this->filterFiles($list, function($name) { return $this->isIncremental($name); });
 
-    $this->_log($this->_('%s fichier(s) présent(s) dans %s',
+    $this->_log($this->_('%s fichier(s) à traiter dans %s',
                          count($fulls) + count($incs),
                          $this->_ftp_path));
 
diff --git a/library/Class/Batch/IndexRessourcesNumeriques.php b/library/Class/Batch/IndexRessourcesNumeriques.php
index db8a2945d1e..77a0b1aa464 100644
--- a/library/Class/Batch/IndexRessourcesNumeriques.php
+++ b/library/Class/Batch/IndexRessourcesNumeriques.php
@@ -1,6 +1,8 @@
 <?php
 
 class Class_Batch_IndexRessourcesNumeriques extends Class_Batch_Abstract {
+  const TYPE = 'INDEX_RESSOURCES_NUMERIQUES';
+
   public function getLabel() {
     return $this->_("Indexer les ressources numériques");
   }
diff --git a/library/Class/Batch/Jamendo.php b/library/Class/Batch/Jamendo.php
index 11e7bb1b172..68148377f6d 100644
--- a/library/Class/Batch/Jamendo.php
+++ b/library/Class/Batch/Jamendo.php
@@ -21,6 +21,8 @@
 
 
 class Class_Batch_Jamendo extends Class_Batch_RessourceNumerique{
+  const TYPE = 'MOISSONAGE_JAMENDO';
+
   protected function _getService() {
     return new Class_WebService_BibNumerique_Jamendo();
   }
diff --git a/library/Class/Batch/NumeriquePremium.php b/library/Class/Batch/NumeriquePremium.php
index 63cfcdc4cec..375eceacfea 100644
--- a/library/Class/Batch/NumeriquePremium.php
+++ b/library/Class/Batch/NumeriquePremium.php
@@ -16,11 +16,13 @@
  *
  * 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 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 
 class Class_Batch_NumeriquePremium extends Class_Batch_RessourceNumerique{
+  const TYPE = 'MOISSONNAGE_NUMERIQUEPREMIUM';
+
   protected function _getService() {
     return new Class_WebService_BibNumerique_NumeriquePremium();
   }
diff --git a/library/Class/Batch/Numilog.php b/library/Class/Batch/Numilog.php
index 90ba4fe80b1..232529d1be2 100644
--- a/library/Class/Batch/Numilog.php
+++ b/library/Class/Batch/Numilog.php
@@ -16,11 +16,13 @@
  *
  * 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 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 
 class Class_Batch_Numilog extends Class_Batch_RessourceNumerique{
+  const TYPE = 'MOISSONNAGE_NUMILOG';
+
   protected function _getService() {
     return new Class_WebService_BibNumerique_Numilog();
   }
diff --git a/library/Class/Batch/OneDTouch.php b/library/Class/Batch/OneDTouch.php
index 31013f4953d..a80c6aa6fd4 100644
--- a/library/Class/Batch/OneDTouch.php
+++ b/library/Class/Batch/OneDTouch.php
@@ -16,11 +16,13 @@
  *
  * 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 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 
 class Class_Batch_OneDTouch extends Class_Batch_RessourceNumerique{
+  const TYPE = 'MOISSONAGE_1DTOUCH';
+
   protected function _getService() {
     return new Class_WebService_BibNumerique_OneDTouch();
   }
diff --git a/library/Class/Batch/Orphea.php b/library/Class/Batch/Orphea.php
index d8453855332..588ea1bba7b 100644
--- a/library/Class/Batch/Orphea.php
+++ b/library/Class/Batch/Orphea.php
@@ -21,6 +21,8 @@
 
 
 class Class_Batch_Orphea extends Class_Batch_RessourceNumerique{
+  const TYPE = 'MOISSONAGE_ORPHEA';
+
   protected function _getService() {
     return new Class_WebService_BibNumerique_Orphea();
   }
diff --git a/library/Class/Batch/PanierNotice.php b/library/Class/Batch/PanierNotice.php
index 03554726137..e5f1edff101 100644
--- a/library/Class/Batch/PanierNotice.php
+++ b/library/Class/Batch/PanierNotice.php
@@ -16,11 +16,13 @@
  *
  * 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 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 
 class Class_Batch_PanierNotice extends Class_Batch_Abstract {
+  const TYPE = 'CORRECTION_PANIERS';
+
   public function getLabel() {
     return $this->_('Recherche les notices perdues des paniers');
   }
diff --git a/library/Class/Batch/PanierUser.php b/library/Class/Batch/PanierUser.php
index c9be2737d78..fb801ddbf9e 100644
--- a/library/Class/Batch/PanierUser.php
+++ b/library/Class/Batch/PanierUser.php
@@ -16,11 +16,13 @@
  *
  * 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 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 
 class Class_Batch_PanierUser extends Class_Batch_Abstract {
+  const TYPE = 'CART_REALLOCATION';
+
   public function getLabel() {
     return $this->_('Réaffecte les paniers perdus des abonnés');
   }
diff --git a/library/Class/Batch/ToutApprendre.php b/library/Class/Batch/ToutApprendre.php
index 5dd3409ae9b..47bc9e5232b 100644
--- a/library/Class/Batch/ToutApprendre.php
+++ b/library/Class/Batch/ToutApprendre.php
@@ -16,11 +16,13 @@
  *
  * 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 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 
 class Class_Batch_ToutApprendre extends Class_Batch_RessourceNumerique {
+  const TYPE = 'MOISSONNAGE_TOUTAPPRENDRE';
+
   protected function _getService() {
     return new Class_WebService_BibNumerique_ToutApprendre();
   }
diff --git a/library/Class/Batch/Typo3.php b/library/Class/Batch/Typo3.php
index d1541c0ff54..3d9ba03157c 100644
--- a/library/Class/Batch/Typo3.php
+++ b/library/Class/Batch/Typo3.php
@@ -21,6 +21,8 @@
 
 
 class Class_Batch_Typo3 extends Class_Batch_Abstract {
+  const TYPE = 'IMPORT_TYPO3';
+
   public function getLabel() {
     return $this->_('Import d\'articles TYPO3');
   }
diff --git a/library/Class/Batch/Vodeclic.php b/library/Class/Batch/Vodeclic.php
index 026cbe0f5b2..bc56e6e8fd8 100644
--- a/library/Class/Batch/Vodeclic.php
+++ b/library/Class/Batch/Vodeclic.php
@@ -16,11 +16,13 @@
  *
  * 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 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 
 class Class_Batch_Vodeclic extends Class_Batch_RessourceNumerique{
+  const TYPE = 'MOISSONNAGE_VODECLIC';
+
   protected function _getService() {
     return new Class_WebService_BibNumerique_Vodeclic();
   }
diff --git a/tests/library/Class/Batch/DilicomTest.php b/tests/library/Class/Batch/DilicomTest.php
index 99f8535f451..96d5c078639 100644
--- a/tests/library/Class/Batch/DilicomTest.php
+++ b/tests/library/Class/Batch/DilicomTest.php
@@ -52,6 +52,8 @@ abstract class Class_Batch_DilicomTestCase extends ModelTestCase {
                                        ->answers(file_get_contents(__DIR__ . '/diffusion_pnb_3056309900005_20150728T050431Z.xml'))
     );
 
+    $this->_prepareFixtures();
+
     $batch = new Class_Batch_Dilicom();
     $batch
       ->setLogger($this->getLogger())
@@ -59,6 +61,10 @@ abstract class Class_Batch_DilicomTestCase extends ModelTestCase {
   }
 
 
+  protected function _prepareFixtures() {
+
+  }
+
   public function getFtpClient() {
     return $this->mock();
   }
@@ -185,7 +191,7 @@ class Class_Batch_DilicomWithFullTest extends Class_Batch_DilicomTestCase {
 
   /** @test */
   public function shouldLog4FilesInDirectory() {
-    $this->assertContains('4 fichier(s) présent(s) dans HUB/O/', $this->_log);
+    $this->assertContains('4 fichier(s) à traiter dans HUB/O/', $this->_log);
   }
 
 
@@ -210,6 +216,49 @@ class Class_Batch_DilicomWithFullTest extends Class_Batch_DilicomTestCase {
 }
 
 
+class Class_Batch_DilicomWithDataTest extends Class_Batch_DilicomTestCase {
+  public function getFtpClient() {
+    return parent::getFtpClient()
+      ->whenCalled('connect')
+      ->with('pftp.centprod.com', '007', 'IGotZeLicense')
+      ->answers(true)
+
+      ->whenCalled('ls')
+      ->with('HUB/O/')
+      ->answers(['full_pnb_3056309900005_20150726T050431Z.xml',
+                 'full_pnb_3056309900005_20150719T050431Z.xml',
+                 'diffusion_pnb_3056309900005_20150720T050431Z.xml',
+                 'diffusion_pnb_3056309900005_20150728T050431Z.xml',
+                 '007.xml'])
+
+      ->whenCalled('get')
+      ->with('HUB/O/full_pnb_3056309900005_20150726T050431Z.xml',
+             PATH_TEMP . 'dilicom/full_pnb_3056309900005_20150726T050431Z.xml')
+      ->answers(true)
+
+      ->whenCalled('get')
+      ->with('HUB/O/diffusion_pnb_3056309900005_20150728T050431Z.xml',
+             PATH_TEMP . 'dilicom/diffusion_pnb_3056309900005_20150728T050431Z.xml')
+      ->answers(true)
+
+      ->beStrict();
+  }
+
+  protected function _prepareFixtures() {
+    $this->fixture('Class_Batch',
+                   [ 'id' => 12,
+                    'type' => Class_Batch_Dilicom::TYPE,
+                    'data' => 'full_pnb_3056309900005_20150822T050431Z.xml']);
+  }
+
+  /** @test */
+  public function shouldLogFullFileToProcess() {
+    $this->assertContains('Aucun fichier plus récent que le dernier fichier déjà traité (full_pnb_3056309900005_20150822T050431Z.xml)',
+                          $this->_log);
+  }
+}
+
+
 
 class Class_Batch_DilicomWithoutFullTest extends Class_Batch_DilicomTestCase {
   public function getFtpClient() {
@@ -240,7 +289,7 @@ class Class_Batch_DilicomWithoutFullTest extends Class_Batch_DilicomTestCase {
 
   /** @test */
   public function shouldLog2FilesInDirectory() {
-    $this->assertContains('2 fichier(s) présent(s) dans HUB/O/', $this->_log);
+    $this->assertContains('2 fichier(s) à traiter dans HUB/O/', $this->_log);
   }
 
 
@@ -255,4 +304,4 @@ class Class_Batch_DilicomWithoutFullTest extends Class_Batch_DilicomTestCase {
     $this->assertContains('Fichiers incrémentaux à traiter : diffusion_pnb_3056309900005_20150720T050431Z.xml diffusion_pnb_3056309900005_20150728T050431Z.xml',
                           $this->_log);
   }
-}
\ No newline at end of file
+}
-- 
GitLab