-
-
Notifications
You must be signed in to change notification settings - Fork 186
[NodeBundle] Undo deleting pages #2706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 9 commits
4402bf0
0f70f5c
631ddf3
dab4e8f
e1eed18
c7b8ae5
ca06327
bca8eb2
6b67689
e576798
4391b9f
602924a
a51b83a
d12fa0d
1a35997
d59d195
9eee63e
05a812b
ed19196
d379ffb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Kunstmaan\NodeBundle\AdminList; | ||
|
||
use Doctrine\ORM\QueryBuilder; | ||
use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM\DateFilterType; | ||
use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM\StringFilterType; | ||
|
||
class DeletedNodeAdminListConfigurator extends NodeAdminListConfigurator | ||
{ | ||
public function buildFilters() | ||
{ | ||
$this | ||
->addFilter('title', new StringFilterType('title'), 'kuma_node.admin.list.filter.title') | ||
->addFilter('created', new DateFilterType('created'), 'kuma_node.admin.list.filter.created_at') | ||
->addFilter('updated', new DateFilterType('updated'), 'kuma_node.admin.list.filter.updated_at') | ||
; | ||
} | ||
|
||
public function buildFields() | ||
{ | ||
$this | ||
->addField('title', 'kuma_node.admin.list.header.title', true, '@KunstmaanNode/Admin/title.html.twig') | ||
->addField('created', 'kuma_node.admin.list.header.created_at', true) | ||
->addField('updated', 'kuma_node.admin.list.header.updated_at', true) | ||
; | ||
} | ||
|
||
public function adaptQueryBuilder(QueryBuilder $queryBuilder) | ||
{ | ||
parent::adaptQueryBuilder($queryBuilder); | ||
|
||
$queryBuilder | ||
->where('b.lang = :lang') | ||
->andWhere('n.deleted = 1') | ||
; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
use DateTime; | ||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\ORM\EntityManager; | ||
use Esites\CustomerAdminBundle\Entity\User; | ||
use InvalidArgumentException; | ||
use Kunstmaan\AdminBundle\Entity\BaseUser; | ||
use Kunstmaan\AdminBundle\Entity\EntityInterface; | ||
|
@@ -16,6 +17,9 @@ | |
use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\PermissionMap; | ||
use Kunstmaan\AdminBundle\Service\AclManager; | ||
use Kunstmaan\AdminListBundle\AdminList\AdminList; | ||
use Kunstmaan\AdminListBundle\AdminList\ItemAction\SimpleItemAction; | ||
use Kunstmaan\AdminListBundle\AdminList\ListAction\SimpleListAction; | ||
use Kunstmaan\NodeBundle\AdminList\DeletedNodeAdminListConfigurator; | ||
use Kunstmaan\NodeBundle\AdminList\NodeAdminListConfigurator; | ||
use Kunstmaan\NodeBundle\Entity\HasNodeInterface; | ||
use Kunstmaan\NodeBundle\Entity\Node; | ||
|
@@ -140,18 +144,28 @@ public function indexAction(Request $request) | |
'params' => ['_locale' => $locale, 'url' => $item->getUrl()], | ||
); | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
$nodeAdminListConfigurator->addSimpleItemAction('action.preview', $itemRoute, 'eye'); | ||
$nodeAdminListConfigurator->addListAction( | ||
new SimpleListAction( | ||
[ | ||
'path' => 'KunstmaanNodeBundle_deleted_nodes', | ||
'params' => [], | ||
], | ||
'deleted_pages.view_action', | ||
null, | ||
'@KunstmaanAdmin/Settings/button_resolve_all.html.twig' | ||
) | ||
); | ||
$nodeAdminListConfigurator->setDomainConfiguration($this->get('kunstmaan_admin.domain_configuration')); | ||
$nodeAdminListConfigurator->setShowAddHomepage($this->getParameter('kunstmaan_node.show_add_homepage') && $this->isGranted('ROLE_SUPER_ADMIN')); | ||
|
||
/** @var AdminList $adminlist */ | ||
$adminlist = $this->get('kunstmaan_adminlist.factory')->createList($nodeAdminListConfigurator); | ||
$adminlist->bindRequest($request); | ||
|
||
return array( | ||
'adminlist' => $adminlist, | ||
$nodeAdminListConfigurator->setShowAddHomepage( | ||
$this->getParameter('kunstmaan_node.show_add_homepage') && $this->isGranted('ROLE_SUPER_ADMIN') | ||
); | ||
|
||
return $this->renderAdminList($request, $nodeAdminListConfigurator); | ||
} | ||
|
||
/** | ||
|
@@ -347,7 +361,6 @@ public function unPublishAction(Request $request, $id) | |
$node = $this->em->getRepository(Node::class)->find($id); | ||
|
||
$nodeTranslation = $node->getNodeTranslation($this->locale, true); | ||
$request = $this->get('request_stack')->getCurrentRequest(); | ||
$this->nodePublisher->chooseHowToUnpublish($request, $nodeTranslation, $this->translator); | ||
|
||
return $this->redirect($this->generateUrl('KunstmaanNodeBundle_nodes_edit', array('id' => $node->getId()))); | ||
|
@@ -451,6 +464,102 @@ public function deleteAction(Request $request, $id) | |
return $response; | ||
} | ||
|
||
/** | ||
* @Route("/deleted", name="KunstmaanNodeBundle_deleted_nodes") | ||
* @Template("@KunstmaanNode/Admin/deleted_list.html.twig") | ||
* | ||
* @param Request $request | ||
* | ||
* @return array | ||
*/ | ||
public function deletedNodesAction(Request $request) | ||
{ | ||
$this->init($request); | ||
|
||
$nodeAdminListConfigurator = new DeletedNodeAdminListConfigurator( | ||
$this->em, | ||
$this->aclHelper, | ||
$this->locale, | ||
PermissionMap::PERMISSION_DELETE, | ||
$this->authorizationChecker | ||
); | ||
$nodeAdminListConfigurator->addListAction( | ||
new SimpleListAction( | ||
[ | ||
'path' => 'KunstmaanNodeBundle_nodes', | ||
'params' => [], | ||
], | ||
'pages.view_action', | ||
null, | ||
'@KunstmaanAdmin/Settings/button_resolve_all.html.twig' | ||
) | ||
); | ||
|
||
JZuidema marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
$locale = $this->locale; | ||
$acl = $this->authorizationChecker; | ||
|
||
$nodeAdminListConfigurator->addSimpleItemAction( | ||
'action.undo_delete', | ||
function (EntityInterface $item) use ($locale, $acl) { | ||
if ($acl->isGranted(PermissionMap::PERMISSION_DELETE, $item->getNode())) { | ||
return [ | ||
'path' => 'KunstmaanNodeBundle_nodes_delete_undo', | ||
'params' => [ | ||
'_locale' => $locale, | ||
'id' => $item->getNode()->getId(), | ||
], | ||
]; | ||
} | ||
|
||
return null; | ||
}, | ||
'undo', | ||
'@KunstmaanAdmin/Settings/button_resolve_all.html.twig' | ||
); | ||
|
||
return $this->renderAdminList($request, $nodeAdminListConfigurator); | ||
} | ||
|
||
/** | ||
* @Route( | ||
* "/{id}/delete/undo", | ||
* requirements={"id" = "\d+"}, | ||
* name="KunstmaanNodeBundle_nodes_delete_undo", | ||
* ) | ||
* | ||
* @param Request $request | ||
* @param int $id | ||
* | ||
* @return RedirectResponse | ||
*/ | ||
public function undoDeleteAction(Request $request, $id) | ||
{ | ||
$this->init($request); | ||
|
||
/* @var Node $node */ | ||
$node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id); | ||
|
||
try { | ||
$this->undoDeleteNode($node); | ||
|
||
$this->em->flush(); | ||
|
||
$this->addFlash( | ||
FlashTypes::SUCCESS, | ||
$this->get('translator')->trans('kuma_node.admin.undo_delete.flash.success') | ||
); | ||
} catch (AccessDeniedException $exception) { | ||
$this->addFlash( | ||
FlashTypes::SUCCESS, | ||
$this->get('translator')->trans('kuma_node.admin.undo_delete.flash.error') | ||
); | ||
} | ||
|
||
return $this->redirectToRoute( | ||
'KunstmaanNodeBundle_deleted_nodes' | ||
); | ||
} | ||
|
||
/** | ||
* @Route( | ||
* "/{id}/duplicate", | ||
|
@@ -881,6 +990,13 @@ public function editAction(Request $request, $id, $subaction) | |
$nodeVersion = $draftNodeVersion; | ||
$page = $nodeVersion->getRef($this->em); | ||
} else { | ||
if (!empty($request->request->get('undo_delete'))) { | ||
$node->setDeleted(false); | ||
|
||
$this->em->persist($node); | ||
$this->em->flush(); | ||
} | ||
|
||
if ($request->getMethod() == 'POST') { | ||
$nodeVersionIsLocked = $this->isNodeVersionLocked($nodeTranslation, true); | ||
|
||
|
@@ -1219,6 +1335,34 @@ private function deleteNodeChildren( | |
} | ||
} | ||
|
||
/** | ||
* @param Node $node | ||
*/ | ||
private function undoDeleteNode( | ||
Node $node | ||
) { | ||
$this->denyAccessUnlessGranted( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add a early return here if the node is not deleted. A possible case could be that you delete a parent with nested children and already restore a child before. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've applied this |
||
PermissionMap::PERMISSION_DELETE, | ||
$node | ||
); | ||
|
||
$node->setDeleted(false); | ||
|
||
foreach ($node->getNodeTranslations() as $nodeTranslation) { | ||
if (!$nodeTranslation instanceof NodeTranslation) { | ||
continue; | ||
} | ||
|
||
$this->nodePublisher->unPublish($nodeTranslation); | ||
} | ||
|
||
$this->em->persist($node); | ||
|
||
foreach ($node->getChildren() as $child) { | ||
$this->undoDeleteNode($child); | ||
} | ||
} | ||
|
||
/** | ||
* @param Request $request | ||
* @param string $type | ||
|
@@ -1302,4 +1446,23 @@ private function renderNodeNotTranslatedPage(Node $node) | |
) | ||
); | ||
} | ||
|
||
/** | ||
* @param Request $request | ||
* @param NodeAdminListConfigurator $nodeAdminListConfigurator | ||
* | ||
* @return array | ||
*/ | ||
private function renderAdminList( | ||
Request $request, | ||
NodeAdminListConfigurator $nodeAdminListConfigurator | ||
) { | ||
/** @var AdminList $adminList */ | ||
$adminList = $this->get('kunstmaan_adminlist.factory')->createList($nodeAdminListConfigurator); | ||
$adminList->bindRequest($request); | ||
|
||
return [ | ||
'adminlist' => $adminList, | ||
]; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.