From 884239992ac92a95056a68cf7f6ebf5d4ad5d591 Mon Sep 17 00:00:00 2001
From: gloas <gloas@afi-sa.fr>
Date: Tue, 23 Jan 2018 14:53:47 +0100
Subject: [PATCH] dev #69826 : wip cosmogramme phase

---
 cosmogramme/php/integre_traite_main.php       | 13 ++++++
 .../Integration/PhaseBookmarkedSearches.php   | 43 +++++++++++++++++++
 tests/scenarios/bookmarks/SearchTest.php      | 39 +++++++++++++++++
 3 files changed, 95 insertions(+)
 create mode 100644 library/Class/Cosmogramme/Integration/PhaseBookmarkedSearches.php

diff --git a/cosmogramme/php/integre_traite_main.php b/cosmogramme/php/integre_traite_main.php
index 025f46c848b..3cb54cbaa47 100644
--- a/cosmogramme/php/integre_traite_main.php
+++ b/cosmogramme/php/integre_traite_main.php
@@ -532,11 +532,24 @@ if ($phase==14 or $phase==15) {
 	$phase = 16;
 }
 
+
+// ----------------------------------------------------------------
+// Indexation Domaines
+// ----------------------------------------------------------------
 if ($phase==16 or $phase==17) {
 	include("integration/domaines.php");
+}
+
+
+// ----------------------------------------------------------------
+// DSI - Notifications des nouveautés
+// ----------------------------------------------------------------
+if ($phase==17 or $phase==18) {
+  startIntegrationPhase('BookmarkedSearches');
 	$phase=20;
 }
 
+
 // ----------------------------------------------------------------
 // Envoi de mails aux bibs qui ont du retard
 // ----------------------------------------------------------------
diff --git a/library/Class/Cosmogramme/Integration/PhaseBookmarkedSearches.php b/library/Class/Cosmogramme/Integration/PhaseBookmarkedSearches.php
new file mode 100644
index 00000000000..b35ffb49867
--- /dev/null
+++ b/library/Class/Cosmogramme/Integration/PhaseBookmarkedSearches.php
@@ -0,0 +1,43 @@
+<?php
+/**
+ * Copyright (c) 2012-2017, 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_PhaseBookmarkedSearches extends Class_Cosmogramme_Integration_PhaseAbstract {
+  const MY_ID = 18;
+
+  public function __construct($phase, $log, $chrono) {
+    parent::__construct($phase, $log, $chrono);
+    $this->_label = $this->_('Notification des nouveautés dans les recherches favorites');
+  }
+
+
+  protected function _init($phase) {
+    $phase->resetDatas();
+  }
+
+
+  protected function _execute() {
+    if (!$this->_phase->isCron()) {
+      $this->_log->log($this->_('Ce traitement ne se lance qu\'en mode cron.'));
+      return;
+    }
+  }
+}
diff --git a/tests/scenarios/bookmarks/SearchTest.php b/tests/scenarios/bookmarks/SearchTest.php
index 6a20001e4c6..684b75859eb 100644
--- a/tests/scenarios/bookmarks/SearchTest.php
+++ b/tests/scenarios/bookmarks/SearchTest.php
@@ -381,4 +381,43 @@ class Bookmarks_SearchAuthorizedActionTest extends Bookmarks_SearchWithSessionAb
       $this->assertNotNull(Class_User_BookmarkedSearch::find(5));
       $this->assertFlashMessengerContentContains('Vous n\'avez pas la permission');
   }
+}
+
+
+
+class Bookmarks_SearchCosmogrammePhaseTest extends Class_Cosmogramme_Integration_PhaseTestCase {
+  protected $_result;
+
+  protected function _getPreviousPhase() {
+    return (new Class_Cosmogramme_Integration_Phase(17))
+      ->beCron();
+  }
+
+
+  protected function _prepareFixtures() {
+    $criteres_potter = (new Class_CriteresRecherche)
+      ->setParams(['expressionRecherche' => 'Harry Potter',
+                   'page' => 2]);
+
+    $this->fixture('Class_User_BookmarkedSearch',
+                   ['id' => 5,
+                    'criterias' => $criteres_potter,
+                    'notified' => 1]);
+  }
+
+
+  public function setUp() {
+    parent::setUp();
+    $this->_phase = $this->_buildPhase('BookmarkedSearches')
+                         ->setMemoryCleaner(function() {})
+                         ->setPrinter($this->_printer);
+
+    $this->_result = $this->_phase->run();
+  }
+
+
+  /** @test */
+  public function fooShouldBar() {
+    $this->assertTrue(false);
+  }
 }
\ No newline at end of file
-- 
GitLab