Commit e0e5579e authored by Tino Goratsch's avatar Tino Goratsch

- reworked the categories delete controller action

- renamed the template error_box_layout.tpl to layout.error_box.tpl and moved it to the other layout template files
parent 04242063
......@@ -54,7 +54,7 @@ class Alerts
$this->view->assign('confirm', $confirm);
return 'system/alerts/confirm_box.tpl';
return 'System/Alerts/confirm_box.tpl';
}
return '';
}
......
......@@ -15,31 +15,31 @@ use ACP3\Modules\ACP3\Categories;
*/
class Delete extends Core\Controller\AbstractAdminAction
{
/**
* @var \ACP3\Modules\ACP3\Categories\Model\Repository\CategoryRepository
*/
protected $categoryRepository;
/**
* @var \ACP3\Modules\ACP3\Categories\Cache
*/
protected $categoriesCache;
/**
* @var Categories\Model\CategoriesModel
*/
protected $categoriesModel;
/**
* Delete constructor.
*
* @param \ACP3\Core\Controller\Context\AdminContext $context
* @param \ACP3\Modules\ACP3\Categories\Model\Repository\CategoryRepository $categoryRepository
* @param Categories\Model\CategoriesModel $categoriesModel
* @param \ACP3\Modules\ACP3\Categories\Cache $categoriesCache
*/
public function __construct(
Core\Controller\Context\AdminContext $context,
Categories\Model\Repository\CategoryRepository $categoryRepository,
Categories\Model\CategoriesModel $categoriesModel,
Categories\Cache $categoriesCache
) {
parent::__construct($context);
$this->categoryRepository = $categoryRepository;
$this->categoriesCache = $categoriesCache;
$this->categoriesModel = $categoriesModel;
}
/**
......@@ -50,43 +50,14 @@ class Delete extends Core\Controller\AbstractAdminAction
*/
public function execute($action = '')
{
return $this->actionHelper->handleCustomDeleteAction(
return $this->actionHelper->handleDeleteAction(
$action,
function (array $items) {
$bool = false;
$isInUse = false;
foreach ($items as $item) {
if (!empty($item) && $this->categoryRepository->resultExists($item) === true) {
$category = $this->categoryRepository->getCategoryDeleteInfosById($item);
$serviceId = strtolower($category['module'] . '.' . $category['module'] . 'repository');
if ($this->container->has($serviceId) &&
$this->get($serviceId)->countAll('', $item) > 0
) {
$isInUse = true;
continue;
}
// Kategoriebild ebenfalls löschen
$upload = new Core\Helpers\Upload($this->appPath, Categories\Installer\Schema::MODULE_NAME);
$upload->removeUploadedFile($category['picture']);
$bool = $this->categoryRepository->delete($item);
}
}
$result = $this->categoriesModel->delete($items);
$this->categoriesCache->getCacheDriver()->deleteAll();
Core\Cache\Purge::doPurge($this->appPath->getCacheDir() . 'http');
if ($isInUse === true) {
$text = $this->translator->t('categories', 'category_is_in_use');
$bool = false;
} else {
$text = $this->translator->t('system', $bool !== false ? 'delete_success' : 'delete_error');
}
return $this->redirectMessages()->setMessage($bool, $text);
return $result;
}
);
}
......
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Modules\ACP3\Categories\Event\Listener;
use ACP3\Core\Environment\ApplicationPath;
use ACP3\Core\Helpers\Upload;
use ACP3\Core\Model\Event\ModelSaveEvent;
use ACP3\Modules\ACP3\Categories\Installer\Schema;
use ACP3\Modules\ACP3\Categories\Model\Repository\CategoryRepository;
class DeleteCategoryPictureOnOnCategoriesModelDeleteBeforeListener
{
/**
* @var CategoryRepository
*/
private $categoryRepository;
/**
* @var ApplicationPath
*/
private $appPath;
/**
* OnCategoriesModelDeleteBeforeListener constructor.
* @param ApplicationPath $appPath
* @param CategoryRepository $categoryRepository
*/
public function __construct(ApplicationPath $appPath, CategoryRepository $categoryRepository)
{
$this->categoryRepository = $categoryRepository;
$this->appPath = $appPath;
}
/**
* @param ModelSaveEvent $event
*/
public function execute(ModelSaveEvent $event)
{
if ($event->isDeleteStatement()) {
return;
}
foreach ($event->getEntryId() as $entryId) {
$category = $this->categoryRepository->getCategoryDeleteInfosById($entryId);
$upload = new Upload($this->appPath, Schema::MODULE_NAME);
$upload->removeUploadedFile($category['picture']);
}
}
}
......@@ -12,7 +12,7 @@ services:
class: ACP3\Modules\ACP3\Categories\Controller\Admin\Index\Delete
arguments:
- '@core.context.admin'
- '@categories.model.categories_repository'
- '@categories.model.categories_model'
- '@categories.cache'
categories.controller.admin.index.edit:
......
......@@ -6,3 +6,11 @@ services:
- '@categories.model.categories_repository'
tags:
- { name: core.eventListener, event: categories.model.categories.after_save, method: execute }
categories.event.on_categories_model_delete_before_listener:
class: ACP3\Modules\ACP3\Categories\Event\Listener\DeleteCategoryPictureOnOnCategoriesModelDeleteBeforeListener
arguments:
- '@core.environment.application_path'
- '@categories.model.categories_repository'
tags:
- { name: core.eventListener, event: categories.model.categories.before_delete, method: execute }
......@@ -15,12 +15,10 @@
<a href="{$confirm.backward}" class="btn btn-default">{lang t="system|no"}</a>
{elseif $confirm.overlay == 1}
<a href="javascript:window.parent.$.fancybox.close();window.parent.location.reload();" class="btn btn-primary">{lang t="system|close_window"}</a>
{elseif is_array($confirm.forward)}
<a href="{$confirm.forward.url}" class="btn btn-primary">{$confirm.forward.lang}</a>
{else}
{if is_array($confirm.forward)}
<a href="{$confirm.forward.url}" class="btn btn-primary">{$confirm.forward.lang}</a>
{else}
<a href="{$confirm.forward}" class="btn btn-primary">{lang t="system|forward"}</a>
{/if}
<a href="{$confirm.forward}" class="btn btn-primary">{lang t="system|forward"}</a>
{/if}
{/block}
</div>
......
{extends file="asset:system/alerts/error_box_layout.tpl"}
{extends file="asset:System/layout.error_box.tpl"}
{block CONTENT}
<div id="error-box" class="alert alert-warning alert-block">
......
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