Commit ff7a3355 authored by Patrick Barroca's avatar Patrick Barroca 😠
Browse files

Merge branch 'hotline#104766_pnb_pas_de_vignette' into 'hotline'

hotline #104766 add tools to reset thumbnails for a specific doc type

See merge request !3397
parents 08cdb4e7 03b04ff0
Pipeline #9403 passed with stage
in 55 minutes and 47 seconds
- ticket #104766 : Ajout d'actions dans l'interface d'administration "Types de documents" pour réinitialiser toutes les vignettes pour un type donné
\ No newline at end of file
......@@ -23,6 +23,22 @@ class Admin_TypeDocsController extends ZendAfi_Controller_Action {
public function getPlugins() {
return ['ZendAfi_Controller_Plugin_ResourceDefinition_DocType',
'ZendAfi_Controller_Plugin_Manager_Manager'];
'ZendAfi_Controller_Plugin_Manager_DocType'];
}
public function resetThumbnailsAction() {
$id = $this->_getParam('id');
if (!$type_doc = Class_TypeDoc::find($id)) {
$this->_helper->notify($this->_('Type de document inconnu'));
return $this->_redirect('/admin/type-docs');
}
Zend_Registry::get('sql')->execute("update notices set url_vignette='', url_image='' where type_doc='" . $type_doc->getId() . "'");
$this->_helper->notify($this->_('Vignettes réinitialisées pour le type %s',
$type_doc->getLibelle()));
$this->_redirect('/admin/type-docs');
}
}
<?php
Class_ScriptLoader::getInstance()
->addSearchInputToContent($this->_('Filtrer les connecteurs '));
?>
<p><?php
echo $this->_("Bokeh s'interface avec un certain nombre de ressources numériques. Les ressources numérisées sont cataloguées dans le portail et indexées dans l’OPAC comme les notices du SIGB. Ce qui constitue la force et le caractère unique de Bokeh, est sa capacité à proposer une recherche fusionnée par un métamoteur qui interroge simultanément tous les fonds et tous les contenus.");
?></p>
......
<?php
echo $this->tagModelTable($this->type_docs,
[$this->_('Libellé'), $this->_('Famille')],
['label', 'libelle_famille'],
[ ['action' => 'edit' , 'content' => $this->boutonIco('type=edit')]],
'type_docs');
Class_ScriptLoader::getInstance()
->addSearchInputToContent($this->_('Filtrer les types de documents'));
$description = (new Class_TableDescription('type_docs'))
->addColumn($this->_('Libellé'), 'label')
->addColumn($this->_('Famille'), 'libelle_famille')
->addRowAction(function($model) { return $this->renderPluginsActions($model); });
echo $this->renderTable($description,
$this->type_docs);
?>
......@@ -24,7 +24,7 @@ abstract class Class_Notice_Thumbnail_ProviderAbstract {
const THUMBS_DIRECTORY = 'vignettes_titre/';
protected static $_default_image_factory;
protected $_filesystem, $_record;
protected $_record;
/** @category testing */
......@@ -40,8 +40,7 @@ abstract class Class_Notice_Thumbnail_ProviderAbstract {
}
public function __construct($filesystem, $record) {
$this->_filesystem = $filesystem;
public function __construct($record) {
$this->_record = $record;
}
......
......@@ -23,8 +23,24 @@
class Class_Notice_Thumbnail_ProviderAlbum
extends Class_Notice_Thumbnail_ProviderLocal {
use Trait_StaticFileSystem;
protected function _getOriginalUrlOrPath() {
return ($album = $this->_record->getAlbum()) && ($path = $album->getFirstImagePathFoundInResources())
? $path : null;
if (!$album = $this->_record->getAlbum())
return null;
if ($path = $album->getFirstImagePathFoundInResources())
return $path;
if (($path = $album->getVignettePath()) && $this->getFileSystem()->file_exists($path))
return $path;
if (!$url = $album->getPoster())
return null;
if ((new Class_WebService_BibNumerique_Vignette())->downloadPoster($album))
return $album->getVignettePath();
return null;
}
}
......@@ -21,7 +21,7 @@
class Class_Notice_Thumbnail_ProviderFactory {
public function newWith($file_system, $notice) {
public function newWith($notice) {
$mapping =
['Article' => function($record) { return $record->isArticleCms(); },
'Album' => function($record) { return $this->_isAlbum($record); },
......@@ -33,7 +33,7 @@ class Class_Notice_Thumbnail_ProviderFactory {
foreach ($mapping as $name => $closure)
if ($closure($notice)) {
$class_name = 'Class_Notice_Thumbnail_Provider' . $name;
return new $class_name($file_system, $notice);
return new $class_name($notice);
}
}
......
......@@ -26,7 +26,7 @@ class Class_Notice_Thumbnail_ProviderThirdParty
public function updateNotice() {
return ($url = $this->_getThirdPartyUrl())
? $this->_setRecordUrls($url)
: (new Class_Notice_Thumbnail_ProviderCacheServer($this->_filesystem, $this->_record))->updateNotice();
: (new Class_Notice_Thumbnail_ProviderCacheServer($this->_record))->updateNotice();
}
......
......@@ -20,8 +20,6 @@
*/
class Class_WebService_Vignette extends Class_WebService_Abstract {
use Trait_StormFileSystem;
const NO_DATA = 'NO';
public static function getClefControle() {
......@@ -43,7 +41,7 @@ class Class_WebService_Vignette extends Class_WebService_Abstract {
public function getThumbnailProviderFor($notice) {
$factory = new Class_Notice_Thumbnail_ProviderFactory();
return $factory->newWith($this->getFileSystem(), $notice);
return $factory->newWith($notice);
}
......
<?php
/**
* Copyright (c) 2012-2020, 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 ZendAfi_Controller_Plugin_Manager_DocType extends ZendAfi_Controller_Plugin_Manager_Manager {
public function getActions($model) {
return
[
['url' => '/admin/type-docs/edit/id/%s',
'icon' => 'edit',
'label' => $this->_('Modifier le type de document %s', $model->getLibelle())],
['url' => '/admin/type-docs/reset-thumbnails/id/%s',
'icon' => 'images',
'label' => $this->_('Réinitialiser les vignettes des notices de type %s', $model->getLibelle()),
'anchorOptions' => $this->_confirm($this->_('Êtes vous sûr(e) de réinitialiser l\'ensemble des vignettes des notices de type "%s" ?', $model->getLibelle()))],
['url' => '/recherche/simple/type_doc/%s',
'icon' => 'view',
'anchorOptions' => ['target' => '_blank'],
'label' => $this->_('Lancer une recherche de notices de type %s', $model->getLibelle())]
];
}
}
\ No newline at end of file
......@@ -28,7 +28,9 @@ class ZendAfi_Form_TypeDocs_Edit extends ZendAfi_Form {
if (!$id_type_doc)
return $form;
$type_doc= Class_TypeDoc::find($id_type_doc);
if (!$type_doc = Class_TypeDoc::find($id_type_doc))
return $form;
if (!$type_doc->isRessourceNumerique())
return $form;
......
......@@ -911,12 +911,6 @@ class CmsControllerArticleConcertEditActionPostTest extends CmsControllerWithPer
public function setUp() {
parent::setUp();
$filesystem = new Storm_FileSystem_Volatile();
$thumbnail_paths = PATH_TEMP .'vignettes_titre/';
$filesystem
->mkdir($thumbnail_paths)
->cd($thumbnail_paths);
Class_Article::setFileWriter($this->mock()
->whenCalled('fileExists')
->with(BASE_URL.'/images/bonlieu.jpg')
......@@ -936,8 +930,6 @@ class CmsControllerArticleConcertEditActionPostTest extends CmsControllerWithPer
->beStrict());
Class_WebService_Vignette::setFileSystem($filesystem);
$image = $this->mock()
->whenCalled('thumbnailImage')
->with(500, 500, true, false)
......@@ -1025,7 +1017,6 @@ class CmsControllerArticleConcertEditActionPostTest extends CmsControllerWithPer
public function tearDown() {
Class_WebService_Vignette::setFileSystem(null);
Class_Notice_Thumbnail_ProviderAbstract::setDefaultImageFactory(null);
parent::tearDown();
}
......
......@@ -91,6 +91,24 @@ class TypeDocsControllerIndexTest extends AbstractTypeDocsControllerTestCase {
}
/** @test */
public function tableShouldContainsLinkToResetThumbnails() {
$this->assertXPath('//a[contains(@href, "admin/type-docs/reset-thumbnails/id/1")]');
}
/** @test */
public function tableShouldContainsLinksToOpenSearchOnTypeDoc() {
$this->assertXPath('//a[contains(@href, "/recherche/simple/type_doc/1")][@target="_blank"]');
}
/** @test */
public function pageShouldContainsSearchInput() {
$this->assertXPathContentContains('//script', '.search_input(');
}
/** @test */
public function tableShouldContainsLinkToEditEbooKs() {
$this->assertXPath('//a[contains(@href, "admin/type-docs/edit/id/102")]', $this->_response->getBody());
......@@ -104,6 +122,8 @@ class TypeDocsControllerIndexTest extends AbstractTypeDocsControllerTestCase {
}
class TypeDocsControllerEditTest extends AbstractTypeDocsControllerTestCase {
public function setUp() {
parent::setUp();
......@@ -247,4 +267,47 @@ class TypeDocsControllerEditEbookPostTest extends AbstractTypeDocsControllerTest
$this->assertEquals(4,Class_CodifTypeDoc::find(102)->getFamilleId());
}
}
class TypeDocsControllerResetThumbnailsTest extends AbstractTypeDocsControllerTestCase {
protected $_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
Zend_Registry::set('sql',
$this->mock()
->whenCalled('execute')
->with('update notices set url_vignette=\'\', url_image=\'\' where type_doc=\'Assimil\'')
->answers(null)
->beStrict());
}
/** @test */
public function withAssmilTypeDocShouldResetUrlVignetteAndImage() {
$this->dispatch('/admin/type-docs/reset-thumbnails/id/Assimil');
$this->assertTrue(Zend_Registry::get('sql')->methodHasBeenCalled('execute'));
}
/** @test */
public function withAssmilTypeDocShouldRedirectToAdminTypeDocs() {
$this->dispatch('/admin/type-docs/reset-thumbnails/id/Assimil');
$this->assertRedirectTo('/admin/type-docs');
}
/** @test */
public function withAssmilTypeDocShouldNotifyThumbnailsReset() {
$this->dispatch('/admin/type-docs/reset-thumbnails/id/Assimil');
$this->assertFlashMessengerContentContains('Vignettes réinitialisées pour le type ASSIMIL e-méthode');
}
/** @test */
public function withUnknowTypeDocShouldNotifyError() {
$this->dispatch('/admin/type-docs/reset-thumbnails/id/PouetTagada');
$this->assertFlashMessengerContentContains('Type de document inconnu');
}
}
?>
\ No newline at end of file
......@@ -22,20 +22,16 @@
abstract class RechercheControllerThumbnailTestCase extends AbstractControllerTestCase {
protected
$_storm_default_to_volatile = true,
$_file_system;
$_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
$this->_file_system = $this->mock();
Class_WebService_Vignette::setFileSystem($this->_file_system);
Class_Notice_Thumbnail_ProviderAbstract::setDefaultImageFactory($this->_getCoolImagick());
}
public function tearDown() {
Class_WebService_Vignette::setFileSystem(null);
Class_Notice_Thumbnail_ProviderAbstract::setDefaultImageFactory(null);
parent::tearDown();
}
......@@ -137,3 +133,62 @@ class RechercheControllerThumbnailAlbumSiteWithImageTest
$this->getResponseLocation());
}
}
class RechercheControllerThumbnailAlbumFromDigitalResourceWithBrokenThumbnailTest
extends RechercheControllerThumbnailTestCase {
public function setUp() {
parent::setUp();
$fs = $this->mock()
->whenCalled('file_exists')
->with('./userfiles/album/777/thumb_something_deleted.jpg')
->answers(false)
->whenCalled('file_exists')
->with('./userfiles/album/777/something_deleted.jpg')
->answers(false)
->beStrict();
Class_Notice_Thumbnail_ProviderAlbum::setFileSystem($fs);
Class_Album::setFileSystem($fs);
$album = $this->fixture('Class_Album',
['id' => 777,
'titre' => 'Testing Album',
'visible' => 1,
'type_doc_id' => Class_TypeDoc::JAMENDO,
'fichier' => 'something_deleted.jpg',
'status' => Class_Album::STATUS_VALIDATED]);
$album
->addPosterURI('http://jamendo.com/images/medium_XXXX.jpg')
->assertSave();
$album->index();
$album->getNotice()
->setUrlVignette('')
->setUrlImage('')
->assertSave();
$this->dispatch('recherche/vignette/id_notice/' . $album->getNotice()->getId(),
true);
}
public function tearDown() {
Class_Notice_Thumbnail_ProviderAlbum::setFileSystem(null);
Class_Album::setFileSystem(null);
parent::tearDown();
}
/** @test */
public function shouldRedirectToGeneratedThumbnailUrl() {
$this->assertContains('/temp/vignettes_titre/TESTINGALBUM------115.jpg',
$this->getResponseLocation());
}
}
......@@ -1084,12 +1084,7 @@ class ArticleIndexAllTest extends ModelTestCase {
Class_Url::setBaseUrl(null);
$_SERVER['SCRIPT_NAME'] = '/tom';
$filesystem = new Storm_FileSystem_Volatile();
$thumbnail_paths = PATH_TEMP .'vignettes_titre/';
$filesystem
->mkdir($thumbnail_paths)
->cd($thumbnail_paths);
Class_Article::setFileWriter($this->mock()
->whenCalled('fileExists')
->with('/tom/images/bonlieu.jpg')
......@@ -1101,8 +1096,6 @@ class ArticleIndexAllTest extends ModelTestCase {
->beStrict());
Class_WebService_Vignette::setFileSystem($filesystem);
$image = $this->mock()
->whenCalled('thumbnailImage')
->with(500, 500, true, false)
......
......@@ -34,14 +34,6 @@ class NoticeVignetteTest extends ModelTestCase {
Class_WebService_Vignette::setDefaultHttpClient($this->_http_client);
$this->_filesystem = new Storm_FileSystem_Volatile();
$thumbnail_paths = PATH_TEMP .'vignettes_titre/';
$this->_filesystem
->mkdir($thumbnail_paths)
->cd($thumbnail_paths)
->touch('notice_2.png');
Class_WebService_Vignette::setFileSystem($this->_filesystem);
Class_CosmoVar::setValueOf('url_services', 'http://cache.org');
$this->_notice_without_thumbnails = $this->fixture('Class_Notice',
......@@ -126,7 +118,6 @@ class NoticeVignetteTest extends ModelTestCase {
public function tearDown() {
Class_WebService_AllServices::setHttpClient(null);
Class_WebService_Vignette::setDefaultHttpClient(null);
Class_WebService_Vignette::setFileSystem(null);
Class_Article::setFileWriter(null);
parent::tearDown();
}
......
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