Commit e4e9a97c authored by Ghislain Loas's avatar Ghislain Loas
Browse files

Merge branch...

Merge branch 'dev#65212_explo_ne_plus_dupliquer_les_vignettes_dans_les_caches_locaux_de_chaque_bokeh' into 'stable'

dev #65212 replace writed local image to png response

See merge request !2353
parents d00d302b 3bc6b82a
- ticket #65212 : Les vignettes ne sont plus dupliquées dans le cache local de Bokeh
\ No newline at end of file
......@@ -437,6 +437,19 @@ class RechercheController extends ZendAfi_Controller_Action {
}
public function rawThumbnailAction() {
$viewRenderer = $this->getHelper('ViewRenderer');
$viewRenderer->setNoRender();
session_write_close();
$record = Class_Notice::find((int)$this->_getParam('id'));
(new Class_WebService_Vignette())
->renderThumbnail($record->getId(),
$record->getTitrePrincipal(),
$record->getTypeDoc());
}
public function reservationAction() {
if ((!$library = Class_Bib::find((int)$this->_getParam('id_bib')))
|| !$record = Class_Notice::find((int)$this->_getParam('id_notice'))) {
......
......@@ -395,9 +395,7 @@ class Class_Notice extends Storm_Model_Abstract {
$url = $this->getUrlVignette();
if ($url=='NO')
return Class_WebService_Vignette::saveImage($this->getId(),
$this->getTitrePrincipal(),
$this->getTypeDoc());
return $this->_rawThumbnailUrl();
return $url ? $url : Class_WebService_Vignette::getAjaxUrl($this);
}
......@@ -411,14 +409,19 @@ class Class_Notice extends Storm_Model_Abstract {
$url = $this->getUrlVignette();
}
if ($url=='NO')
return $ws_vignette->saveImage($this->getId(),
$this->getTitrePrincipal(),
$this->getTypeDoc());
return ($url=='NO')
? $this->_rawThumbnailUrl()
: $ws_vignette->writeImageCache($this, $url);
}
return $ws_vignette->writeImageCache($this, $url);
protected function _rawThumbnailUrl() {
return Class_Url::assemble(['controller' => 'recherche',
'action' => 'raw-thumbnail',
'id' => $this->getId()]);
}
public function getFetchUrlVignette() {
return $this->fetchUrlVignette();
}
......
......@@ -21,7 +21,7 @@
class Class_Notice_Thumbnail_ProviderCacheServer
extends Class_Notice_Thumbnail_ProviderCloud {
extends Class_Notice_Thumbnail_ProviderAbstract {
public function updateNotice() {
if (!$urls = $this->_getUrls())
......
<?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_Notice_Thumbnail_ProviderCloud
extends Class_Notice_Thumbnail_ProviderAbstract {
public function writeImageCache($url) {
$nom_fic = 'notice_' . $this->_record->getId().".jpg";
$path = $this->_getPath($nom_fic);
try {
if ($this->_filesystem->fileExists($path)==false) {
$data = (new Class_WebService_Abstract())->httpGet($url);
$this->_filesystem->filePutContents($path, $data);
}
} catch(Exception $e) {
return null;
}
return $this->_getUrl($nom_fic);
}
}
......@@ -21,7 +21,7 @@
class Class_Notice_Thumbnail_ProviderThirdParty
extends Class_Notice_Thumbnail_ProviderCloud {
extends Class_Notice_Thumbnail_ProviderAbstract {
public function updateNotice() {
return ($url = $this->_getThirdPartyUrl())
......
......@@ -88,20 +88,13 @@ class Class_WebService_Vignette extends Class_WebService_Abstract {
}
static function saveImage($id_notice,$titre,$type_doc) {
$filename = "/temp/vignettes_titre/notice_".$id_notice.".png";
$full_path = getcwd().$filename;
if (static::getFileSystem()->fileExists($full_path))
return $filename;
static function renderThumbnail($id_notice,$titre,$type_doc) {
$image = static::createImage($titre,
$width=100,
$height=90,
$type_doc);
imagepng($image, $full_path);
return $filename;
imagepng($image);
}
......
......@@ -645,16 +645,19 @@ class RechercheControllerViewNoticeMetasTest extends RechercheControllerNoticeTe
class RechercheControllerVignetteTest extends RechercheControllerNoticeTestCase {
public function setUp() {
parent::setUp();
class RechercheControllerThumbnailTest extends RechercheControllerNoticeTestCase {
/** @test */
public function rechercheVignetteActionShouldRedirectToRawThumbnailAction() {
$this->dispatch('recherche/vignette/id_notice/345', true);
$this->assertRedirectTo(Class_Url::absolute('/recherche/raw-thumbnail/id/345'),
$this->getResponseLocation());
}
/** @test */
public function responseShouldRedirectToVignetteUrl() {
$this->assertContains('/temp/vignettes_titre/notice_345.png',
$this->getResponseLocation());
public function rawThumbnailForIdNoticeTwoShouldAnswerPngImage() {
$this->dispatch('/recherche/raw-thumbnail/id/345', true);
$this->assertContains('iVBORw0', base64_encode($this->_response->getBody()));
}
}
......@@ -682,8 +685,8 @@ class RechercheControllerVignetteEmptyTest extends AbstractControllerTestCase {
/** @test */
public function responseShouldRedirectToVignetteUrl() {
$this->assertContains('/temp/vignettes_titre/notice_1.png',
public function responseShouldRedirectToRawThumbnailUrl() {
$this->assertContains(Class_Url::absolute('/recherche/raw-thumbnail/id/1'),
$this->getResponseLocation());
}
}
......
......@@ -185,32 +185,34 @@ class NoticeVignetteTest extends ModelTestCase {
'image' => 'diplo.jpg']))
->beStrict();
$this->assertEquals('/temp/vignettes_titre/notice_9.png',
$this->assertEquals(Class_Url::assemble(['controller' => 'recherche',
'action' => 'raw-thumbnail',
'id' => 9]),
$this->_serial_without_thumbnails->fetchUrlLocalVignette());
}
/** @test */
public function withInexistingThumbnailFetchUrlVignetteShouldAnswerLocalUrl() {
public function withInexistingThumbnailFetchUrlVignetteShouldAnswerRawUrlThumbnail() {
$this->assertFalse($this->_http_client->methodHasBeenCalled('open_url'));
$this->assertEquals('/temp/vignettes_titre/notice_2.png',
$this->assertEquals(Class_Url::assemble(['controller' => 'recherche',
'action' => 'raw-thumbnail',
'id' => 2]),
$this->_notice_inexisting_thumbnails->fetchUrlVignette());
}
/** @test */
public function withoutThumbnailFetchUrlLocalVignetteFoundShouldAnswerLocalUrl() {
public function withoutThumbnailFetchUrlLocalVignetteFoundShouldAnswerImageFromCacheServer() {
$this->_http_client
->whenCalled('open_url')
->with('from_cache_small.jpg')
->answers('some data');
$this->assertEquals('/temp/vignettes_titre/notice_1.jpg',
$this->assertEquals('from_cache_small.jpg',
$this->_notice_without_thumbnails->fetchUrlLocalVignette());
$this->assertContains('some data',
$this->_filesystem->fileGetContents(PATH_TEMP.'vignettes_titre/notice_1.jpg'));
Class_Notice::clearCache();
$this->assertEquals('from_cache_small.jpg', Class_Notice::find(1)->getUrlVignette());
......@@ -292,12 +294,14 @@ class NoticeVignetteTest extends ModelTestCase {
/** @test */
public function withoutThumbnailFetchUrlLocalVignetteNotFoundShouldAnswerLocalUrl() {
public function withoutThumbnailFetchUrlLocalVignetteNotFoundShouldAnswerRawUrlThumbnail() {
$this->_http_client
->whenCalled('open_url')
->answers('');
$this->assertEquals('/temp/vignettes_titre/notice_1.png',
$this->assertEquals(Class_Url::assemble(['controller' => 'recherche',
'action' => 'raw-thumbnail',
'id' => 1]),
$this->_notice_without_thumbnails->fetchUrlLocalVignette());
Class_Notice::clearCache();
......@@ -307,34 +311,22 @@ class NoticeVignetteTest extends ModelTestCase {
/** @test */
public function withThumbnailFetchUrlLocalVignetteShouldAnswerIt() {
$this->_http_client
->whenCalled('open_url')
->with('tintin_small.jpg')
->answers('some data');
$this->assertEquals('/temp/vignettes_titre/notice_3.jpg',
$this->assertEquals('tintin_small.jpg',
$this->_notice_with_thumbnails->fetchUrlLocalVignette());
$this->assertContains('some data',
$this->_filesystem->fileGetContents(PATH_TEMP.'vignettes_titre/notice_3.jpg'));
}
/** @test */
public function urlThumbnailShoudBeFromGamAnnecy() {
$this->_http_client
->whenCalled('open_url')
->with('http://www.gamannecy.com/polysson/201009/05-3760127221081.jpg')
->answers('some data')
->beStrict();
$this->assertEquals('/temp/vignettes_titre/notice_8.jpg',
$this->assertEquals('http://www.gamannecy.com/polysson/201009/05-3760127221081.jpg',
$this->_notice_gam->fetchUrlLocalVignette());
$this->assertContains('some data',
$this->_filesystem->fileGetContents(PATH_TEMP.'vignettes_titre/notice_8.jpg'));
}
......@@ -344,26 +336,19 @@ class NoticeVignetteTest extends ModelTestCase {
Class_Profil::getCurrentProfil()
->setCfgModules(['recherche' => ['viewnotice'.Class_TypeDoc::DISQUE => $preferences]]);
$this->_http_client
->whenCalled('open_url')
->with('from_cache_small.jpg')
->answers('some data');
$this->assertEquals('/temp/vignettes_titre/notice_8.jpg',
$this->assertEquals('from_cache_small.jpg',
$this->_notice_gam->fetchUrlLocalVignette());
$this->assertContains('some data',
$this->_filesystem->fileGetContents(PATH_TEMP.'vignettes_titre/notice_8.jpg'));
}
/** @test */
public function withInexistingThumbnailFetchUrlLocalVignetteShouldAnswerLocalFile() {
public function withInexistingThumbnailFetchUrlLocalVignetteShouldAnswerRawUrlThumbnail() {
$this->assertFalse($this->_http_client->methodHasBeenCalled('open_url'));
$this->assertEquals('/temp/vignettes_titre/notice_2.png',
$this->_notice_inexisting_thumbnails->fetchUrlLocalVignette());
$this->assertEquals(Class_Url::assemble(['controller' => 'recherche',
'action' => 'raw-thumbnail',
'id' => 2]),
$this->_notice_inexisting_thumbnails->fetchUrlLocalVignette());
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment