Skip to content
Snippets Groups Projects
Commit 2f9b5fbf authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

Merge branch 'hotline#86808_valence_suppression_des_albums_dimusic' into 'hotline'

hotline #86808 improve album categories with huge number of items deletion

See merge request !3008
parents b8c8bcba 0e4d4ed8
3 merge requests!3297WIP: Master,!3009Hotline,!3008hotline #86808 improve album categories with huge number of items deletion
Pipeline #6346 failed with stage
in 28 minutes and 26 seconds
- ticket #86808 : Administration : amélioration de la suppression des albums.
\ No newline at end of file
......@@ -269,4 +269,14 @@ class Class_AlbumCategorie extends Storm_Model_Abstract {
'categories' => $this->getAlbumsInfosForTree($this->getSousCategories()),
'items' => []];
}
public function getSousCategoriesIds($ids = []) {
$ids [] = $this->getId();
foreach ($this->getSousCategories() as $sous_categorie)
$ids = $sous_categorie->getSousCategoriesIds($ids);
return $ids;
}
}
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2019, 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_AlbumCategorie_Remover extends Class_Entity {
use Trait_StaticCommand;
public function run() {
$command = sprintf('delete_album_category.php %s >/dev/null 2>&1 &',
escapeshellarg($this->getId()));
$this->getCommand()->execTimedScript(3600, $command);
return $this;
}
}
......@@ -57,8 +57,13 @@ class ZendAfi_Controller_Plugin_Manager_Album extends ZendAfi_Controller_Plugin_
public function deletecategorieAction() {
if ($categorie = Class_AlbumCategorie::find((int)$this->_getParam('id')))
$categorie->delete();
if (!$category = Class_AlbumCategorie::find((int)$this->_getParam('id')))
$this->_redirect('admin/album');
$this->_helper->notify($this->_('La suppression de la catégorie %s a bien été prise en compte.',
$category->getLibelle()));
(new Class_AlbumCategorie_Remover(['Id' => $category->getId()]))->run();
$this->_redirect('admin/album');
}
......
<?php
require(__DIR__.'/../console.php');
$id = $argv[1];
if (!$category = Class_AlbumCategorie::find($id))
exit(1);
while ($albums = Class_Album::findAllBy(['cat_id' => $category->getSousCategoriesIds(),
'limit' => 500])) {
array_map(function($album) { $album->delete();}, $albums);
Class_Album::clearCache();
}
$category->delete();
?>
\ No newline at end of file
......@@ -46,13 +46,6 @@ abstract class Admin_AlbumControllerTestCase extends Admin_AbstractControllerTes
->whenCalled('findAllBy')
->answers([$cus, $fre, $dak]);
$favoris = $this->fixture('Class_AlbumCategorie', ['id' => 2])
->setParentId(0)
->setLibelle('Favoris')
->setSousCategories([])
->setAlbums([]);
$favoris->save();
$adulte = $this->fixture('Class_AlbumCategorie', ['id' => 6])
->setLibelle('Adulte')
->setParentId(2)
......@@ -60,6 +53,13 @@ abstract class Admin_AlbumControllerTestCase extends Admin_AbstractControllerTes
->setAlbums([]);
$adulte->save();
$favoris = $this->fixture('Class_AlbumCategorie', ['id' => 2])
->setParentId(0)
->setLibelle('Favoris')
->setSousCategories([$adulte])
->setAlbums([]);
$favoris->save();
$patrimoine = $this->fixture('Class_AlbumCategorie', ['id' => 38])
->setParentId(0)
->setSousCategories([])
......@@ -541,16 +541,34 @@ class Admin_AlbumControllerEditCategorieFavorisTest extends Admin_AlbumControlle
class Admin_AlbumControllerDeleteCategorieFavorisTest extends Admin_AlbumControllerTestCase {
public function setUp() {
parent::setUp();
$command = $this
->mock()->beStrict()
->whenCalled('execTimedScript')
->with(3600, 'delete_album_category.php \'2\' >/dev/null 2>&1 &')
->willDo(function()
{
Class_AlbumCategorie::find(2)->delete();
Class_AlbumCategorie::clearCache();
});
Class_AlbumCategorie_Remover::setCommand($command);
$this->dispatch('/admin/album/delete_categorie/id/2');
}
/** @test */
public function deleteShouldHaveBeenCalledOnFavoris() {
public function categoryFavorisShouldHaveBeenDeleted() {
$this->assertNull(Class_AlbumCategorie::findFirstBy(['libelle'=>'Favoris']));
}
/** @test */
public function adulteShouldHaveBeenDeleted() {
$this->assertNull(Class_AlbumCategorie::findFirstBy(['libelle'=>'Adulte']));
}
/** @test */
public function shouldRedirectToIndex() {
$this->assertRedirectTo('/admin/album');
......
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