Skip to content

Commit

Permalink
implemented twin-elements/crud-logger
Browse files Browse the repository at this point in the history
  • Loading branch information
twin-elements committed Jun 10, 2022
1 parent 3d3c9d0 commit e906d4d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
"require": {
"php": "^7.1.3",
"symfony/framework-bundle": "^4.4 || ^5.4",
"twin-elements/admin-bundle": "^1.9"
"twin-elements/admin-bundle": "^1.11"
},
"autoload": {
"psr-4": {
"TwinElements\\MenuBundle\\": "src/"
}
},
"conflict": {
"twin-elements/admin-bundle": "<1.9"
"twin-elements/admin-bundle": "<1.11.3"
}
}
23 changes: 13 additions & 10 deletions src/Controller/MenuCategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace TwinElements\MenuBundle\Controller;

use Doctrine\Persistence\ManagerRegistry;
use TwinElements\AdminBundle\Model\CrudControllerTrait;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use TwinElements\AdminBundle\Role\AdminUserRole;
use TwinElements\Component\CrudLogger\CrudLogger;
use TwinElements\MenuBundle\Entity\MenuCategory;
use TwinElements\MenuBundle\Form\MenuCategoryType;
use TwinElements\MenuBundle\Repository\MenuCategoryRepository;
Expand Down Expand Up @@ -38,7 +40,9 @@ public function indexAction(MenuCategoryRepository $menuCategoryRepository)
/**
* @Route("/new", name="menucategory_new", methods={"GET", "POST"})
*/
public function newAction(Request $request)
public function newAction(
ManagerRegistry $managerRegistry,
Request $request)
{
$this->denyAccessUnlessGranted("ROLE_SUPER_ADMIN");
$menuCategory = new Menucategory();
Expand All @@ -48,12 +52,12 @@ public function newAction(Request $request)
if ($form->isSubmitted() && $form->isValid()) {

try {
$em = $this->getDoctrine()->getManager();
$em = $managerRegistry->getManager();
$em->persist($menuCategory);
$em->flush();

$this->flashes->successMessage($this->adminTranslator->translate('admin.success_operation'));;
$this->crudLogger->createLog($menuCategory->getId(), $menuCategory->getTitle());
$this->crudLogger->createLog(MenuCategory::class, CrudLogger::CreateAction, $menuCategory->getId());

} catch (\Exception $exception) {
$this->flashes->errorMessage($exception->getMessage());
Expand Down Expand Up @@ -81,7 +85,7 @@ public function newAction(Request $request)
/**
* @Route("/{id}/edit", name="menucategory_edit", methods={"GET", "POST"})
*/
public function editAction(Request $request, MenuCategory $menuCategory)
public function editAction(ManagerRegistry $managerRegistry, Request $request, MenuCategory $menuCategory)
{
$this->denyAccessUnlessGranted(AdminUserRole::ROLE_ADMIN);
$deleteForm = $this->createDeleteForm($menuCategory);
Expand All @@ -91,10 +95,10 @@ public function editAction(Request $request, MenuCategory $menuCategory)
if ($editForm->isSubmitted() && $editForm->isValid()) {

try {
$this->getDoctrine()->getManager()->flush();
$managerRegistry->getManager()->flush();

$this->flashes->successMessage($this->adminTranslator->translate('admin.success_operation'));;
$this->crudLogger->createLog($menuCategory->getId(), $menuCategory->getTitle());
$this->crudLogger->createLog(MenuCategory::class, CrudLogger::EditAction, $menuCategory->getId());

} catch (\Exception $exception) {
$this->flashes->errorMessage($exception->getMessage());
Expand Down Expand Up @@ -124,7 +128,7 @@ public function editAction(Request $request, MenuCategory $menuCategory)
*
* @Route("/{id}", name="menucategory_delete", methods={"DELETE"})
*/
public function deleteAction(Request $request, MenuCategory $menuCategory)
public function deleteAction(Request $request, MenuCategory $menuCategory, ManagerRegistry $managerRegistry)
{
$this->denyAccessUnlessGranted(AdminUserRole::ROLE_ADMIN);

Expand All @@ -136,14 +140,13 @@ public function deleteAction(Request $request, MenuCategory $menuCategory)
try {

$id = $menuCategory->getId();
$title = $menuCategory->getTitle();

$em = $this->getDoctrine()->getManager();
$em = $managerRegistry->getManager();
$em->remove($menuCategory);
$em->flush();

$this->flashes->successMessage($this->adminTranslator->translate('admin.success_operation'));;
$this->crudLogger->createLog($id, $title);
$this->crudLogger->createLog(MenuCategory::class, CrudLogger::DeleteAction, $id);

} catch (\Exception $exception){
$this->flashes->errorMessage($exception->getMessage());
Expand Down
11 changes: 6 additions & 5 deletions src/Controller/MenuController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
namespace TwinElements\MenuBundle\Controller;

use Symfony\Component\Cache\Adapter\AdapterInterface;
use TwinElements\Component\CrudLogger\CrudLogger;
use TwinElements\Component\CrudLogger\CrudLoggerInterface;
use TwinElements\SortableBundle\Entity\PositionInterface;
use TwinElements\AdminBundle\Helper\Breadcrumbs;
use TwinElements\AdminBundle\Helper\CrudLoggerMessage;
use TwinElements\AdminBundle\Model\CrudControllerTrait;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
Expand Down Expand Up @@ -34,7 +35,7 @@ class MenuController extends AbstractController
CrudControllerTrait::__construct as private __crudConstruct;
}

public function __construct(Breadcrumbs $breadcrumbs, Flashes $flashes, CrudLoggerMessage $crudLogger, AdminTranslator $translator, AdapterInterface $cache)
public function __construct(Breadcrumbs $breadcrumbs, Flashes $flashes, CrudLoggerInterface $crudLogger, AdminTranslator $translator, AdapterInterface $cache)
{
$this->__crudConstruct($breadcrumbs, $flashes, $crudLogger, $translator);
$this->cache = $cache;
Expand Down Expand Up @@ -106,7 +107,7 @@ public function newAction(Request $request, AdapterInterface $cache)
}

$this->flashes->successMessage($this->adminTranslator->translate('admin.success_operation'));;
$this->crudLogger->createLog($menu->getId(), $menu->getTitle());
$this->crudLogger->createLog(Menu::class, CrudLogger::CreateAction, $menu->getId());

} catch (\Exception $exception) {
$this->flashes->errorMessage($exception->getMessage());
Expand Down Expand Up @@ -164,7 +165,7 @@ public function editAction(Request $request, Menu $menu, AdapterInterface $cache
}

$this->flashes->successMessage($this->adminTranslator->translate('admin.success_operation'));;
$this->crudLogger->createLog($menu->getId(), $menu->getTitle());
$this->crudLogger->createLog(Menu::class, CrudLogger::EditAction, $menu->getId());

} catch (\Exception $exception) {
$this->flashes->errorMessage($exception->getMessage());
Expand Down Expand Up @@ -221,7 +222,7 @@ public function deleteAction(Request $request, Menu $menu)

$this->removeCache($category, $request->getLocale());

$this->crudLogger->createLog($id, $title);
$this->crudLogger->createLog(Menu::class, CrudLogger::DeleteAction, $menu->getId());
$this->flashes->successMessage($this->adminTranslator->translate('menu.the_menu_item_has_been_deleted'));
} catch (\Exception $exception) {
$this->flashes->errorMessage($exception->getMessage());
Expand Down

0 comments on commit e906d4d

Please sign in to comment.