From 9cfac3028aaa291cc66e658a0a8a90b88c3ec487 Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@git-test.afi-sa.fr>
Date: Tue, 16 Jul 2013 14:08:57 +0000
Subject: [PATCH] Les requetes kiosques ne font plus de select *

---
 library/Class/Catalogue.php                   | 20 ++++++++++++-------
 .../ZendAfi/View/Helper/Accueil/Kiosque.php   |  2 +-
 tests/library/Class/CatalogueTest.php         |  4 ++--
 .../View/Helper/Accueil/KiosqueTest.php       |  2 +-
 4 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/library/Class/Catalogue.php b/library/Class/Catalogue.php
index 9acd634e956..7872ad87142 100644
--- a/library/Class/Catalogue.php
+++ b/library/Class/Catalogue.php
@@ -338,11 +338,13 @@ class Class_Catalogue extends Storm_Model_Abstract {
 
 	public function getAllNoticeIdsForDomaine($nb_par_page,$numero_page) {
 		$preferences = $this->toArray();
-		$req=$this->getRequetes($preferences);
-		//	$requete_ids=str_replace('select *',"select group_concat(id_notice separator ',')",$req['req_liste']);
-		$requete_ids=str_replace('select *',"select id_notice ",$req['req_liste']);
+
+		$req=$this->getRequetes($preferences, ['id_notice']);
+
 		$start=$nb_par_page*$numero_page;
-		$requete_ids=str_replace('LIMIT 5000',"limit ".$nb_par_page*$numero_page.','.$nb_par_page,$requete_ids);
+		$requete_ids=str_replace('LIMIT 5000',
+														 "limit ".$nb_par_page*$numero_page.','.$nb_par_page, 
+														 $req['req_liste']);
 
 		$sql = Zend_Registry::get('sql');
 
@@ -598,7 +600,7 @@ class Class_Catalogue extends Storm_Model_Abstract {
 //------------------------------------------------------------------------------
 // Rend les notices selon les preferences
 //------------------------------------------------------------------------------
-	public function getRequetes($preferences, $no_limit=false)	{
+	public function getRequetes($preferences, $fields = null)	{
 		
 		// Si panier traitement special
 		if (isset($preferences["id_panier"])  && (0 !== (int)$preferences["id_panier"])) 
@@ -632,8 +634,12 @@ class Class_Catalogue extends Storm_Model_Abstract {
 
 		// Calcul des requetes
 		$order_by = $this->orderByForCatalogueRequestByPreferences($preferences);
-		$limite = $this->limitForCatalogueRequestByPreferences($preferences, $no_limit);
-		$ret["req_liste"]="select * from notices ".$join.$where.$order_by.$limite;
+		$limite = $this->limitForCatalogueRequestByPreferences($preferences);
+
+
+		$select_fields = $fields ? implode(',', $fields): '*';
+
+		$ret["req_liste"]="select ".$select_fields." from notices ".$join.$where.$order_by.$limite;
 		$ret["req_comptage"]="select count(*) from notices ".$join.$where;
 		$ret["req_facettes"]="select notices.id_notice,type_doc,facettes from notices ".$join.$where.$limite;
 
diff --git a/library/ZendAfi/View/Helper/Accueil/Kiosque.php b/library/ZendAfi/View/Helper/Accueil/Kiosque.php
index ae4d9b52296..eba1bef890f 100644
--- a/library/ZendAfi/View/Helper/Accueil/Kiosque.php
+++ b/library/ZendAfi/View/Helper/Accueil/Kiosque.php
@@ -174,7 +174,7 @@ class ZendAfi_View_Helper_Accueil_Kiosque extends ZendAfi_View_Helper_Accueil_Ba
 		$nombre_notices_par_page = $this->preferences['nb_notices'];
 		$this->preferences['nb_notices'] = 0;
 		$this->preferences['nb_analyse'] = 0;
-		$requetes = $catalogue->getRequetes($this->preferences);
+		$requetes = $catalogue->getRequetes($this->preferences, ['id_notice']);
 
 		$nombre_total_notices = 0;
 		$notices = [];
diff --git a/tests/library/Class/CatalogueTest.php b/tests/library/Class/CatalogueTest.php
index 0a507dc6011..c683d09d001 100644
--- a/tests/library/Class/CatalogueTest.php
+++ b/tests/library/Class/CatalogueTest.php
@@ -923,7 +923,7 @@ class CatalogueGetAllNoticesIdsForDomaineTest extends Storm_Test_ModelTestCase {
 	public function queryWithNb5Page10() {
 		$this->mock_sql
 			->whenCalled('fetchAll')
-			->with('select id_notice  from notices  where MATCH(facettes) AGAINST(\' +(T1)\' IN BOOLEAN MODE) order by alpha_titre  limit 50,5')
+			->with('select id_notice from notices  where MATCH(facettes) AGAINST(\' +(T1)\' IN BOOLEAN MODE) order by alpha_titre  limit 50,5')
 			->answers([ ['id_notice' => 23, 'titre' => 'POTTER'],
 									['id_notice' => 45, 'titre' => 'POTTER2'],
 									])
@@ -936,7 +936,7 @@ class CatalogueGetAllNoticesIdsForDomaineTest extends Storm_Test_ModelTestCase {
 	public function queryWithNb1Page2() {
 		$this->mock_sql
 			->whenCalled('fetchAll')
-			->with('select id_notice  from notices  where MATCH(facettes) AGAINST(\' +(T1)\' IN BOOLEAN MODE) order by alpha_titre  limit 2,1')
+			->with('select id_notice from notices  where MATCH(facettes) AGAINST(\' +(T1)\' IN BOOLEAN MODE) order by alpha_titre  limit 2,1')
 			->answers([])
 			->beStrict();
 		$this->assertEquals([], $this->_catalogue->getAllNoticeIdsForDomaine(1, 2));
diff --git a/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php b/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php
index f330aed4f43..7e10b64578a 100644
--- a/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php
+++ b/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php
@@ -190,7 +190,7 @@ class ZendAfi_View_Helper_Accueil_KiosqueRequetesTest extends ZendAfi_View_Helpe
 			->whenCalled('fetchOne')->with("select count(*) from notices  where url_vignette > '' and url_vignette != 'NO'")
 			->answers(10)
 
-			->whenCalled('fetchAll')->with("select * from notices  where url_vignette > '' and url_vignette != 'NO' order by date_creation DESC  LIMIT 5000", false)
+			->whenCalled('fetchAll')->with("select id_notice from notices  where url_vignette > '' and url_vignette != 'NO' order by date_creation DESC  LIMIT 5000", false)
 			->answers([ ['id_notice' => 2],
 									['id_notice' => 45] ])
 			->beStrict();
-- 
GitLab